PluginProbe
Vimeography: Vimeo Video Gallery WordPress Plugin / trunk
Vimeography: Vimeo Video Gallery WordPress Plugin vtrunk
2.4.9 2.4.8 trunk 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 0.6 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8 0.6.8.1 0.6.9 0.6.9.1 0.6.9.2 0.7 0.8 All 103 releases
vimeography / lib / admin / scripts.php

scripts.php in Vimeography: Vimeo Video Gallery WordPress Plugin trunk, at lib/admin/scripts.php

141 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if (!defined('ABSPATH')) {
5 exit();
6 }
7
8 class Vimeography_Admin_Scripts
9 {
10 public function __construct()
11 {
12 add_action('admin_enqueue_scripts', array($this, 'add_scripts'), 10, 1);
13 }
14
15 /**
16 * Load the common admin scripts across the Vimeography plugin.
17 *
18 * @param string $hook slug of the current admin page
19 */
20 public function add_scripts($hook)
21 {
22 if (
23 strpos($hook, 'vimeography') !== false &&
24 strpos($hook, 'vimeography-stats') == false
25 ) {
26 wp_register_style(
27 'vimeography-bootstrap',
28 VIMEOGRAPHY_URL . 'lib/admin/assets/css/bootstrap.min.css'
29 );
30 wp_register_style(
31 'vimeography-admin',
32 VIMEOGRAPHY_URL . 'lib/admin/assets/css/admin.css'
33 );
34
35 wp_register_script(
36 'vimeography-bootstrap',
37 VIMEOGRAPHY_URL . 'lib/admin/assets/js/bootstrap.min.js'
38 );
39
40 switch ($hook) {
41 case 'vimeography_page_vimeography-new-gallery':
42 wp_register_script(
43 'fullpage',
44 'https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.2/jquery.fullPage.min.js',
45 array('jquery')
46 );
47 wp_register_script(
48 'select2',
49 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
50 array('jquery')
51 );
52 wp_register_style(
53 'fullpage',
54 'https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.2/jquery.fullPage.min.css'
55 );
56 wp_register_style(
57 'select2',
58 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css'
59 );
60 wp_enqueue_script('fullpage');
61 wp_enqueue_style('fullpage');
62 wp_enqueue_script('select2');
63 wp_enqueue_style('select2');
64 break;
65 case "toplevel_page_vimeography-edit-galleries":
66 if (defined('VIMEOGRAPHY_DEV') && VIMEOGRAPHY_DEV) {
67 $devserver_path = defined('VIMEOGRAPHY_ADMIN_JS_URL') ? VIMEOGRAPHY_ADMIN_JS_URL : 'http://localhost:8024';
68 wp_enqueue_script(
69 'vimeography_admin_react',
70 $devserver_path . '/index.js',
71 [],
72 "1.0",
73 true
74 );
75 } else {
76 $manifest = VIMEOGRAPHY_PATH . 'lib/admin/app/dist/manifest.json';
77 $manifest = file_get_contents($manifest);
78 $manifest = (array) json_decode($manifest);
79
80 $script_url =
81 VIMEOGRAPHY_URL . 'lib/admin/app/dist/' . $manifest['index.js'];
82
83 // There was a bug introduced in Vimeography Pro 2.1 where Pro JS mistakenly depended
84 // on `vimeography_admin_react` to be loaded before itself, which led to a
85 // race condition of scripts loading as expected. We've corrected this
86 // issue in Pro 2.1.1, so let's check to see if the user has the corrected
87 // version, and if so, we can safely avoid a circular dependency loop
88 // Otherwise, the user will have to live with the race condition bug
89 // until they update to 2.1.1
90
91 // Ref: https://github.com/davekiss/vimeography-pro/commit/08099c072928df96a7df6cc5b4050fe9390b35b3
92 if (
93 is_plugin_active('vimeography-pro/vimeography-pro.php') &&
94 defined('VIMEOGRAPHY_PRO_VERSION') &&
95 version_compare(VIMEOGRAPHY_PRO_VERSION, '2.1.1', '>=')
96 ) {
97 $deps = array('vimeography_pro_admin');
98 } else {
99 $deps = array();
100 }
101
102 wp_enqueue_script(
103 'vimeography_admin_react',
104 $script_url,
105 $deps,
106 "1.0",
107 true
108 );
109 }
110
111 wp_add_inline_script(
112 'vimeography_admin_react',
113 'var vimeographyThemeNonce = "' .
114 wp_create_nonce("vimeography-theme-action") .
115 '";',
116 'before'
117 );
118
119 wp_add_inline_script(
120 'vimeography_admin_react',
121 'var vimeographyApiSettings = ' .
122 json_encode(array(
123 'root' => esc_url_raw(rest_url()),
124 'nonce' => wp_create_nonce('wp_rest')
125 )),
126 'before'
127 );
128
129 break;
130 default:
131 wp_enqueue_style('vimeography-bootstrap');
132 wp_enqueue_script('vimeography-bootstrap');
133 break;
134 }
135
136 wp_enqueue_style('vimeography-admin');
137 wp_enqueue_script('vimeography-admin');
138 }
139 }
140 }
141