PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.2.2
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.2.2
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / Gutenberg / plugin.php
embedpress / Gutenberg Last commit date
block-backend 1 year ago css 1 year ago dist 1 year ago plugin.php 1 year ago
plugin.php
1432 lines
1 <?php
2
3 /**
4 * Blocks Initializer
5 *
6 * Enqueue CSS/JS of all the blocks.
7 *
8 * @since 1.0.0
9 * @package CGB
10 */
11
12 // Exit if accessed directly.
13 use EmbedPress\Includes\Classes\Helper;
14
15 if (!defined('ABSPATH')) {
16 exit;
17 }
18
19
20 /**
21 * Enqueue Gutenberg block assets for both frontend + backend.
22 *
23 * @uses {wp-editor} for WP editor styles.
24 * @since 1.0.0
25 */
26 function embedpress_blocks_cgb_block_assets()
27 { // phpcs:ignore
28 // Styles.
29 wp_register_style(
30 'embedpress_blocks-cgb-style-css', // Handle.
31 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.style.build.css', // Block style CSS.
32 is_admin() ? array('wp-editor') : null, // Dependency to include the CSS after it.
33 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.style.build.css') // Version: File modification time.
34 );
35 }
36
37 // Hook: Frontend assets.
38 add_action('enqueue_block_assets', 'embedpress_blocks_cgb_block_assets');
39
40 if (!function_exists('get_options_value')) {
41 function get_options_value($key)
42 {
43 $g_settings = get_option(EMBEDPRESS_PLG_NAME);
44
45 if (isset($g_settings[$key])) {
46 return $g_settings[$key];
47 }
48 return '';
49 }
50 }
51 if (!function_exists('get_branding_value')) {
52 function get_branding_value($key, $provider)
53 {
54 $settings = get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []);
55
56 if (isset($settings['branding']) && $settings['branding'] === 'yes' && isset($settings[$key])) {
57 return $settings[$key];
58 }
59 return '';
60 }
61 }
62
63
64 /**
65 * Enqueue Gutenberg block assets for backend editor.
66 *
67 * @uses {wp-blocks} for block type registration & related functions.
68 * @uses {wp-element} for WP Element abstraction — structure of blocks.
69 * @uses {wp-i18n} to internationalize the block's text.
70 * @uses {wp-editor} for WP editor styles.
71 * @since 1.0.0
72 */
73
74 if (!function_exists('embedpress_get_user_roles')) {
75 function embedpress_get_user_roles()
76 {
77 global $wp_roles; // Access global roles object
78 $user_roles = [];
79
80 if (isset($wp_roles->roles) && is_array($wp_roles->roles)) {
81 foreach ($wp_roles->roles as $role_key => $role_data) {
82 $user_roles[] = [
83 'value' => $role_key, // Machine-readable key
84 'label' => $role_data['name'], // Human-readable name
85 ];
86 }
87 }
88
89 return $user_roles;
90 }
91 }
92
93 function embedpress_blocks_cgb_editor_assets()
94 { // phpcs:ignore
95 // Scripts.
96
97 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
98 $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
99
100 if (!wp_script_is('embedpress-pdfobject')) {
101 wp_enqueue_script(
102 'embedpress-pdfobject',
103 EMBEDPRESS_URL_ASSETS . 'js/pdfobject.js',
104 [],
105 EMBEDPRESS_VERSION
106 );
107 }
108
109 wp_enqueue_script(
110 'embedpress_blocks-cgb-block-js', // Handle.
111 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.build.js', // Block.build.js: We register the block here. Built with Webpack.
112 array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-api-fetch', 'wp-is-shallow-equal', 'wp-editor', 'wp-components', 'embedpress-pdfobject'), // Dependencies, defined above.
113 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.build.js'), // Version: File modification time.
114 true // Enqueue the script in the footer.
115 );
116
117 if (!empty($g_blocks['document'])) {
118 wp_enqueue_script(
119 'embedpress_documents_viewer_script',
120 EMBEDPRESS_PLUGIN_DIR_URL . 'assets/js/documents-viewer-script.js',
121 array('wp-blocks', 'wp-dom-ready', 'wp-edit-post'),
122 EMBEDPRESS_PLUGIN_VERSION,
123 true
124 );
125 }
126
127 $wistia_labels = array(
128 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
129 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
130 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
131 );
132 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
133 $active_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
134
135 $wistia_labels = json_encode($wistia_labels);
136 $wistia_options = null;
137 if (function_exists('embedpress_wisita_pro_get_options')) :
138 $wistia_options = embedpress_wisita_pro_get_options();
139 endif;
140 $pars_url = wp_parse_url(get_site_url());
141 $documents_cta_options = (array) get_option(EMBEDPRESS_PLG_NAME . ':document');
142 $current_user = wp_get_current_user();
143
144 wp_localize_script('embedpress_blocks-cgb-block-js', 'embedpressObj', array(
145 'wistia_labels' => $wistia_labels,
146 'wisita_options' => $wistia_options,
147 'embedpress_powered_by' => apply_filters('embedpress_document_block_powered_by', true),
148 'embedpress_pro' => defined('EMBEDPRESS_PRO_PLUGIN_FILE'),
149 'twitch_host' => !empty($pars_url['host']) ? $pars_url['host'] : '',
150 'site_url' => site_url(),
151 'active_blocks' => $active_blocks,
152 'document_cta' => $documents_cta_options,
153 'pdf_renderer' => Helper::get_pdf_renderer(),
154 'is_pro_plugin_active' => defined('EMBEDPRESS_SL_ITEM_SLUG'),
155 'ajaxurl' => admin_url('admin-ajax.php'),
156 'source_nonce' => wp_create_nonce('source_nonce_embedpress'),
157 'can_upload_media' => current_user_can('upload_files'),
158 'EMBEDPRESS_URL_ASSETS' => EMBEDPRESS_URL_ASSETS,
159 'iframe_width' => get_options_value('enableEmbedResizeWidth'),
160 'iframe_height' => get_options_value('enableEmbedResizeHeight'),
161 'pdf_custom_color' => get_options_value('custom_color'),
162 'pdf_custom_color' => get_options_value('custom_color'),
163 'youtube_brand_logo_url' => get_branding_value('logo_url', 'youtube'),
164 'vimeo_brand_logo_url' => get_branding_value('logo_url', 'vimeo'),
165 'wistia_brand_logo_url' => get_branding_value('logo_url', 'wistia'),
166 'twitch_brand_logo_url' => get_branding_value('logo_url', 'twitch'),
167 'dailymotion_brand_logo_url' => get_branding_value('logo_url', 'dailymotion'),
168 'user_roles' => embedpress_get_user_roles(),
169 'current_user' => $current_user->data,
170 'is_embedpress_feedback_submited' => get_option('embedpress_feedback_submited'),
171
172 ));
173
174 // Styles.
175 wp_enqueue_style(
176 'embedpress_blocks-cgb-block-editor-css', // Handle.
177 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.editor.build.css', // Block editor CSS.
178 array('wp-edit-blocks'), // Dependency to include the CSS after it.
179 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.editor.build.css') // Version: File modification time.
180 );
181 wp_enqueue_style('embedpress_blocks-cgb-style-css');
182 }
183
184 // Hook: Editor assets.
185 add_action('enqueue_block_editor_assets', 'embedpress_blocks_cgb_editor_assets');
186
187
188 function embedpress_block_category($categories, $post)
189 {
190 return array_merge(
191 $categories,
192 array(
193 array(
194 'slug' => 'embedpress',
195 'title' => 'EmbedPress',
196 'icon' => '',
197 ),
198 )
199 );
200 }
201 $wp_version = get_bloginfo('version', 'display');
202 if (version_compare($wp_version, '5.8', '>=')) {
203 add_filter('block_categories_all', 'embedpress_block_category', 10, 2);
204 } else {
205 add_filter('block_categories', 'embedpress_block_category', 10, 2);
206 }
207
208
209
210
211 foreach (glob(EMBEDPRESS_GUTENBERG_DIR_PATH . 'block-backend/*.php') as $block_logic) {
212 require_once $block_logic;
213 }
214
215 /**
216 * Registers the embedpress gutneberg block on server.
217 */
218
219 function embedpress_gutenberg_register_all_block()
220 {
221 if (function_exists('register_block_type')) :
222
223 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
224 $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
225 $blocks_to_registers = ['twitch-block', 'google-slides-block', 'google-sheets-block', 'google-maps-block', 'google-forms-block', 'google-drawings-block', 'google-docs-block', 'embedpress', 'embedpress-pdf', 'embedpress-calendar', 'document'];
226
227 foreach ($blocks_to_registers as $blocks_to_register) {
228 if (!empty($g_blocks[$blocks_to_register])) {
229 if ('embedpress' === $blocks_to_register) {
230 register_block_type('embedpress/embedpress', [
231 'render_callback' => 'embedpress_render_block',
232 // 'style' => [
233 // 'plyr',
234 // ],
235 // 'script' => [
236 // 'plyr.polyfilled',
237 // 'initplyr',
238 // 'vimeo-player',
239 // 'embedpress-front',
240 // 'embedpress-ads',
241 // ],
242 'attributes' => array(
243 'clientId' => [
244 'type' => 'string',
245 ],
246 'height' => [
247 'type' => 'string',
248 'default' => get_options_value('enableEmbedResizeHeight')
249 ],
250 'width' => [
251 'type' => 'string',
252 'default' => get_options_value('enableEmbedResizeWidth')
253 ],
254 'lockContent' => [
255 'type' => 'boolean',
256 'default' => false
257 ],
258 'protectionType' => [
259 'type' => 'string',
260 'default' => 'password'
261 ],
262 'userRole' => [
263 'type' => 'array',
264 'default' => []
265 ],
266 'protectionMessage' => [
267 'type' => 'string',
268 'default' => 'You do not have access to this content. Only users with the following roles can view it: [user_roles]'
269 ],
270 'lockHeading' => [
271 'type' => 'string',
272 'default' => 'Content Locked'
273 ],
274 'lockSubHeading' => [
275 'type' => 'string',
276 'default' => 'Content is locked and requires password to access it.'
277 ],
278 'lockErrorMessage' => [
279 'type' => 'string',
280 'default' => 'Oops, that wasn\'t the right password. Try again.'
281 ],
282 'passwordPlaceholder' => [
283 'type' => 'string',
284 'default' => 'Password'
285 ],
286 'submitButtonText' => [
287 'type' => 'string',
288 'default' => 'Unlock'
289 ],
290 'submitUnlockingText' => [
291 'type' => 'string',
292 'default' => 'Unlocking'
293 ],
294 'enableFooterMessage' => [
295 'type' => 'boolean',
296 'default' => false
297 ],
298 'footerMessage' => [
299 'type' => 'string',
300 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
301 ],
302 'contentPassword' => [
303 'type' => 'string',
304 'default' => '',
305 ],
306 'contentShare' => [
307 'type' => 'boolean',
308 'default' => false
309 ],
310 'sharePosition' => [
311 'type' => 'string',
312 'default' => 'right'
313 ],
314 'customTitle' => [
315 'type' => 'string',
316 'default' => ''
317 ],
318 'customDescription' => [
319 'type' => 'string',
320 'default' => ''
321 ],
322 'customThumbnail' => [
323 'type' => 'string',
324 'default' => ''
325 ],
326
327 'videosize' => [
328 'type' => 'string',
329 'default' => 'fixed'
330 ],
331
332 'loadmore' => [
333 'type' => 'boolean',
334 'default' => false
335 ],
336 //Youtube Attributes
337 'starttime' => [
338 'type' => 'string',
339 ],
340 'endtime' => [
341 'type' => 'string',
342 ],
343 'autoplay' => [
344 'type' => 'boolean',
345 'default' => false
346 ],
347 'controls' => [
348 'type' => 'string',
349 ],
350 'progressbarcolor' => [
351 'type' => 'string',
352 ],
353 'videoannotations' => [
354 'type' => 'string',
355 ],
356 'closedcaptions' => [
357 'type' => 'boolean',
358 'default' => true
359 ],
360 'relatedvideos' => [
361 'type' => 'boolean',
362 'default' => true
363 ],
364 'fullscreen' => [
365 'type' => 'boolean',
366 'default' => true
367 ],
368
369 'modestbranding' => [
370 'type' => 'string',
371 ],
372 'pagesize' => [
373 'type' => 'number',
374 ],
375 // custom player attributes
376 'autoPause' => [
377 'type' => 'boolean',
378 'default' => false
379 ],
380 'customPlayer' => [
381 'type' => 'boolean',
382 'default' => false
383 ],
384
385 'posterThumbnail' => [
386 'type' => 'string',
387 'default' => ''
388 ],
389
390 'playerPreset' => [
391 'type' => 'string',
392 'default' => ''
393 ],
394
395 'playerColor' => [
396 'type' => 'string',
397 'default' => '#2e2e99'
398 ],
399
400 'playerPip' => [
401 'type' => 'boolean',
402 'default' => false
403 ],
404
405 'playerRestart' => [
406 'type' => 'boolean',
407 'default' => true
408 ],
409
410 'playerRewind' => [
411 'type' => 'boolean',
412 'default' => true
413 ],
414
415 'playerFastForward' => [
416 'type' => 'boolean',
417 'default' => true
418 ],
419 'playerTooltip' => [
420 'type' => 'boolean',
421 'default' => true
422 ],
423 'playerHideControls' => [
424 'type' => 'boolean',
425 'default' => true
426 ],
427 'playerDownload' => [
428 'type' => 'boolean',
429 'default' => true
430 ],
431 //Wistia Attributes
432 'wstarttime' => [
433 'type' => 'string',
434 ],
435 'wautoplay' => [
436 'type' => 'boolean',
437 'default' => true
438 ],
439 'scheme' => [
440 'type' => 'string',
441 ],
442 'captions' => [
443 'type' => 'boolean',
444 'default' => true
445 ],
446 'playbutton' => [
447 'type' => 'boolean',
448 'default' => true
449 ],
450 'smallplaybutton' => [
451 'type' => 'boolean',
452 'default' => true
453 ],
454 'playbar' => [
455 'type' => 'boolean',
456 'default' => true
457 ],
458 'resumable' => [
459 'type' => 'boolean',
460 'default' => true
461 ],
462 'wistiafocus' => [
463 'type' => 'boolean',
464 'default' => true
465 ],
466 'volumecontrol' => [
467 'type' => 'boolean',
468 'default' => true
469 ],
470 'volume' => [
471 'type' => 'number',
472 'default' => 100
473 ],
474 'rewind' => [
475 'type' => 'boolean',
476 'default' => false
477 ],
478 'wfullscreen' => [
479 'type' => 'boolean',
480 'default' => true
481 ],
482
483 // Vimeo attributes
484 'vstarttime' => [
485 'type' => 'string',
486 ],
487 'vautoplay' => [
488 'type' => 'boolean',
489 'default' => false
490 ],
491 'vscheme' => [
492 'type' => 'string',
493 ],
494 'vtitle' => [
495 'type' => 'boolean',
496 'default' => true
497 ],
498 'vauthor' => [
499 'type' => 'boolean',
500 'default' => true
501 ],
502 'vavatar' => [
503 'type' => 'boolean',
504 'default' => true
505 ],
506 'vloop' => [
507 'type' => 'boolean',
508 'default' => false
509 ],
510 'vautopause' => [
511 'type' => 'boolean',
512 'default' => false
513 ],
514 'vdnt' => [
515 'type' => 'boolean',
516 'default' => false
517 ],
518
519 // instaFeed attributes
520 'instaLayout' => [
521 'type' => 'string',
522 'default' => 'insta-grid',
523 ],
524 'instafeedFeedType' => [
525 'type' => 'string',
526 'default' => 'user_account_type',
527 ],
528 'instafeedAccountType' => [
529 'type' => 'string',
530 'default' => 'personal',
531 ],
532 'instafeedProfileImage' => [
533 'type' => 'boolean',
534 'default' => true,
535 ],
536 'instafeedProfileImageUrl' => [
537 'type' => 'string',
538 'default' => '',
539 ],
540 'instafeedFollowBtn' => [
541 'type' => 'boolean',
542 'default' => true,
543 ],
544 'instafeedFollowBtnLabel' => [
545 'type' => 'string',
546 'default' => 'Follow',
547 ],
548 'instafeedPostsCount' => [
549 'type' => 'boolean',
550 'default' => true,
551 ],
552 'instafeedPostsCountText' => [
553 'type' => 'string',
554 'default' => '[count] posts',
555 ],
556 'instafeedFollowersCount' => [
557 'type' => 'boolean',
558 'default' => true,
559 ],
560 'instafeedFollowersCountText' => [
561 'type' => 'string',
562 'default' => '[count] followers',
563 ],
564 'instafeedAccName' => [
565 'type' => 'boolean',
566 'default' => true,
567 ],
568 'instafeedColumns' => [
569 'type' => 'string',
570 'default' => '3',
571 ],
572 'instafeedColumnsGap' => [
573 'type' => 'string',
574 'default' => '5',
575 ],
576 'instafeedPostsPerPage' => [
577 'type' => 'string',
578 'default' => '12',
579 ],
580 'instafeedTab' => [
581 'type' => 'boolean',
582 'default' => true,
583 ],
584 'instafeedLikesCount' => [
585 'type' => 'boolean',
586 'default' => true,
587 ],
588 'instafeedCommentsCount' => [
589 'type' => 'boolean',
590 'default' => true,
591 ],
592 'instafeedPopup' => [
593 'type' => 'boolean',
594 'default' => true,
595 ],
596 'instafeedPopupFollowBtn' => [
597 'type' => 'boolean',
598 'default' => true,
599 ],
600 'instafeedPopupFollowBtnLabel' => [
601 'type' => 'string',
602 'default' => 'Follow',
603 ],
604 'instafeedLoadmore' => [
605 'type' => 'boolean',
606 'default' => true,
607 ],
608 'instafeedLoadmoreLabel' => [
609 'type' => 'string',
610 'default' => 'Load More',
611 ],
612 'slidesShow' => [
613 'type' => 'string',
614 'default' => '4',
615 ],
616 'slidesScroll' => [
617 'type' => 'string',
618 'default' => '4',
619 ],
620 'carouselAutoplay' => [
621 'type' => 'boolean',
622 'default' => false,
623 ],
624 'autoplaySpeed' => [
625 'type' => 'string',
626 'default' => '3000',
627 ],
628 'transitionSpeed' => [
629 'type' => 'string',
630 'default' => '1000',
631 ],
632 'carouselLoop' => [
633 'type' => 'boolean',
634 'default' => true,
635 ],
636 'carouselArrows' => [
637 'type' => 'boolean',
638 'default' => true,
639 ],
640 'carouselSpacing' => [
641 'type' => 'string',
642 'default' => '0',
643 ],
644 'carouselDots' => [
645 'type' => 'boolean',
646 'default' => false,
647 ],
648 // Calendly attributes
649 'cEmbedType' => array(
650 'type' => 'string',
651 'default' => 'inline'
652 ),
653 'calendlyData' => array(
654 'type' => 'boolean',
655 'default' => false
656 ),
657 'hideCookieBanner' => array(
658 'type' => 'boolean',
659 'default' => false
660 ),
661 'hideEventTypeDetails' => array(
662 'type' => 'boolean',
663 'default' => false
664 ),
665 'cBackgroundColor' => array(
666 'type' => 'string',
667 'default' => 'ffffff'
668 ),
669 'cTextColor' => array(
670 'type' => 'string',
671 'default' => '1A1A1A'
672 ),
673 'cButtonLinkColor' => array(
674 'type' => 'string',
675 'default' => '0000FF'
676 ),
677 'cPopupButtonText' => array(
678 'type' => 'string',
679 'default' => 'Schedule time with me'
680 ),
681 'cPopupButtonBGColor' => array(
682 'type' => 'string',
683 'default' => '#0000FF'
684 ),
685 'cPopupButtonTextColor' => array(
686 'type' => 'string',
687 'default' => '#FFFFFF'
688 ),
689 'cPopupLinkText' => array(
690 'type' => 'string',
691 'default' => 'Schedule time with me'
692 ),
693
694 //Ad attributes
695 'adManager' => [
696 'type' => 'boolean',
697 'default' => false
698 ],
699 'adSource' => [
700 'type' => 'string',
701 'default' => 'video'
702 ],
703 'adContent' => [
704 'type' => 'object',
705 ],
706 'adWidth' => array(
707 'type' => 'string',
708 'default' => '300'
709 ),
710 'adHeight' => array(
711 'type' => 'string',
712 'default' => '200'
713 ),
714 'adXPosition' => array(
715 'type' => 'number',
716 'default' => 25
717 ),
718 'adYPosition' => array(
719 'type' => 'number',
720 'default' => 10
721 ),
722 'adUrl' => [
723 'type' => 'string',
724 'default' => ''
725 ],
726 'adStart' => [
727 'type' => 'string',
728 'default' => '10'
729 ],
730 'adSkipButton' => [
731 'type' => 'boolean',
732 'default' => true
733 ],
734 'adSkipButtonAfter' => [
735 'type' => 'string',
736 'default' => '5'
737 ]
738
739 ),
740 ]);
741 } elseif ('embedpress-pdf' === $blocks_to_register) {
742 register_block_type('embedpress/embedpress-pdf', [
743 'attributes' => array(
744 'clientId' => [
745 'type' => 'string',
746 ],
747 // 'height' => [
748 // 'type' => 'string',
749 // 'default' => (int) get_options_value('enableEmbedResizeHeight')
750 // ],
751 // 'width' => [
752 // 'type' => 'string',
753 // 'default' => (int) get_options_value('enableEmbedResizeWidth')
754 // ],
755 'customColor' => [
756 'type' => 'string',
757 'default' => get_options_value('custom_color')
758 ],
759 'powered_by' => [
760 'type' => 'boolean',
761 'default' => true
762 ],
763 'lockContent' => [
764 'type' => 'boolean',
765 'default' => false
766 ],
767 'protectionType' => [
768 'type' => 'string',
769 'default' => 'password'
770 ],
771 'userRole' => [
772 'type' => 'array',
773 'default' => []
774 ],
775 'protectionMessage' => [
776 'type' => 'string',
777 'default' => 'You do not have access to this content. Only users with the following roles can view it: [user_roles]'
778 ],
779 'lockHeading' => [
780 'type' => 'string',
781 'default' => 'Content Locked'
782 ],
783 'lockSubHeading' => [
784 'type' => 'string',
785 'default' => 'Content is locked and requires password to access it.'
786 ],
787 'passwordPlaceholder' => [
788 'type' => 'string',
789 'default' => 'Password'
790 ],
791 'submitButtonText' => [
792 'type' => 'string',
793 'default' => 'Unlock'
794 ],
795 'submitUnlockingText' => [
796 'type' => 'string',
797 'default' => 'Unlocking'
798 ],
799 'lockErrorMessage' => [
800 'type' => 'string',
801 'default' => 'Oops, that wasn\'t the right password. Try again.'
802 ],
803 'enableFooterMessage' => [
804 'type' => 'boolean',
805 'default' => false
806 ],
807 'footerMessage' => [
808 'type' => 'string',
809 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
810 ],
811 'contentPassword' => [
812 'type' => 'string',
813 'default' => ''
814 ],
815 'contentShare' => [
816 'type' => 'boolean',
817 'default' => false
818 ],
819 'sharePosition' => [
820 'type' => 'string',
821 'default' => 'right'
822 ],
823 'presentation' => [
824 'type' => "boolean",
825 'default' => true,
826 ],
827 'lazyLoad' => [
828 'type' => "boolean",
829 'default' => false,
830 ],
831
832 'position' => [
833 'type' => "string",
834 'default' => 'top',
835 ],
836 'flipbook_toolbar_position' => [
837 'type' => "string",
838 'default' => 'bottom',
839 ],
840
841 'print' => [
842 'type' => "boolean",
843 'default' => true,
844 ],
845
846 'download' => [
847 'type' => "boolean",
848 'default' => true,
849 ],
850 'open' => [
851 'type' => "boolean",
852 'default' => true,
853 ],
854 'selection_tool' => [
855 'type' => "string",
856 'default' => '0',
857 ],
858 'scrolling' => [
859 'type' => "string",
860 'default' => '-1',
861 ],
862 'spreads' => [
863 'type' => "string",
864 'default' => '-1',
865 ],
866 'copy_text' => [
867 'type' => "boolean",
868 'default' => true,
869 ],
870 'add_text' => [
871 'type' => "boolean",
872 'default' => true,
873 ],
874 'draw' => [
875 'type' => "boolean",
876 'default' => true,
877 ],
878 'toolbar' => [
879 'type' => "boolean",
880 'default' => true,
881 ],
882 'doc_details' => [
883 'type' => "boolean",
884 'default' => true,
885 ],
886 'doc_rotation' => [
887 'type' => "boolean",
888 'default' => true,
889 ],
890 'add_image' => [
891 'type' => "boolean",
892 'default' => true,
893 ],
894 'unitoption' => [
895 'type' => "string",
896 'default' => '%',
897 ],
898 'zoomIn' => [
899 'type' => "boolean",
900 'default' => true,
901 ],
902 'zoomOut' => [
903 'type' => "boolean",
904 'default' => true,
905 ],
906 'fitView' => [
907 'type' => "boolean",
908 'default' => true,
909 ],
910 'bookmark' => [
911 'type' => "boolean",
912 'default' => true,
913 ],
914 //Spreaker
915 'theme' => array(
916 'type' => 'string',
917 'default' => 'light',
918 ),
919 'color' => array(
920 'type' => 'string',
921 'default' => '',
922 ),
923 'coverImageUrl' => array(
924 'type' => 'string',
925 'default' => '',
926 ),
927 'playlist' => array(
928 'type' => 'boolean',
929 'default' => false,
930 ),
931 'playlistContinuous' => array(
932 'type' => 'boolean',
933 'default' => false,
934 ),
935 'playlistLoop' => array(
936 'type' => 'boolean',
937 'default' => false,
938 ),
939 'playlistAutoupdate' => array(
940 'type' => 'boolean',
941 'default' => true,
942 ),
943 'chaptersImage' => array(
944 'type' => 'boolean',
945 'default' => true,
946 ),
947 'episodeImagePosition' => array(
948 'type' => 'string',
949 'default' => 'right',
950 ),
951 'hideLikes' => array(
952 'type' => 'boolean',
953 'default' => false,
954 ),
955 'hideComments' => array(
956 'type' => 'boolean',
957 'default' => false,
958 ),
959 'hideSharing' => array(
960 'type' => 'boolean',
961 'default' => false,
962 ),
963 'hideLogo' => array(
964 'type' => 'boolean',
965 'default' => false,
966 ),
967 'hideEpisodeDescription' => array(
968 'type' => 'boolean',
969 'default' => false,
970 ),
971 'hidePlaylistDescriptions' => array(
972 'type' => 'boolean',
973 'default' => false,
974 ),
975 'hidePlaylistImages' => array(
976 'type' => 'boolean',
977 'default' => false,
978 ),
979 'hideDownload' => array(
980 'type' => 'boolean',
981 'default' => false,
982 ),
983 'mode' => array(
984 'type' => 'string',
985 'default' => 'carousel'
986 ),
987 'imageWidth' => array(
988 'type' => 'number',
989 'default' => 800
990 ),
991 'imageHeight' => array(
992 'type' => 'number',
993 'default' => 600
994 ),
995 'playerAutoplay' => array(
996 'type' => 'boolean',
997 'default' => false
998 ),
999 'delay' => array(
1000 'type' => 'number',
1001 'default' => 5
1002 ),
1003 'repeat' => array(
1004 'type' => 'boolean',
1005 'default' => true
1006 ),
1007 'mediaitemsAspectRatio' => array(
1008 'type' => 'boolean',
1009 'default' => true
1010 ),
1011 'mediaitemsEnlarge' => array(
1012 'type' => 'boolean',
1013 'default' => false
1014 ),
1015 'mediaitemsStretch' => array(
1016 'type' => 'boolean',
1017 'default' => false
1018 ),
1019 'mediaitemsCover' => array(
1020 'type' => 'boolean',
1021 'default' => false
1022 ),
1023 'backgroundColor' => array(
1024 'type' => 'string',
1025 'default' => ''
1026 ),
1027 'expiration' => array(
1028 'type' => 'number',
1029 'default' => 60
1030 ),
1031 //Ad attributes
1032 'adManager' => [
1033 'type' => 'boolean',
1034 'default' => false
1035 ],
1036 'adSource' => [
1037 'type' => 'string',
1038 'default' => 'video'
1039 ],
1040 'adContent' => [
1041 'type' => 'object',
1042 ],
1043 'adWidth' => array(
1044 'type' => 'string',
1045 'default' => '300'
1046 ),
1047 'adHeight' => array(
1048 'type' => 'string',
1049 'default' => '200'
1050 ),
1051 'adXPosition' => array(
1052 'type' => 'number',
1053 'default' => 25
1054 ),
1055 'adYPosition' => array(
1056 'type' => 'number',
1057 'default' => 20
1058 ),
1059 'adUrl' => [
1060 'type' => 'string',
1061 'default' => ''
1062 ],
1063 'adStart' => [
1064 'type' => 'string',
1065 'default' => '10'
1066 ],
1067 'adSkipButton' => [
1068 'type' => 'boolean',
1069 'default' => true
1070 ],
1071 'adSkipButtonAfter' => [
1072 'type' => 'string',
1073 'default' => '5'
1074 ]
1075 ),
1076 'render_callback' => 'embedpress_pdf_render_block',
1077 ]);
1078 } elseif ('embedpress-calendar' === $blocks_to_register) {
1079 register_block_type('embedpress/embedpress-calendar', [
1080 'render_callback' => 'embedpress_calendar_render_block',
1081 ]);
1082 } elseif ('document' === $blocks_to_register) {
1083 register_block_type('embedpress/' . $blocks_to_register, [
1084 // 'render_callback' => 'embedpress_document_render_block',
1085 ]);
1086 } else {
1087 register_block_type('embedpress/' . $blocks_to_register);
1088 }
1089 } else {
1090
1091 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
1092 unregister_block_type('embedpress/' . $blocks_to_register);
1093 }
1094 }
1095 }
1096
1097 endif;
1098 }
1099
1100 add_action('init', 'embedpress_gutenberg_register_all_block');
1101
1102 function getParamData($attributes)
1103 {
1104
1105 $urlParamData = array(
1106 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
1107 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
1108 'position' => $attributes['position'] ?? 'top',
1109 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
1110 'lazyLoad' => !empty($attributes['lazyLoad']) ? 'true' : 'false',
1111 'download' => !empty($attributes['download']) ? 'true' : 'false',
1112 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
1113 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
1114 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
1115 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
1116 'add_image' => !empty($attributes['add_image']) ? 'true' : 'false',
1117 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
1118 'zoom_in' => !empty($attributes['zoomIn']) ? 'true' : 'false',
1119 'zoom_out' => !empty($attributes['zoomOut']) ? 'true' : 'false',
1120 'fit_view' => !empty($attributes['fitView']) ? 'true' : 'false',
1121 'bookmark' => !empty($attributes['bookmark']) ? 'true' : 'false',
1122 'flipbook_toolbar_position' => !empty($attributes['flipbook_toolbar_position']) ? $attributes['flipbook_toolbar_position'] : 'bottom',
1123 'selection_tool' => isset($attributes['selection_tool']) ? esc_attr($attributes['selection_tool']) : '0',
1124 'scrolling' => isset($attributes['scrolling']) ? esc_attr($attributes['scrolling']) : '-1',
1125 'spreads' => isset($attributes['spreads']) ? esc_attr($attributes['spreads']) : '-1',
1126 );
1127
1128 if ($urlParamData['themeMode'] == 'custom') {
1129 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
1130 }
1131
1132 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] == 'flip-book') {
1133 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1134 }
1135
1136 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1137 }
1138
1139 function embedpress_pdf_block_scripts($attributes)
1140 {
1141
1142 $script_handles = [];
1143
1144 $script_handles[] = 'embedpress-pdfobject';
1145 $script_handles[] = 'embedpress-front';
1146
1147 if (!empty($attributes['adManager'])) {
1148 $script_handles[] = 'embedpress-ads';
1149 }
1150
1151 foreach ($script_handles as $handle) {
1152 wp_enqueue_script($handle);
1153 }
1154
1155 $style_handles = [
1156 'embedpress_blocks-cgb-style-css',
1157 'embedpress-style'
1158 ];
1159
1160 foreach ($style_handles as $handle) {
1161 wp_enqueue_style($handle);
1162 }
1163 }
1164
1165 if (!function_exists('has_content_allowed_roles')) {
1166 function has_content_allowed_roles($allowed_roles = [])
1167 {
1168
1169 if ((count($allowed_roles) === 1 && empty($allowed_roles[0]))) {
1170 return true;
1171 }
1172
1173 $current_user = wp_get_current_user();
1174 $user_roles = $current_user->roles;
1175
1176 return !empty(array_intersect($user_roles, $allowed_roles));
1177 }
1178 }
1179
1180
1181
1182 function embedpress_pdf_render_block($attributes)
1183 {
1184 embedpress_pdf_block_scripts($attributes);
1185
1186 if (!empty($attributes['href'])) {
1187 $renderer = Helper::get_pdf_renderer();
1188 $pdf_url = $attributes['href'];
1189 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
1190 $client_id = md5($id);
1191
1192
1193 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
1194 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : (get_options_value('enableEmbedResizeWidth') ?: 600) . 'px';
1195
1196
1197 if ($unitoption == '%') {
1198 $width_class = ' ep-percentage-width';
1199 } else {
1200 $width_class = 'ep-fixed-width';
1201 }
1202 $content_share_class = '';
1203 $share_position_class = '';
1204 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
1205
1206 if (!empty($attributes['contentShare'])) {
1207 $content_share_class = 'ep-content-share-enabled';
1208 $share_position_class = 'ep-share-position-' . $share_position;
1209 }
1210
1211 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
1212 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
1213
1214
1215 $content_protection_class = 'ep-content-protection-enabled';
1216 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
1217 $content_protection_class = 'ep-content-protection-disabled';
1218 }
1219
1220
1221 $height = !empty($attributes['height'])
1222 ? $attributes['height'] . 'px'
1223 : (get_options_value('enableEmbedResizeHeight') ?: 600) . 'px';
1224
1225 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1226
1227 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1228 if (isset($attributes['powered_by'])) {
1229 $powered_by = $attributes['powered_by'];
1230 }
1231
1232 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
1233
1234 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
1235
1236 $aligns = [
1237 'left' => 'ep-alignleft',
1238 'right' => 'ep-alignright',
1239 'center' => 'ep-aligncenter',
1240 'wide' => 'ep-alignwide',
1241 'full' => 'ep-alignfull'
1242 ];
1243 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1244 $dimension = "width:$width;height:$height";
1245 ob_start();
1246 ?>
1247
1248
1249 <?php
1250
1251 $url = !empty($attributes['href']) ? $attributes['href'] : '';
1252
1253 $embed_code = '<iframe title="' . esc_attr(Helper::get_file_title($attributes['href'])) . '" class="embedpress-embed-document-pdf ' . esc_attr($id) . '" style="' . esc_attr($dimension) . '; max-width:100%; display: inline-block" src="' . esc_url($src) . '" frameborder="0" oncontextmenu="return false;"></iframe> ';
1254
1255 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] === 'flip-book') {
1256 $src = urlencode($url) . getParamData($attributes);
1257 $embed_code = '<iframe title="' . esc_attr(Helper::get_file_title($attributes['href'])) . '" class="embedpress-embed-document-pdf ' . esc_attr($id) . '" style="' . esc_attr($dimension) . '; max-width:100%; display: inline-block" src="' . esc_url(EMBEDPRESS_URL_ASSETS . 'pdf-flip-book/viewer.html?file=' . $src) . '" frameborder="0" oncontextmenu="return false;"></iframe> ';
1258 }
1259 if ($powered_by) {
1260 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1261 }
1262
1263 $adsAtts = '';
1264 if (!empty($attributes['adManager'])) {
1265 $ad = base64_encode(json_encode($attributes));
1266 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=sponsored-mask";
1267 }
1268 ?>
1269
1270 <div id="ep-gutenberg-content-<?php echo esc_attr($client_id) ?>" class="ep-gutenberg-content <?php echo esc_attr($alignment . ' ' . $width_class . ' ' . $content_share_class . ' ' . $share_position_class . ' ' . $content_protection_class); ?> ">
1271 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
1272 echo esc_attr('emebedpress-unit-percent');
1273 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
1274 $style_attr = 'max-width:' . $attributes['width'] . '%';
1275 } else {
1276 $style_attr = 'max-width:100%';
1277 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
1278 <div <?php echo esc_attr($adsAtts); ?>>
1279 <?php
1280 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
1281 $embed = $embed_code;
1282
1283 if (
1284 !apply_filters('embedpress/is_allow_rander', false) ||
1285 empty($attributes['lockContent']) || ($attributes['protectionType'] == 'password' && empty($attributes['contentPassword'])) || ($attributes['protectionType'] == 'password' && (!empty(Helper::is_password_correct($client_id))) && ($hash_pass === $password_correct)) || ($attributes['protectionType'] == 'user-role' && has_content_allowed_roles($attributes['userRole']))
1286 ) {
1287
1288 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
1289
1290 echo '<div class="ep-embed-content-wraper">';
1291 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1292 $embed .= $embed_code;
1293 $embed .= '</div>';
1294
1295 if (!empty($attributes['contentShare'])) {
1296 $content_id = $attributes['id'];
1297 $embed .= Helper::embed_content_share($content_id, $attributes);
1298 }
1299 echo $embed;
1300 echo '</div>';
1301 } else {
1302 if (!empty($attributes['contentShare'])) {
1303 $content_id = $attributes['clientId'];
1304 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1305 $embed .= $embed_code;
1306 $embed .= '</div>';
1307 $embed .= Helper::embed_content_share($content_id, $attributes);
1308 }
1309 echo '<div class="ep-embed-content-wraper">';
1310 if ($attributes['protectionType'] == 'password') {
1311 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $attributes);
1312 } else {
1313 do_action('embedpress/content_protection_content', $client_id, $attributes['protectionMessage'], $attributes['userRole']);
1314 }
1315 echo '</div>';
1316 }
1317
1318 ?>
1319
1320 <?php
1321 if (!empty($attributes['adManager'])) {
1322 $embed = apply_filters('embedpress/generate_ad_template', $embed, $client_id, $attributes, 'gutenberg');
1323 }
1324 ?>
1325 </div>
1326 </div>
1327 </div>
1328 <?php
1329 return ob_get_clean();
1330 }
1331 }
1332
1333 function isGoogleCalendar($url)
1334 {
1335 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1336 return preg_match($pattern, $url);
1337 }
1338
1339 function embedpress_calendar_render_block($attributes)
1340 {
1341
1342 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1343 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1344
1345 if (!isGoogleCalendar($url)) {
1346 return;
1347 }
1348
1349 $is_private = isset($attributes['is_public']);
1350 $client_id = md5($id);
1351 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1352 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1353 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1354 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1355 if (isset($attributes['powered_by'])) {
1356 $powered_by = $attributes['powered_by'];
1357 }
1358
1359 $aligns = [
1360 'left' => 'alignleft',
1361 'right' => 'alignright',
1362 'wide' => 'alignwide',
1363 'full' => 'alignfull'
1364 ];
1365 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1366 $dimension = "width:$width;height:$height";
1367 ob_start();
1368 ?>
1369 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1370
1371 <?php
1372 if (!empty($url) && !$is_private) {
1373 ?>
1374 <iframe title="<?php echo esc_attr(Helper::get_file_title($url)); ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block" src="<?php echo esc_url($url); ?>"></iframe>
1375 <?php } else {
1376 do_action('embedpress_google_helper_shortcode', 10);
1377 } ?>
1378 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1379
1380 <?php
1381 if ($powered_by) {
1382 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1383 } ?>
1384
1385 </div>
1386 <?php
1387 return ob_get_clean();
1388 }
1389
1390 function embedpress_document_block_scripts()
1391 {
1392 // Exit if this is the admin panel
1393 if (is_admin()) {
1394 return;
1395 }
1396
1397 global $post;
1398
1399 // Check for the presence of the 'embedpress/document' block
1400 $block_exists = false;
1401
1402 if (function_exists('has_block')) {
1403 $block_exists = has_block('embedpress/document');
1404 } elseif (isset($post->post_content)) {
1405 // Fallback for older WordPress versions
1406 $block_exists = strpos($post->post_content, '<!-- wp:embedpress/document') !== false;
1407 }
1408
1409 // If the block exists, enqueue the scripts and styles
1410 if ($block_exists) {
1411 $script_handles = [
1412 'embedpress-pdfobject',
1413 'embedpress-front',
1414 'embedpress_documents_viewer_script'
1415 ];
1416
1417 foreach ($script_handles as $handle) {
1418 wp_enqueue_script($handle);
1419 }
1420
1421 $style_handles = [
1422 'embedpress_blocks-cgb-style-css',
1423 'embedpress-style'
1424 ];
1425
1426 foreach ($style_handles as $handle) {
1427 wp_enqueue_style($handle);
1428 }
1429 }
1430 }
1431 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1432