-
Notifications
You must be signed in to change notification settings - Fork 7
/
wp-react-plugin.php
50 lines (40 loc) · 1.3 KB
/
wp-react-plugin.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
40
41
42
43
44
45
46
47
48
49
50
<?php
/*
Plugin Name: WP React Plugin
Description: Develop React apps inside WordPress. Uses React Hot Loader to update changes in real time while also preserving React state.
Version: 0.0.1
Author: David Gwyer
Author URI: http://www.wpgoplugins.com
*/
class WP_React_Plugin {
protected $plugin_options_page = '';
/**
* Class constructor
*/
public function __construct() {
require('plugin_options.php');
}
/**
* Initialize hooks.
*/
public function init() {
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_frontend_scripts' ) );
}
public function enqueue_frontend_scripts($hook) {
//wp_enqueue_script('react');
//wp_enqueue_script('react-dom');
// add react and react-dom from core
$dep = ''; //['wp-element'];
$handle = 'wp-react-plugin-';
// enqueue development or production React code
if(file_exists(dirname(__FILE__) . "/dist/main.js")) {
$handle .= 'prod';
wp_enqueue_script( $handle, plugins_url( "/dist/main.js", __FILE__ ), ['wp-element'], '0.1', true );
} else {
$handle .= 'dev';
wp_enqueue_script( $handle, 'http://localhost:3000/assets/main.js', ['wp-element'], '0.1', true );
}
}
}
$wp_react_plugin = new WP_React_Plugin();
$wp_react_plugin->init();