-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreact-postgrid.php
39 lines (30 loc) · 1.37 KB
/
react-postgrid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/*
Plugin Name: React Postgrid
Plugin URI: https://brettshumaker.com
Description: Provides a shortcode that renders a posts grid in react. Choose a category and view posts with no page reload. :)
Version: 1.0
Author: Brett Shumaker
Author URI: https://brettshumaker.com/
License: GPLv3
*/
function reactjs_display() {
return '<div id="react-postgrid-wrap"></div>';
}
add_shortcode( 'react-postgrid', 'reactjs_display' );
add_action( 'wp_enqueue_scripts', 'load_scripts' );
function load_scripts() {
wp_enqueue_script( 'react-js', 'https://unpkg.com/react@15/dist/react.js' );
wp_enqueue_script( 'react-dom', 'https://unpkg.com/react-dom@15/dist/react-dom.js', array( 'react-js' ) );
wp_enqueue_script( 'babel', 'https://npmcdn.com/[email protected]/browser.min.js', array( 'react-dom') );
wp_enqueue_script( 'axios', 'https://unpkg.com/axios/dist/axios.min.js', array('react-dom') );
wp_enqueue_script( 'react-postgrid', plugin_dir_url( __FILE__ ) . 'js/react-postgrid.js', array( 'axios', 'babel' ) );
wp_enqueue_style( 'react-plugin', plugin_dir_url( __FILE__ ) . 'css/react-postgrid.css' );
}
add_filter( 'script_loader_tag', 'react_js_plugin_babel_type', 10, 3 );
function react_js_plugin_babel_type( $tag, $handle, $src ) {
if ( $handle !== 'react-postgrid' ) {
return $tag;
}
return '<script src="' . $src . '" type="text/babel"></script>' . "\n";
}