-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.php
97 lines (60 loc) · 1.79 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* @package pwp
* @version 1.0
**/
/**
Plugin Name: Phaser 3 to WordPress
Plugin URI: https://greoux.re/code/index.php/phaser-3-to-wordpress-plugin/
Description: Insert a phaser.io-based game in your WordPress posts and pages with a simple shortcode: [pwp].
Author: Gréoux Research
Version: 1.0
Author URI: https://greoux.re
**/
/* --- */
if (!function_exists("add_action")) {
exit;
}
/* --- */
define("GREOUXRE_PWP_URL", plugin_dir_url(__FILE__));
define("GREOUXRE_PWP_DIR", plugin_dir_path(__FILE__));
/* --- */
$GREOUXRE_PWP_CAN_BE_LOADED = 0;
function GREOUXRE_PWP_TEMPLATE_REDIRECT()
{
global $GREOUXRE_PWP_CAN_BE_LOADED;
if ((is_page() or is_single()) and (strpos(get_post(get_the_ID())->post_content, "[pwp]") !== false)) {
$GREOUXRE_PWP_CAN_BE_LOADED = 1;
}
}
add_action("template_redirect", "GREOUXRE_PWP_TEMPLATE_REDIRECT");
/* --- */
function GREOUXRE_PWP_WP_ENQUEUE_SCRIPTS()
{
global $GREOUXRE_PWP_CAN_BE_LOADED;
if ($GREOUXRE_PWP_CAN_BE_LOADED === 1) {
wp_enqueue_script("jquery");
wp_enqueue_script(
"phaser3",
GREOUXRE_PWP_URL . "assets/[email protected]/phaser.min.js"
);
wp_enqueue_script(
"pwp",
GREOUXRE_PWP_URL . "assets/[email protected]/game.js",
array("jquery", "phaser3")
);
}
}
add_action("wp_enqueue_scripts", "GREOUXRE_PWP_WP_ENQUEUE_SCRIPTS");
/* --- */
function GREOUXRE_PWP_HTM($atts)
{
global $GREOUXRE_PWP_CAN_BE_LOADED;
if ($GREOUXRE_PWP_CAN_BE_LOADED === 1) {
return "<div id='pwp' style='height: 100%; max-width: 600px; margin: 2rem auto; overflow: hidden;' data-path='" . GREOUXRE_PWP_URL . "assets/[email protected]/'></div>";
} else {
return "";
}
}
add_shortcode("pwp", "GREOUXRE_PWP_HTM");
/* --- */