PluginProbe
Getwid – Gutenberg Blocks / 3.0.2
Getwid – Gutenberg Blocks v3.0.2
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
← All changes | includes/scripts-manager.php +267 -205 2.1.23.0.2 View file →
@@ -20,265 +20,327 @@
20 20
21 21 $this->version = $settings->getVersion();
22 22 $this->prefix = $settings->getPrefix();
23 23
24 - // Fires after block assets have been enqueued for the editing interface.
25 - add_action( 'enqueue_block_editor_assets', [ $this, 'enqueueEditorAssets'] );
24 + add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ), 10 );
25 + add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ), 10 );
26 26
27 - // Fires after enqueuing block assets for both editor and front-end.
28 - add_action( 'enqueue_block_assets', [ $this, 'enqueueFrontBlockAssets' ] );
27 + add_action( 'enqueue_block_assets', array( $this, 'enqueue_common_blocks_assets' ), 15 );
28 + }
29 29
30 - // section_content_width inline styles
31 - add_action( 'after_theme_setup', [ $this, 'enqueue_editor_section_css' ] );
30 + public function enqueue_block_editor_assets() {
32 31
33 - add_action( 'wp_footer', [ $this, 'localizeFrontend' ] );
32 + $this->setup_editor_global_data();
34 33
35 - // Register frontend styles
36 - add_action( 'wp_footer', [ $this, 'wp_late_enqueue_scripts' ] );
37 - }
34 + $style_url = getwid_get_plugin_url( '/assets/components/index.css' );
35 + $script_url = getwid_get_plugin_url( '/assets/components/index.js' );
36 + $asset_path = getwid_get_plugin_path( '/assets/components/index.asset.php' );
38 37
39 - public function get_image_sizes() {
38 + if ( ! file_exists( $asset_path ) ) {
39 + return;
40 + }
40 41
41 - global $_wp_additional_image_sizes;
42 + $asset = include $asset_path;
42 43
43 - $intermediate_image_sizes = get_intermediate_image_sizes();
44 + wp_enqueue_script(
45 + 'getwid-components',
46 + $script_url,
47 + $asset['dependencies'],
48 + $asset['version'],
49 + );
44 50
45 - $image_sizes = array();
46 - foreach ( $intermediate_image_sizes as $size ) {
47 - if ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
48 - $image_sizes[ $size ] = array(
49 - 'width' => $_wp_additional_image_sizes[ $size ][ 'width' ],
50 - 'height' => $_wp_additional_image_sizes[ $size ][ 'height' ]
51 - );
52 - } else {
53 - $image_sizes[ $size ] = array(
54 - 'width' => intval( get_option( "{$size}_size_w" ) ),
55 - 'height' => intval( get_option( "{$size}_size_h" ) )
56 - );
51 + $disabled_blocks = array();
52 + $disabled_blocks_data = array();
53 + if ( getwid()->blocksManager()->hasDisabledBlocks() ) {
54 + $disabled_blocks = getwid()->blocksManager()->getDisabledBlocks();
55 + foreach ( $disabled_blocks as $block ) {
56 + $disabled_blocks_data[] = $block->get_block_name();
57 57 }
58 58 }
59 59
60 - $sizes_arr = [];
61 - foreach ( $image_sizes as $key => $value ) {
62 - $temp_arr = [];
63 - $temp_arr[ 'value' ] = $key;
64 - $temp_arr[ 'label' ] = ucwords( strtolower( preg_replace( '/[-_]/', ' ', $key ) ) ) . " - {$value['width']} x {$value['height']}";
65 - $sizes_arr[] = $temp_arr;
66 - }
60 + $data = apply_filters(
61 + 'getwid/editor_blocks_js/localize_data',
62 + array(
63 + 'disabledBlocks' => $disabled_blocks_data,
64 + 'optionsUrl' => array(
65 + 'general' => getwid()->settingsPage()->getTabUrl( 'general' ),
66 + 'appearance' => getwid()->settingsPage()->getTabUrl( 'appearance' ),
67 + 'blocks' => getwid()->settingsPage()->getTabUrl( 'blocks' ),
68 + ),
69 + 'templates' => array(
70 + 'name' => getwid()->postTemplatePart()->postType,
71 + 'new' => admin_url( 'post-new.php?post_type=' . getwid()->postTemplatePart()->postType ),
72 + 'view' => admin_url( 'edit.php?post_type=' . getwid()->postTemplatePart()->postType ),
73 + 'edit' => admin_url( 'post.php?post=' ),
74 + ),
75 + 'settings' => array(
76 + 'image_sizes' => $this->get_image_sizes(),
77 + ),
78 + )
79 + );
80 + wp_add_inline_script( 'getwid-components', 'const GetwidComponentsData = ' . json_encode( $data ), 'before' );
67 81
68 - $sizes_arr[] = array(
69 - 'value' => 'full',
70 - 'label' => __( 'Full Size', 'getwid' )
82 + wp_enqueue_style(
83 + 'getwid-components',
84 + $style_url,
85 + apply_filters(
86 + 'getwid/editor_blocks_css/dependencies',
87 + array( 'wp-components' )
88 + ),
89 + $asset['version']
71 90 );
72 91
73 - return $sizes_arr;
92 + wp_register_style(
93 + "{$this->prefix}-blocks-editor-common",
94 + getwid_get_plugin_url( 'assets/common-styles/editor.css' ),
95 + array(),
96 + $this->version
97 + );
98 +
99 + wp_style_add_data( "{$this->prefix}-blocks-editor-common", 'rtl', 'replace' );
74 100 }
75 101
76 - /**
77 - * Enqueue editor-only js and css (Enqueue scripts (only on Edit Post Page))
78 - */
79 - public function enqueueEditorAssets() {
102 + public function enqueue_block_assets() {
80 103
81 - global $pagenow;
104 + wp_register_script(
105 + 'slick',
106 + getwid_get_plugin_url( 'vendors/slick/slick/slick.min.js' ),
107 + array( 'jquery' ),
108 + '1.9.0',
109 + true
110 + );
82 111
83 - $dependencies = array( 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-api', 'wp-api-fetch', 'lodash' );
112 + wp_add_inline_script(
113 + 'slick',
114 + sprintf(
115 + 'window.Getwid = window.Getwid || {}; window.Getwid = {...window.Getwid, ...%s};',
116 + wp_json_encode(
117 + array( 'isRTL' => is_rtl() )
118 + )
119 + ),
120 + 'before'
121 + );
84 122
85 - if ( $pagenow && $pagenow === 'widgets.php' ) {
86 - array_push( $dependencies, 'wp-edit-widgets' );
87 - } else {
88 - array_push( $dependencies, 'wp-editor' );
89 - }
123 + wp_register_style(
124 + 'slick',
125 + getwid_get_plugin_url( 'vendors/slick/slick/slick.min.css' ),
126 + array(),
127 + '1.9.0'
128 + );
90 129
91 - // Enqueue the bundled block JS file
92 - wp_enqueue_script(
93 - "{$this->prefix}-blocks-editor-js",
94 - getwid_get_plugin_url( 'assets/js/editor.blocks.js' ),
95 - apply_filters(
96 - 'getwid/editor_blocks_js/dependencies',
97 - $dependencies
98 - ),
99 - $this->version,
100 - true
130 + wp_register_style(
131 + 'slick-theme',
132 + getwid_get_plugin_url( 'vendors/slick/slick/slick-theme.min.css' ),
133 + array(),
134 + '1.9.0'
101 135 );
102 136
103 - //disabled blocks
104 - $disabledBlocks = [];
105 - $disabledBlocksData = [];
106 - if ( getwid()->blocksManager()->hasDisabledBlocks() ) {
107 - $disabledBlocks = getwid()->blocksManager()->getDisabledBlocks();
108 - foreach ( $disabledBlocks as $block ) {
109 - $disabledBlocksData[] = $block->getBlockName();
110 - }
111 - }
137 + wp_register_style(
138 + 'animate',
139 + getwid_get_plugin_url( 'vendors/animate.css/animate.min.css' ),
140 + array(),
141 + '3.7.0'
142 + );
112 143
113 - wp_localize_script(
114 - "{$this->prefix}-blocks-editor-js",
115 - 'Getwid',
116 - apply_filters(
117 - 'getwid/editor_blocks_js/localize_data',
118 - [
119 - 'disabled_blocks' => $disabledBlocksData,
120 - 'settings' => [
121 - 'wide_support' => get_theme_support( 'align-wide' ),
122 - 'date_time_utc' => current_time('Y-m-d H:i:s'),
123 - 'post_type' => get_post_type(),
124 - 'google_api_key' => get_option( 'getwid_google_api_key', '' ),
125 - 'instagram_token_isset' => (bool) get_option( 'getwid_instagram_token', '' ),
144 + wp_register_script(
145 + 'wow',
146 + getwid_get_plugin_url( 'vendors/wow.js/dist/wow.min.js' ),
147 + array( 'jquery' ),
148 + '1.2.1',
149 + true
150 + );
126 151
127 - 'assets_path' => getwid_get_plugin_url( '/assets' ),
128 - 'image_sizes' => $this->get_image_sizes(),
152 + wp_register_script(
153 + 'mp-fancybox',
154 + getwid_get_plugin_url( 'vendors/mp-fancybox/jquery.fancybox.min.js' ),
155 + array( 'jquery' ),
156 + '3.5.7-mp.1',
157 + true
158 + );
129 159
130 - 'excerpt_length' => apply_filters( 'excerpt_length', 55 ),
131 - 'recaptcha_site_key' => get_option( 'getwid_recaptcha_v2_site_key' , '' ),
132 - 'recaptcha_secret_key' => get_option( 'getwid_recaptcha_v2_secret_key', '' ),
133 - 'mailchimp_api_key' => get_option( 'getwid_mailchimp_api_key' , '' ),
134 - 'debug' => ( defined( 'WP_DEBUG' ) ? WP_DEBUG : false )
135 - ],
136 - 'templates' => [
137 - 'name' => getwid()->postTemplatePart()->postType,
138 - 'new' => admin_url( 'post-new.php?post_type=' . getwid()->postTemplatePart()->postType ),
139 - 'view' => admin_url( 'edit.php?post_type=' . getwid()->postTemplatePart()->postType ),
140 - 'edit' => admin_url( 'post.php?post=' )
141 - ],
142 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
143 - 'options_general_url' => admin_url( 'options-general.php' ),
144 - 'get_instagram_token_url' => add_query_arg(
145 - ['nonce' => wp_create_nonce('getwid_nonce_save_instagram_token') ],
146 - admin_url( 'options-general.php' )
147 - ),
148 - 'options_url' => [
149 - 'general' => getwid()->settingsPage()->getTabUrl('general'),
150 - 'appearance' => getwid()->settingsPage()->getTabUrl('appearance'),
151 - 'blocks' => getwid()->settingsPage()->getTabUrl('blocks'),
152 - ],
153 - 'nonces' => array(
154 - 'google_api_key' => wp_create_nonce( 'getwid_nonce_google_api_key' ),
155 - 'recaptcha_v2' => wp_create_nonce( 'getwid_nonce_recaptcha_v2' ),
156 - 'mailchimp_api_key' => wp_create_nonce( 'getwid_nonce_mailchimp_api_key' ),
157 - 'check_instagram_token' => wp_create_nonce( 'getwid_nonce_check_instagram_token' )
158 - ),
159 - 'acf_exist' => getwid_acf_is_active(),
160 - ]
161 - )
160 + wp_register_style(
161 + 'mp-fancybox',
162 + getwid_get_plugin_url( 'vendors/mp-fancybox/jquery.fancybox.min.css' ),
163 + array(),
164 + '3.5.7-mp.1'
162 165 );
163 166
164 - wp_set_script_translations( "{$this->prefix}-blocks-editor-js", "getwid" );
167 + wp_register_script(
168 + 'countup',
169 + getwid_get_plugin_url( 'vendors/countup.js/dist/countUp.min.js' ),
170 + array(),
171 + '2.0.4',
172 + true
173 + );
165 174
166 - $rtl = is_rtl() ? '.rtl' : '';
167 - // Enqueue optional editor only styles
168 - wp_enqueue_style(
169 - "{$this->prefix}-blocks-editor",
170 - getwid_get_plugin_url( 'assets/css/blocks.editor' . $rtl . '.css' ),
171 - apply_filters(
172 - 'getwid/editor_blocks_css/dependencies',
173 - []
174 - ),
175 - $this->version
175 + wp_register_script(
176 + 'waypoints',
177 + getwid_get_plugin_url( 'vendors/waypoints/lib/jquery.waypoints.min.js' ),
178 + array( 'jquery' ),
179 + '4.0.1',
180 + true
176 181 );
177 - }
178 182
179 - /**
180 - * Enqueue js and css for both editor and front-end
181 - *
182 - */
183 - public function enqueueFrontBlockAssets() {
183 + wp_register_script(
184 + 'popper',
185 + getwid_get_plugin_url( 'vendors/tippy.js/popper.min.js' ),
186 + array( 'jquery' ),
187 + '2.4.0',
188 + true
189 + );
184 190
185 - // *** Start of Backend & Frontend ***
191 + wp_register_script(
192 + 'tippy',
193 + getwid_get_plugin_url( 'vendors/tippy.js/tippy-bundle.umd.min.js' ),
194 + array( 'jquery', 'popper' ),
195 + '6.2.3',
196 + true
197 + );
186 198
187 - /**
188 - * Assets optimization. Currently in Beta.
189 - * @since 1.5.3
190 - */
191 - $_has_enabled_blocks = getwid()->blocksManager()->hasEnabledBlocks();
199 + wp_register_script(
200 + 'unescape',
201 + getwid_get_plugin_url( 'vendors/lodash.unescape/unescape.min.js' ),
202 + array(),
203 + '4.0.1',
204 + true
205 + );
192 206
193 - if ( $_has_enabled_blocks ) {
207 + wp_register_style(
208 + 'tippy-themes',
209 + getwid_get_plugin_url( 'vendors/tippy.js/themes.css' ),
210 + array(),
211 + '6.2.3'
212 + );
194 213
195 - if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() || is_admin() ) {
214 + wp_register_style(
215 + 'tippy-animation',
216 + getwid_get_plugin_url( 'vendors/tippy.js/animations.css' ),
217 + array(),
218 + '6.2.3'
219 + );
220 + }
196 221
197 - $rtl = is_rtl() ? '.rtl' : '';
222 + public function setup_editor_global_data() {
223 + $disabled_blocks = array();
224 + $disabled_blocks_data = array();
225 + if ( getwid()->blocksManager()->hasDisabledBlocks() ) {
226 + $disabled_blocks = getwid()->blocksManager()->getDisabledBlocks();
227 + foreach ( $disabled_blocks as $block ) {
228 + $disabled_blocks_data[] = $block->get_block_name();
229 + }
230 + }
198 231
199 - wp_enqueue_style(
200 - "{$this->prefix}-blocks",
201 - getwid_get_plugin_url( 'assets/css/blocks.style' . $rtl . '.css' ),
232 + $current_user_can_manage_options = current_user_can( 'manage_options' );
202 233
203 - // section, banner, icon-box, icon, image-box, image-hotspot, media-text-slider, video-popup, post-carousel, post-slider, images-slider
204 - /**
205 - * Filters frontend style dependencies.
206 - */
207 - apply_filters(
208 - 'getwid/blocks_style_css/dependencies',
209 - []
210 - ),
211 - $this->version
212 - );
234 + $mailchimp_api_key = get_option( 'getwid_mailchimp_api_key', '' );
213 235
214 - wp_add_inline_style( "{$this->prefix}-blocks", getwid_generate_section_content_width_css() );
215 - wp_add_inline_style( "{$this->prefix}-blocks", getwid_generate_smooth_animation_css() );
216 - }
217 -
236 + if ( ! $current_user_can_manage_options ) {
237 + $mailchimp_api_key = $mailchimp_api_key ? '1' : '';
218 238 }
219 239
220 - // *** End of Backend & Frontend ***
240 + $recaptcha_site_key = $current_user_can_manage_options ? get_option( 'getwid_recaptcha_v2_site_key', '' ) : '1';
241 + $recaptcha_secret_key = $current_user_can_manage_options ? get_option( 'getwid_recaptcha_v2_secret_key', '' ) : '1';
221 242
222 - /**
223 - * Assets optimization. Currently in Beta.
224 - * @since 1.5.3
225 - */
226 - if ( is_admin() || ! $_has_enabled_blocks || ( TRUE == getwid()->assetsOptimization()->load_assets_on_demand() ) ) {
227 - return;
228 - }
243 + $data = apply_filters(
244 + 'getwid/editor_blocks_js/localize_data',
245 + array(
246 + 'disabled_blocks' => $disabled_blocks_data,
247 + 'settings' => array(
248 + 'wide_support' => get_theme_support( 'align-wide' ),
249 + 'date_time_utc' => current_time( 'Y-m-d H:i:s' ),
250 + 'post_type' => get_post_type(),
251 + 'google_api_key' => get_option( 'getwid_google_api_key', '' ),
252 + 'instagram_token_isset' => (bool) get_option( 'getwid_instagram_token', '' ),
229 253
230 - /**
231 - * Filters frontend script dependencies.
232 - */
233 - wp_enqueue_script(
234 - "{$this->prefix}-blocks-frontend-js",
235 - getwid_get_plugin_url( 'assets/js/frontend.blocks.js' ),
236 - apply_filters(
237 - 'getwid/frontend_blocks_js/dependencies',
238 - [ 'jquery' ]
239 - ),
240 - $this->version,
241 - true
242 - );
243 - }
254 + 'assets_path' => getwid_get_plugin_url( '/assets' ),
255 + 'image_sizes' => $this->get_image_sizes(),
244 256
245 - public function localizeFrontend() {
246 - wp_localize_script(
247 - "{$this->prefix}-blocks-frontend-js",
248 - 'Getwid',
249 - apply_filters(
250 - 'getwid/frontend_blocks_js/localize_data',
251 - [
252 - 'settings' => [],
253 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
254 - 'isRTL' => is_rtl(),
255 - 'nonces' => array(
256 - 'contact_form' => wp_create_nonce( 'getwid_nonce_send_contact_form' )
257 - ),
258 - ]
257 + 'excerpt_length' => apply_filters( 'excerpt_length', 55 ),
258 + 'recaptcha_site_key' => $recaptcha_site_key,
259 + 'recaptcha_secret_key' => $recaptcha_secret_key,
260 + 'mailchimp_api_key' => $mailchimp_api_key,
261 + 'debug' => ( defined( 'WP_DEBUG' ) ? WP_DEBUG : false ),
262 + ),
263 + 'templates' => array(
264 + 'name' => getwid()->postTemplatePart()->postType,
265 + 'new' => admin_url( 'post-new.php?post_type=' . getwid()->postTemplatePart()->postType ),
266 + 'view' => admin_url( 'edit.php?post_type=' . getwid()->postTemplatePart()->postType ),
267 + 'edit' => admin_url( 'post.php?post=' ),
268 + ),
269 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
270 + 'options_general_url' => admin_url( 'options-general.php' ),
271 + 'get_instagram_token_url' => add_query_arg(
272 + array( 'nonce' => wp_create_nonce( 'getwid_nonce_save_instagram_token' ) ),
273 + admin_url( 'options-general.php' )
274 + ),
275 + 'options_url' => array(
276 + 'general' => getwid()->settingsPage()->getTabUrl( 'general' ),
277 + 'appearance' => getwid()->settingsPage()->getTabUrl( 'appearance' ),
278 + 'blocks' => getwid()->settingsPage()->getTabUrl( 'blocks' ),
279 + ),
280 + 'nonces' => array(
281 + 'google_api_key' => wp_create_nonce( 'getwid_nonce_google_api_key' ),
282 + 'recaptcha_v2' => wp_create_nonce( 'getwid_nonce_recaptcha_v2' ),
283 + 'mailchimp_api_key' => wp_create_nonce( 'getwid_nonce_mailchimp_api_key' ),
284 + 'check_instagram_token' => wp_create_nonce( 'getwid_nonce_check_instagram_token' ),
285 + ),
286 + 'acf_exist' => getwid_acf_is_active(),
287 + 'current_user' => array(
288 + 'can_manage_options' => $current_user_can_manage_options,
289 + ),
259 290 )
260 291 );
292 +
293 + wp_add_inline_script( 'wp-blocks', 'const Getwid = ' . wp_json_encode( $data ), 'before' );
261 294 }
262 295
263 - public function wp_late_enqueue_scripts() {
296 + public function get_image_sizes() {
264 297
265 - $should_enqueue_common_style = apply_filters('getwid/optimize/should_load_common_css', false);
298 + global $_wp_additional_image_sizes;
266 299
267 - if ( TRUE == getwid()->assetsOptimization()->load_assets_on_demand() && $should_enqueue_common_style ) {
300 + $intermediate_image_sizes = get_intermediate_image_sizes();
268 301
269 - $rtl = is_rtl() ? '.rtl' : '';
302 + $image_sizes = array();
303 + foreach ( $intermediate_image_sizes as $size ) {
304 + if ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
305 + $image_sizes[ $size ] = array(
306 + 'width' => $_wp_additional_image_sizes[ $size ]['width'],
307 + 'height' => $_wp_additional_image_sizes[ $size ]['height'],
308 + );
309 + } else {
310 + $image_sizes[ $size ] = array(
311 + 'width' => intval( get_option( "{$size}_size_w" ) ),
312 + 'height' => intval( get_option( "{$size}_size_h" ) ),
313 + );
314 + }
315 + }
270 316
271 - wp_enqueue_style(
272 - "{$this->prefix}-blocks-common",
273 - getwid_get_plugin_url( 'assets/blocks/common.style' . $rtl . '.css' ),
274 - [],
275 - $this->version
276 - );
317 + $sizes_arr = array();
318 + foreach ( $image_sizes as $key => $value ) {
319 + $temp_arr = array();
320 + $temp_arr['value'] = $key;
321 + $temp_arr['label'] = ucwords( strtolower( preg_replace( '/[-_]/', ' ', $key ) ) ) . " - {$value['width']} x {$value['height']}";
322 + $sizes_arr[] = $temp_arr;
277 323 }
324 +
325 + $sizes_arr[] = array(
326 + 'value' => 'full',
327 + 'label' => __( 'Full Size', 'getwid' ),
328 + );
329 +
330 + return $sizes_arr;
278 331 }
279 332
280 - public function enqueue_editor_section_css() {
281 - add_editor_style( getwid_generate_section_content_width_css() );
333 + public function enqueue_common_blocks_assets() {
334 + wp_enqueue_style(
335 + "{$this->prefix}-blocks-common",
336 + getwid_get_plugin_url( 'assets/common-styles/style.css' ),
337 + array(),
338 + $this->version,
339 + );
340 +
341 + wp_style_add_data( "{$this->prefix}-blocks-common", 'rtl', 'replace' );
342 +
343 + wp_add_inline_style( "{$this->prefix}-blocks-common", getwid_generate_section_content_width_css() );
344 + wp_add_inline_style( "{$this->prefix}-blocks-common", getwid_generate_smooth_animation_css() );
282 345 }
283 -
284 346 }