-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-vite-react.php
58 lines (49 loc) · 1.37 KB
/
wp-vite-react.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
51
52
53
54
55
56
57
58
<?php
/**
* Plugin Name: Wordpress Vite React Plugin
* Description: Um plugin WordPress com tecnologia Vite e ReactJS. Utilize o shortcode <code>[wp_vite_react]</code> para exibir o app em qualquer local do site.
* Version: 1.0.1
* Author: Estevan Ulian
* Text Domain: wp-vite-react
* Domain Path: /languages/
* Requires PHP: 7.4
* Update URI: https://estevanulian.com
*/
if ( ! defined( 'ABSPATH' ) ) exit;
add_shortcode( 'wp_vite_react', 'wp_vite_react_shortcode' );
function wp_vite_react_shortcode () {
$elementor_edit_mode = \Elementor\Plugin::$instance->editor->is_edit_mode();
if ($elementor_edit_mode) {
return '';
}
wp_react_app_load_scripts();
ob_start();
?>
<div id="wp-vite-react-app-wrapper"></div>
<?php
return ob_get_clean();
}
function wp_react_app_load_scripts () {
$app_url = plugins_url( 'app/build', __FILE__ );
wp_enqueue_script(
'wp-vite-react-app',
$app_url . '/assets/index.js',
false,
'1.0.0',
true
);
wp_localize_script(
'wp-vite-react-app',
'wpReactPlugin',
[
'root' => '#wp-vite-react-app-wrapper',
'baseUrl' => rtrim( $app_url, '/' )
]
);
wp_enqueue_style(
'wp-vite-react-app',
$app_url . '/assets/index.css',
false,
'1.0.0'
);
}