PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.5.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.5.0
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 / Core / LocalizationManager.php
embedpress / Core Last commit date
AssetManager.php 2 months ago LocalizationManager.php 2 months ago init.php 9 months ago
LocalizationManager.php
622 lines
1 <?php
2
3 namespace EmbedPress\Core;
4
5 use EmbedPress\Includes\Classes\Helper;
6
7 /**
8 * EmbedPress Localization Manager
9 *
10 * Handles all JavaScript localization for EmbedPress blocks, admin, and frontend
11 * Provides clean separation of concerns from AssetManager
12 */
13 class LocalizationManager
14 {
15 /**
16 * Setup admin localization scripts
17 *
18 * @param string $hook Current admin page hook
19 */
20 public static function setup_admin_localization($hook)
21 {
22 global $pagenow;
23
24 self::setup_license_localization();
25 self::setup_feature_notices_localization();
26
27 // Setup settings page localization if on EmbedPress settings page
28 if (strpos($hook, 'embedpress') !== false) {
29 self::setup_settings_localization();
30 self::setup_preview_localization();
31 }
32
33 // Only setup localization on post edit pages
34 if (!in_array($pagenow, ['post.php', 'post-new.php'])) {
35 return;
36 }
37 }
38
39 /**
40 * Setup editor localization scripts
41 */
42 public static function setup_editor_localization()
43 {
44 self::setup_frontend_script_localization();
45 self::setup_gutenberg_localization();
46 self::setup_new_blocks_localization();
47 self::setup_preview_localization();
48 }
49
50 /**
51 * Setup frontend localization scripts
52 */
53 public static function setup_frontend_localization()
54 {
55 self::setup_frontend_script_localization();
56 self::setup_gutenberg_localization();
57 self::setup_preview_localization();
58 self::setup_analytics_localization();
59 self::setup_pdf_gallery_localization();
60 self::setup_pdf_lightbox_localization();
61 }
62
63 /**
64 * Setup Elementor widget localization
65 */
66 public static function setup_elementor_localization()
67 {
68 self::setup_frontend_script_localization();
69 self::setup_calendar_widget_localization();
70 self::setup_analytics_localization();
71 self::setup_pdf_gallery_localization();
72 self::setup_pdf_lightbox_localization();
73 }
74
75 /**
76 * Setup preview localization (attached to preview script)
77 */
78 private static function setup_preview_localization()
79 {
80 // Try both admin and preview script handles
81 $script_handles = ['embedpress-admin', 'embedpress-preview'];
82
83 $url_schemes = apply_filters('embedpress:getAdditionalURLSchemes', self::get_url_schemes());
84
85 // Ensure required constants are defined with fallbacks
86 $version = defined('EMBEDPRESS_VERSION') ? EMBEDPRESS_VERSION : '1.0.0';
87 $shortcode = defined('EMBEDPRESS_SHORTCODE') ? EMBEDPRESS_SHORTCODE : 'embedpress';
88 $assets_url = defined('EMBEDPRESS_URL_ASSETS') ? EMBEDPRESS_URL_ASSETS : '';
89
90 $localization_data = [
91 'previewSettings' => [
92 'baseUrl' => get_site_url() . '/',
93 'versionUID' => $version,
94 'debug' => defined('WP_DEBUG') && WP_DEBUG,
95 ],
96 'shortcode' => $shortcode,
97 'assetsUrl' => $assets_url,
98 'urlSchemes' => $url_schemes,
99 ];
100
101 foreach ($script_handles as $script_handle) {
102 if (wp_script_is($script_handle, 'enqueued') || wp_script_is($script_handle, 'registered')) {
103 wp_localize_script($script_handle, 'embedpressPreviewData', $localization_data);
104 }
105 }
106
107 wp_localize_script($script_handle, 'embedpressAdminParams', [
108 'ajaxUrl' => admin_url('admin-ajax.php'),
109 'nonce' => wp_create_nonce('embedpress')
110 ]);
111 }
112
113 /**
114 * Setup license script localization
115 */
116 private static function setup_license_localization()
117 {
118 $script_handle = 'embedpress-admin';
119
120 if (!wp_script_is($script_handle, 'enqueued') && !wp_script_is($script_handle, 'registered')) {
121 return;
122 }
123
124 $item_id = defined('EMBEDPRESS_SL_ITEM_ID') ? EMBEDPRESS_SL_ITEM_ID : 'embedpress';
125
126 wp_localize_script($script_handle, 'embedpressLicenseData', [
127 'nonce' => wp_create_nonce('wpdeveloper_sl_' . $item_id . '_nonce')
128 ]);
129 }
130
131 /**
132 * Setup feature notices script localization
133 */
134 private static function setup_feature_notices_localization()
135 {
136 $script_handle = 'embedpress-feature-notices';
137
138 if (!wp_script_is($script_handle, 'enqueued') && !wp_script_is($script_handle, 'registered')) {
139 return;
140 }
141
142 wp_localize_script($script_handle, 'embedpressFeatureNotices', [
143 'ajaxurl' => admin_url('admin-ajax.php'),
144 'nonce' => wp_create_nonce('embedpress_feature_notice'),
145 ]);
146 }
147
148 /**
149 * Setup Gutenberg blocks localization (embedpressObj variable)
150 */
151 private static function setup_gutenberg_localization()
152 {
153 $script_handle = 'embedpress-blocks-editor';
154
155 if (!wp_script_is($script_handle, 'enqueued') && !wp_script_is($script_handle, 'registered')) {
156 return;
157 }
158
159 // Ensure required constants are defined
160 if (!defined('EMBEDPRESS_PLG_NAME')) {
161 return;
162 }
163
164 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
165 $active_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
166
167 $wistia_labels = self::get_wistia_labels();
168 $wistia_options = self::get_wistia_options();
169 $pars_url = wp_parse_url(get_site_url());
170 $documents_cta_options = (array) get_option(EMBEDPRESS_PLG_NAME . ':document');
171 $current_user = wp_get_current_user();
172 $assets_url = defined('EMBEDPRESS_URL_ASSETS') ? EMBEDPRESS_URL_ASSETS : '';
173 $static_url = defined('EMBEDPRESS_URL_STATIC') ? EMBEDPRESS_URL_STATIC : '';
174
175 // Get global powered_by setting
176 $g_settings = get_option(EMBEDPRESS_PLG_NAME, []);
177 $powered_by_default = isset($g_settings['embedpress_document_powered_by']) && $g_settings['embedpress_document_powered_by'] === 'yes';
178 $lazy_load_default = isset($g_settings['g_lazyload']) && $g_settings['g_lazyload'] == 1;
179
180 wp_localize_script($script_handle, 'embedpressGutenbergData', [
181
182
183 // Keep only the variables that are actually used in JavaScript
184 'wistiaLabels' => json_encode($wistia_labels),
185 'wistiaOptions' => $wistia_options,
186 'poweredBy' => apply_filters('embedpress_document_block_powered_by', $powered_by_default),
187 'isProVersion' => defined('EMBEDPRESS_PRO_PLUGIN_FILE'),
188 'twitchHost' => !empty($pars_url['host']) ? $pars_url['host'] : '',
189 'siteUrl' => site_url(),
190 'activeBlocks' => $active_blocks,
191 'documentCta' => $documents_cta_options,
192 'pdfRenderer' => Helper::get_pdf_renderer(),
193 'flipbookRenderer' => Helper::get_flipbook_renderer(),
194 'isProPluginActive' => defined('EMBEDPRESS_SL_ITEM_SLUG'),
195 'ajaxUrl' => admin_url('admin-ajax.php'),
196 'adminUrl' => admin_url(),
197 'sourceNonce' => wp_create_nonce('source_nonce_embedpress'),
198 'canUploadMedia' => current_user_can('upload_files'),
199 'pdfGalleryNonce' => wp_create_nonce('ep_pdf_gallery_nonce'),
200 'assetsUrl' => $assets_url,
201 'staticUrl' => $static_url,
202 // Use underscore naming for consistency with block attributes
203 'iframe_width' => Helper::get_options_value('enableEmbedResizeWidth', '600'),
204 'iframe_height' => Helper::get_options_value('enableEmbedResizeHeight', '400'),
205 'iframeWidth' => Helper::get_options_value('enableEmbedResizeWidth', '600'), // Keep camelCase for backward compatibility
206 'iframeHeight' => Helper::get_options_value('enableEmbedResizeHeight', '400'), // Keep camelCase for backward compatibility
207 'pdfCustomColor' => Helper::get_options_value('custom_color', '#403A81'),
208 'lazyLoad' => $lazy_load_default,
209 'brandingLogos' => [
210 'youtube' => Helper::get_branding_value('logo_url', 'youtube'),
211 'vimeo' => Helper::get_branding_value('logo_url', 'vimeo'),
212 'wistia' => Helper::get_branding_value('logo_url', 'wistia'),
213 'twitch' => Helper::get_branding_value('logo_url', 'twitch'),
214 'dailymotion' => Helper::get_branding_value('logo_url', 'dailymotion'),
215 'document' => Helper::get_branding_value('logo_url', 'document'),
216 ],
217 'userRoles' => Helper::get_user_roles(),
218 'currentUser' => $current_user->data,
219 'feedbackSubmitted' => get_option('embedpress_feedback_submited'),
220 'ratingHelpDisabled' => Helper::get_options_value('turn_off_rating_help', false),
221 'milestoneDisabled' => Helper::get_options_value('turn_off_milestone', false),
222
223 // Legacy support
224 'wistia_labels' => json_encode($wistia_labels),
225 'wisita_options' => $wistia_options,
226 'embedpress_powered_by' => apply_filters('embedpress_document_block_powered_by', $powered_by_default),
227 'embedpress_pro' => defined('EMBEDPRESS_PRO_PLUGIN_FILE'),
228 'twitch_host' => !empty($pars_url['host']) ? $pars_url['host'] : '',
229 'site_url' => site_url(),
230 'rest_url' => get_rest_url(),
231 'embedpress_rest_url' => get_rest_url(null, 'embedpress/v1/oembed/embedpress'),
232 'active_blocks' => $active_blocks,
233 'document_cta' => $documents_cta_options,
234 'pdf_renderer' => Helper::get_pdf_renderer(),
235 'flipbook_renderer' => Helper::get_flipbook_renderer(),
236 'is_pro_plugin_active' => defined('EMBEDPRESS_SL_ITEM_SLUG'),
237 'ajaxurl' => admin_url('admin-ajax.php'),
238 'source_nonce' => wp_create_nonce('source_nonce_embedpress'),
239 'can_upload_media' => current_user_can('upload_files'),
240 'permalink_structure' => get_option('permalink_structure'),
241 'EMBEDPRESS_URL_ASSETS' => EMBEDPRESS_URL_ASSETS,
242 'iframe_width' => Helper::get_options_value('enableEmbedResizeWidth'),
243 'iframe_height' => Helper::get_options_value('enableEmbedResizeHeight'),
244 'pdf_custom_color' => Helper::get_options_value('custom_color'),
245 'pdf_custom_color' => Helper::get_options_value('custom_color'),
246 'youtube_brand_logo_url' => Helper::get_branding_value('logo_url', 'youtube'),
247 'vimeo_brand_logo_url' => Helper::get_branding_value('logo_url', 'vimeo'),
248 'wistia_brand_logo_url' => Helper::get_branding_value('logo_url', 'wistia'),
249 'twitch_brand_logo_url' => Helper::get_branding_value('logo_url', 'twitch'),
250 'dailymotion_brand_logo_url' => Helper::get_branding_value('logo_url', 'dailymotion'),
251 'user_roles' => Helper::get_user_roles(),
252 'current_user' => $current_user->data,
253 'is_embedpress_feedback_submited' => get_option('embedpress_feedback_submited'),
254 'turn_off_rating_help' => Helper::get_options_value('turn_off_rating_help'),
255 'turn_off_milestone' => Helper::get_options_value('turn_off_milestone'),
256 ]);
257 }
258
259 /**
260 * Setup frontend script localization (embedpressFrontendData variable)
261 */
262 private static function setup_frontend_script_localization()
263 {
264 // The embedpressFrontendData variable should be attached to multiple frontend scripts
265 $script_handles = ['embedpress-front', 'embedpress-ads'];
266
267 $localization_data = [
268 'ajaxurl' => admin_url('admin-ajax.php'),
269 'isProPluginActive' => defined('EMBEDPRESS_SL_ITEM_SLUG'),
270 'nonce' => wp_create_nonce('ep_nonce'),
271 ];
272
273 foreach ($script_handles as $script_handle) {
274 if (wp_script_is($script_handle, 'enqueued') || wp_script_is($script_handle, 'registered')) {
275 wp_localize_script($script_handle, 'embedpressFrontendData', $localization_data);
276 }
277 }
278 }
279
280 /**
281 * Setup settings page localization (attached to admin script)
282 */
283 private static function setup_settings_localization()
284 {
285 $script_handle = 'embedpress-admin';
286
287 if (!wp_script_is($script_handle, 'enqueued') && !wp_script_is($script_handle, 'registered')) {
288 return;
289 }
290
291 wp_localize_script($script_handle, 'embedpressSettingsData', [
292 'nonce' => wp_create_nonce('embedpress_elements_action'),
293 'ajaxNonce' => wp_create_nonce('embedpress_ajax_nonce'),
294 ]);
295 }
296
297 /**
298 * Setup new blocks localization (for new block system)
299 */
300 private static function setup_new_blocks_localization()
301 {
302 // Try multiple possible handles for new blocks
303 $possible_handles = [
304 'embedpress-blocks-editor', // Current handle from AssetManager
305 'embedpress-blocks', // Old handle
306 'embedpress_blocks-cgb-block-js', // Legacy handle
307 'embedpress-blocks-js', // Alternative handle
308 ];
309
310 $script_handle = null;
311 foreach ($possible_handles as $handle) {
312 if (wp_script_is($handle, 'enqueued') || wp_script_is($handle, 'registered')) {
313 $script_handle = $handle;
314 break;
315 }
316 }
317
318 if (!$script_handle) {
319 return;
320 }
321
322 // Ensure required constants are defined
323 if (!defined('EMBEDPRESS_PLG_NAME')) {
324 return;
325 }
326
327 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
328 $active_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
329
330 wp_localize_script($script_handle, 'embedpressNewBlocksData', [
331 'pluginDirPath' => defined('EMBEDPRESS_PATH_BASE') ? EMBEDPRESS_PATH_BASE : '',
332 'pluginDirUrl' => defined('EMBEDPRESS_URL_STATIC') ? EMBEDPRESS_URL_STATIC . '../' : '',
333 'activeBlocks' => $active_blocks,
334 'canUploadMedia' => current_user_can('upload_files'),
335 'ajaxUrl' => admin_url('admin-ajax.php'),
336 'nonce' => wp_create_nonce('embedpress_nonce'),
337 'restUrl' => rest_url('embedpress/v1/'),
338 'siteUrl' => site_url(),
339 ]);
340 }
341
342
343
344
345
346 /**
347 * Setup analytics tracker localization
348 */
349 private static function setup_analytics_localization()
350 {
351 $script_handle = 'embedpress-analytics-tracker';
352
353 if (!wp_script_is($script_handle, 'enqueued') && !wp_script_is($script_handle, 'registered')) {
354 return;
355 }
356
357 // Get analytics manager instance to check for embedded content
358 $has_embedded_content = false;
359 if (class_exists('EmbedPress\Includes\Classes\Analytics\Analytics_Manager')) {
360 $analytics_manager = \EmbedPress\Includes\Classes\Analytics\Analytics_Manager::get_instance();
361 $has_embedded_content = $analytics_manager->has_embedded_content();
362 }
363
364 // Get tracking enabled setting
365 $tracking_enabled = get_option('embedpress_analytics_tracking_enabled', true);
366
367 // Get original referrer if available
368 $original_referrer = '';
369 if (defined('EMBEDPRESS_ORIGINAL_REFERRER') && !empty(EMBEDPRESS_ORIGINAL_REFERRER)) {
370 $original_referrer = EMBEDPRESS_ORIGINAL_REFERRER;
371 }
372
373 // Get session ID safely
374 $session_id = self::get_analytics_session_id();
375
376 wp_localize_script($script_handle, 'embedpress_analytics', [
377 'ajax_url' => admin_url('admin-ajax.php'),
378 'rest_url' => rest_url('embedpress/v1/analytics/'),
379 'nonce' => wp_create_nonce('wp_rest'),
380 'session_id' => $session_id,
381 'page_url' => get_permalink(),
382 'post_id' => get_the_ID(),
383 'tracking_enabled' => (bool) $tracking_enabled,
384 'original_referrer' => $original_referrer,
385 'has_embedded_content' => $has_embedded_content
386 ]);
387 }
388
389 /**
390 * Setup Google Calendar widget localization
391 */
392 private static function setup_calendar_widget_localization()
393 {
394 $script_handle = 'epgc';
395
396 if (!wp_script_is($script_handle, 'enqueued') && !wp_script_is($script_handle, 'registered')) {
397 return;
398 }
399
400 $nonce = wp_create_nonce('epgc_nonce');
401 wp_localize_script($script_handle, 'embedpressCalendarData', [
402 'ajaxUrl' => admin_url('admin-ajax.php'),
403 'nonce' => $nonce,
404 'translations' => [
405 'allDay' => __('All day', 'embedpress'),
406 'createdBy' => __('Created by', 'embedpress'),
407 'goToEvent' => __('Go to event', 'embedpress'),
408 'unknownError' => __('Unknown error', 'embedpress'),
409 'requestError' => __('Request error', 'embedpress'),
410 'loading' => __('Loading', 'embedpress')
411 ]
412 ]);
413 }
414
415 /**
416 * Load plugin text domain for translations
417 */
418 public static function load_text_domain()
419 {
420 $locale = determine_locale();
421 $locale = apply_filters('plugin_locale', $locale, 'embedpress');
422
423 // Load from WordPress languages directory first
424 if (file_exists(WP_LANG_DIR . "/embedpress-" . $locale . '.mo')) {
425 unload_textdomain('embedpress');
426 load_textdomain('embedpress', WP_LANG_DIR . "/embedpress-" . $locale . '.mo');
427 }
428
429 // Load from plugin languages directory
430 load_plugin_textdomain('embedpress', false, plugin_basename(dirname(EMBEDPRESS_FILE)) . '/languages');
431 }
432
433 /**
434 * Get Wistia labels for localization
435 *
436 * @return array
437 */
438 private static function get_wistia_labels()
439 {
440 return [
441 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
442 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
443 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
444 ];
445 }
446
447 /**
448 * Get Wistia options safely
449 *
450 * @return mixed|null
451 */
452 private static function get_wistia_options()
453 {
454 if (!function_exists('embedpress_wisita_pro_get_options')) {
455 return null;
456 }
457
458 try {
459 // return embedpress_wisita_pro_get_options();
460 } catch (\Exception $e) {
461 // Silently fail if function throws an error
462 return null;
463 }
464 }
465
466 /**
467 * Get branding value safely
468 *
469 * @param string $type
470 * @param string $provider
471 * @return string
472 */
473 private static function get_branding_value($type, $provider)
474 {
475 if (!function_exists('get_branding_value')) {
476 return '';
477 }
478
479 try {
480 return self::get_branding_value($type, $provider);
481 } catch (\Exception $e) {
482 return '';
483 }
484 }
485
486 /**
487 * Get analytics session ID safely
488 *
489 * @return string
490 */
491 private static function get_analytics_session_id()
492 {
493 // Prefer cookie-based session IDs to avoid server PHP session configuration issues
494 if (isset($_COOKIE['ep_session_id'])) {
495 $cookie = $_COOKIE['ep_session_id'];
496 // Allow only safe characters and a minimum length
497 if (is_string($cookie) && preg_match('/^[A-Za-z0-9._:-]{8,}$/', $cookie)) {
498 return sanitize_text_field($cookie);
499 }
500 }
501
502 // Generate a new ephemeral session ID
503 $id = 'ep-sess-' . time() . '-' . wp_generate_password(8, false);
504
505 // Set a session cookie (expires when the browser closes)
506 if (!headers_sent()) {
507 $path = defined('COOKIEPATH') ? COOKIEPATH : '/';
508 $domain = (defined('COOKIE_DOMAIN') && COOKIE_DOMAIN) ? COOKIE_DOMAIN : '';
509 $secure = is_ssl();
510 $httponly = true;
511 setcookie('ep_session_id', $id, 0, $path, $domain, $secure, $httponly);
512 }
513
514 return $id;
515 }
516
517 /**
518 * Get URL schemes for preview script
519 *
520 * @return array
521 */
522 private static function get_url_schemes()
523 {
524 return [
525 // Apple podcasts
526 'podcasts.apple.com/*',
527 // YouTube
528 'youtube.com/watch\\?*',
529 'youtube.com/playlist\\?*',
530 'youtube.com/channel/*',
531 'youtube.com/c/*',
532 'youtube.com/user/*',
533 'youtube.com/(\w+)[^?\/]*$',
534 // Vimeo
535 'vimeo.com/*',
536 'vimeo.com/groups/*/videos/*',
537 // Twitter
538 'twitter.com/*/status/*',
539 'twitter.com/i/moments/*',
540 'twitter.com/*/timelines/*',
541 // Facebook
542 'facebook.com/*',
543 'fb.watch/*',
544 // Instagram
545 'instagram.com/p/*',
546 'instagr.am/p/*',
547 // SoundCloud
548 'soundcloud.com/*',
549 // Twitch
550 '*.twitch.tv/*',
551 'twitch.tv/*',
552 // Wistia
553 '*.wistia.com/medias/*',
554 'fast.wistia.com/embed/medias/*.jsonp',
555 // Google services
556 'google.com/*',
557 'google.com.*/*',
558 'google.co.*/*',
559 'maps.google.com/*',
560 'docs.google.com/presentation/*',
561 'docs.google.com/document/*',
562 'docs.google.com/spreadsheets/*',
563 'docs.google.com/forms/*',
564 'docs.google.com/drawings/*',
565 ];
566 }
567
568 /**
569 * Setup PDF gallery frontend localization
570 */
571 private static function setup_pdf_gallery_localization()
572 {
573 $script_handle = 'embedpress-pdf-gallery';
574
575 if (!wp_script_is($script_handle, 'enqueued') && !wp_script_is($script_handle, 'registered')) {
576 return;
577 }
578
579 $plugin_url = defined('EMBEDPRESS_URL_ASSETS') ? str_replace('assets/', '', EMBEDPRESS_URL_ASSETS) : '';
580
581 wp_localize_script($script_handle, 'embedpressObj', [
582 'pdfRenderer' => Helper::get_pdf_renderer(),
583 'flipbookRenderer' => Helper::get_flipbook_renderer(),
584 'pluginUrl' => $plugin_url,
585 ]);
586 }
587
588 /**
589 * Setup PDF lightbox frontend localization
590 */
591 private static function setup_pdf_lightbox_localization()
592 {
593 $script_handle = 'embedpress-pdf-lightbox';
594
595 if (!wp_script_is($script_handle, 'enqueued') && !wp_script_is($script_handle, 'registered')) {
596 return;
597 }
598
599 // Only localize if not already done by gallery
600 if (wp_script_is('embedpress-pdf-gallery', 'enqueued')) {
601 return;
602 }
603
604 $plugin_url = defined('EMBEDPRESS_URL_ASSETS') ? str_replace('assets/', '', EMBEDPRESS_URL_ASSETS) : '';
605
606 wp_localize_script($script_handle, 'embedpressObj', [
607 'pdfRenderer' => Helper::get_pdf_renderer(),
608 'flipbookRenderer' => Helper::get_flipbook_renderer(),
609 'pluginUrl' => $plugin_url,
610 ]);
611 }
612
613 /**
614 * Initialize localization manager hooks
615 */
616 public static function init()
617 {
618 // Load text domain early
619 add_action('plugins_loaded', [__CLASS__, 'load_text_domain'], 1);
620 }
621 }
622