PluginProbe
Embed Privacy / 1.10.7
Embed Privacy v1.10.7
1.14.0 1.13.0 trunk 0.1 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.10.0 1.10.1 1.10.10 1.10.2 1.10.3 1.10.4 1.10.5 1.10.6 1.10.7 1.10.8 1.10.9 1.11.0 1.11.1 1.11.2 All 68 releases
embed-privacy / inc / class-embed-privacy.php

class-embed-privacy.php in Embed Privacy 1.10.7, at inc/class-embed-privacy.php

1,255 lines 31.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace epiphyt\Embed_Privacy;
3
4 use epiphyt\Embed_Privacy\admin\Fields;
5 use epiphyt\Embed_Privacy\admin\Settings;
6 use epiphyt\Embed_Privacy\admin\User_Interface;
7 use epiphyt\Embed_Privacy\data\Providers;
8 use epiphyt\Embed_Privacy\data\Replacer;
9 use epiphyt\Embed_Privacy\embed\Replacement;
10 use epiphyt\Embed_Privacy\embed\Template;
11 use epiphyt\Embed_Privacy\handler\Post;
12 use epiphyt\Embed_Privacy\handler\Shortcode;
13 use epiphyt\Embed_Privacy\handler\Theme;
14 use epiphyt\Embed_Privacy\handler\Widget;
15 use epiphyt\Embed_Privacy\integration\Activitypub;
16 use epiphyt\Embed_Privacy\integration\Amp;
17 use epiphyt\Embed_Privacy\integration\Astra;
18 use epiphyt\Embed_Privacy\integration\Divi;
19 use epiphyt\Embed_Privacy\integration\Elementor;
20 use epiphyt\Embed_Privacy\integration\Jetpack;
21 use epiphyt\Embed_Privacy\integration\Kadence_Blocks;
22 use epiphyt\Embed_Privacy\integration\Maps_Marker;
23 use epiphyt\Embed_Privacy\integration\Polylang;
24 use epiphyt\Embed_Privacy\integration\Shortcodes_Ultimate;
25 use epiphyt\Embed_Privacy\integration\X;
26 use epiphyt\Embed_Privacy\thumbnail\Thumbnail;
27 use ReflectionMethod;
28
29 /**
30 * Two click embed main class.
31 *
32 * @author Epiphyt
33 * @license GPL2
34 * @package epiphyt\Embed_Privacy
35 */
36 class Embed_Privacy {
37 /**
38 * @deprecated 1.2.0
39 * @since 1.1.0
40 */
41 const IFRAME_REGEX = '/<iframe(.*?)src="([^"]+)"([^>]*)>((?!<\/iframe).)*<\/iframe>/ms';
42
43 /**
44 * @since 1.4.0
45 * @var mixed The cookie content or any error message from json_decode()
46 */
47 private $cookie;
48
49 /**
50 * @since 1.3.5
51 * @var array Replacements that already have taken place.
52 */
53 public $did_replacements = [];
54
55 /**
56 * @since 1.3.0
57 * @var array An array of embed providers
58 */
59 public $embeds = [];
60
61 /**
62 * @since 1.10.0
63 * @var \epiphyt\Embed_Privacy\admin\Fields
64 */
65 public $fields;
66
67 /**
68 * @since 1.10.0
69 * @var \epiphyt\Embed_Privacy\Frontend
70 */
71 public $frontend;
72
73 /**
74 * @since 1.3.0
75 * @var bool Whether the current request has any embed processed by Embed Privacy
76 */
77 public $has_embed = false;
78
79 /**
80 * @since 1.10.0
81 * @var array List of integrations
82 */
83 private $integrations = [
84 Activitypub::class,
85 Amp::class,
86 Astra::class,
87 Divi::class,
88 Elementor::class,
89 Jetpack::class,
90 Kadence_Blocks::class,
91 Maps_Marker::class,
92 Polylang::class,
93 Shortcodes_Ultimate::class,
94 X::class,
95 ];
96
97 /**
98 * @since 1.10.0
99 * @var bool Whether the current request should be ignored
100 */
101 public $is_ignored_request = false;
102
103 /**
104 * @var \epiphyt\Embed_Privacy\Embed_Privacy
105 */
106 public static $instance;
107
108 /**
109 * @deprecated 1.10.0 Use \EPI_EMBED_PRIVACY_FILE instead
110 * @var string The full path to the main plugin file
111 */
112 public $plugin_file = '';
113
114 /**
115 * @since 1.10.0
116 * @var \epiphyt\Embed_Privacy\handler\Shortcode
117 */
118 public $shortcode;
119
120 /**
121 * @deprecated 1.10.0
122 * @var array Style properties
123 */
124 public $style = [
125 'container' => [],
126 'global' => [],
127 ];
128
129 /**
130 * @var \epiphyt\Embed_Privacy\thumbnail\Thumbnail
131 */
132 public $thumbnail;
133
134 /**
135 * @var bool Determine if we use the cache
136 */
137 public $use_cache;
138
139 /**
140 * @deprecated 1.2.0
141 * @var array The supported media providers
142 */
143 public $embed_providers = [ // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder
144 '.amazon.' => 'Amazon Kindle',
145 '.amzn.' => 'Amazon Kindle',
146 'a.co' => 'Amazon Kindle',
147 'z.cn' => 'Amazon Kindle',
148 'animoto.com' => 'Animoto',
149 'cloudup.com' => 'Cloudup',
150 'crowdsignal.com' => 'Crowdsignal',
151 'dailymotion.com' => 'DailyMotion',
152 'facebook.com' => 'Facebook',
153 'flickr.com' => 'Flickr',
154 'funnyordie.com' => 'Funny Or Die',
155 'imgur.com' => 'Imgur',
156 'instagram.com' => 'Instagram',
157 'issuu.com' => 'Issuu',
158 'kickstarter.com' => 'Kickstarter',
159 'meetup.com' => 'Meetup',
160 'mixcloud.com' => 'Mixcloud',
161 'photobucket.com' => 'Photobucket',
162 'poll.fm' => 'Crowdsignal',
163 'polldaddy.com' => 'Crowdsignal',
164 'reddit.com' => 'Reddit',
165 'reverbnation.com' => 'ReverbNation',
166 'scribd.com' => 'Scribd',
167 'sketchfab.com' => 'Sketchfab',
168 'slideshare.net' => 'SlideShare',
169 'smugmug.com' => 'SmugMug',
170 'soundcloud.com' => 'SoundCloud',
171 'speakerdeck.com' => 'Speaker Deck',
172 'spotify.com' => 'Spotify',
173 'survey.fm' => 'Crowdsignal',
174 'tiktok.com' => 'TikTok',
175 'ted.com' => 'TED',
176 'tumblr.com' => 'Tumblr',
177 'twitter.com' => 'Twitter',
178 'videopress.com' => 'VideoPress',
179 'vimeo.com' => 'Vimeo',
180 'wordpress.org/plugins' => 'WordPress.org',
181 'wordpress.tv' => 'WordPress.tv',
182 'youtu.be' => 'YouTube',
183 'youtube.com' => 'YouTube',
184 ];
185
186 /**
187 * Embed Privacy constructor.
188 */
189 public function __construct() {
190 $this->fields = new Fields();
191 $this->frontend = new Frontend();
192 $this->shortcode = new Shortcode();
193 $this->thumbnail = new Thumbnail();
194 $this->use_cache = ! \is_admin();
195 }
196
197 /**
198 * Initialize the class.
199 *
200 * @since 1.2.0
201 */
202 public function init() {
203 // actions
204 \add_action( 'init', [ $this, 'load_textdomain' ], 0 );
205 \add_action( 'init', [ $this, 'set_ignored_request' ] );
206 \add_action( 'init', [ self::class, 'register_post_type' ], 5 );
207 \add_action( 'plugins_loaded', [ $this, 'init_integrations' ] );
208 \add_action( 'save_post_epi_embed', [ $this, 'preserve_backslashes' ] );
209
210 // filters
211 if ( ! $this->use_cache ) {
212 // set ttl to 0 in admin
213 \add_filter( 'oembed_ttl', '__return_zero' );
214 }
215
216 Migration::get_instance()->init();
217 Post::init();
218 Providers::get_instance()->init();
219 Settings::init();
220 User_Interface::init();
221 Widget::init();
222 $this->fields->init();
223 $this->frontend->init();
224 $this->shortcode->init();
225 $this->thumbnail->init();
226 }
227
228 /**
229 * Initialize all integrations, if necessary.
230 */
231 public function init_integrations() {
232 /**
233 * Filter the integrations.
234 *
235 * @since 1.10.0
236 *
237 * @param array $integrations List of integrations
238 */
239 $this->integrations = (array) \apply_filters( 'embed_privacy_integrations', $this->integrations );
240
241 foreach ( $this->integrations as $integration ) {
242 if ( ! \method_exists( $integration, 'init' ) ) {
243 continue;
244 }
245
246 $reflection = new ReflectionMethod( $integration, 'init' );
247
248 if ( $reflection->isStatic() ) {
249 $integration::init();
250 }
251 else {
252 ( new $integration() )->init(); // phpcs:ignore NeutronStandard.Functions.VariableFunctions.VariableFunction
253 }
254 }
255 }
256
257 /**
258 * Embeds are cached in the postmeta database table and need to be removed
259 * whenever the plugin will be enabled or disabled.
260 *
261 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Post::clear_embed_cache() instead
262 */
263 public function clear_embed_cache() {
264 \_doing_it_wrong(
265 __METHOD__,
266 \sprintf(
267 /* translators: alternative method */
268 \esc_html__( 'Use %s instead', 'embed-privacy' ),
269 'epiphyt\Embed_Privacy\handler\Post::clear_embed_cache()'
270 ),
271 '1.10.0'
272 );
273 Post::clear_embed_cache();
274 }
275
276 /**
277 * Deregister assets.
278 *
279 * @deprecated 1.10.0
280 * @since 1.4.6
281 */
282 public function deregister_assets() {
283 \_doing_it_wrong(
284 __METHOD__,
285 \esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ),
286 '1.10.0'
287 );
288 }
289
290 /**
291 * Enqueue our assets for the frontend.
292 *
293 * @deprecated 1.4.4 Use epiphyt\Embed_Privacy\Frontend::print_assets() instead
294 */
295 public function enqueue_assets() {
296 \_doing_it_wrong(
297 __METHOD__,
298 \sprintf(
299 /* translators: alternative method */
300 \esc_html__( 'Use %s instead.', 'embed-privacy' ),
301 'epiphyt\Embed_Privacy\Frontend::print_assets()'
302 ),
303 '1.4.4'
304 );
305 }
306
307 /**
308 * Get the Embed Privacy cookie.
309 *
310 * @return mixed The content of the cookie
311 */
312 public function get_cookie() {
313 if ( empty( $_COOKIE['embed-privacy'] ) ) {
314 return '';
315 }
316
317 if ( ! empty( $this->cookie ) ) {
318 return $this->cookie;
319 }
320
321 $this->cookie = \json_decode( \sanitize_text_field( \wp_unslash( $_COOKIE['embed-privacy'] ) ) );
322
323 return $this->cookie;
324 }
325
326 /**
327 * Get filters for Elementor.
328 *
329 * @deprecated 1.3.5
330 * @since 1.3.0
331 */
332 public function get_elementor_filters() {
333 \_doing_it_wrong(
334 __METHOD__,
335 \esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ),
336 '1.3.5'
337 );
338
339 if ( ! Elementor::is_used() ) {
340 return;
341 }
342
343 // doesn't currently run with YouTube
344 // see https://github.com/elementor/elementor/issues/14276
345 \add_filter( 'oembed_result', [ $this, 'replace_embeds' ], 10, 3 );
346 }
347
348 /**
349 * Get an embed provider by its name.
350 *
351 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Providers::get_by_name() instead
352 * @since 1.3.5
353 *
354 * @param string $name The name to search for
355 * @return \WP_Post|null The embed or null
356 */
357 public function get_embed_by_name( $name ) {
358 \_doing_it_wrong(
359 __METHOD__,
360 \sprintf(
361 /* translators: alternative method */
362 \esc_html__( 'Use %s instead', 'embed-privacy' ),
363 'epiphyt\Embed_Privacy\data\Providers::get_by_name()'
364 ),
365 '1.10.0'
366 );
367
368 if ( empty( $name ) ) {
369 return null;
370 }
371
372 $embed_providers = $this->get_embeds();
373 $embed = null;
374 $pattern = '/^' . \preg_quote( $name, '/' ) . '\-\d+/';
375
376 foreach ( $embed_providers as $embed_provider ) {
377 if ( $embed_provider->post_name !== $name && ! \preg_match( $pattern, $embed_provider->post_name ) ) {
378 continue;
379 }
380
381 $embed = $embed_provider;
382 break;
383 }
384
385 return $embed;
386 }
387
388 /**
389 * Get an embed provider overlay.
390 *
391 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\embed\Replacement::get() instead
392 * @since 1.3.5
393 *
394 * @param \WP_Post $provider An embed provider
395 * @param string $content The content
396 * @return string The content with additional overlays of an embed provider
397 */
398 public function get_embed_overlay( $provider, $content ) {
399 \_doing_it_wrong(
400 __METHOD__,
401 \sprintf(
402 /* translators: alternative method */
403 \esc_html__( 'Use %s instead', 'embed-privacy' ),
404 'epiphyt\Embed_Privacy\embed\Replacement::get()'
405 ),
406 '1.10.0'
407 );
408
409 $replacement = new Replacement( $content );
410
411 foreach ( $replacement->get_providers() as $provider ) {
412 $content = Template::get( $provider, $replacement );
413 }
414
415 return $content;
416 }
417
418 /**
419 * Get a specific type of embeds.
420 *
421 * For more information on the accepted arguments in $args, see the
422 * {@link https://developer.wordpress.org/reference/classes/wp_query/
423 * WP_Query} documentation in the Developer Handbook.
424 *
425 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Providers::get_list() instead
426 * @since 1.3.0
427 * @since 1.8.0 Added the $args parameter
428 *
429 * @param string $type The embed type
430 * @param array $args Additional arguments
431 * @return array A list of embeds
432 */
433 public function get_embeds( $type = 'all', $args = [] ) {
434 \_doing_it_wrong(
435 __METHOD__,
436 \sprintf(
437 /* translators: alternative method */
438 \esc_html__( 'Use %s instead', 'embed-privacy' ),
439 'epiphyt\Embed_Privacy\data\Providers::get_list()'
440 ),
441 '1.10.0'
442 );
443
444 if ( ! empty( $this->embeds ) && isset( $this->embeds[ $type ] ) ) {
445 return $this->embeds[ $type ];
446 }
447
448 if ( $type === 'all' && isset( $this->embeds['custom'] ) && isset( $this->embeds['oembed'] ) ) {
449 $this->embeds[ $type ] = \array_merge( $this->embeds['custom'], $this->embeds['oembed'] );
450
451 return $this->embeds[ $type ];
452 }
453
454 if ( ! empty( $args ) ) {
455 $hash = \md5( \wp_json_encode( $args ) );
456 }
457
458 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query
459 switch ( $type ) {
460 case 'custom':
461 $custom_providers = \get_posts( \array_merge( [
462 'meta_query' => [ // phpcs:ignore SlevomatCodingStandard.Arrays.DisallowPartiallyKeyed.DisallowedPartiallyKeyed
463 'relation' => 'OR',
464 [ // phpcs:ignore Universal.Arrays.MixedKeyedUnkeyedArray.Found, Universal.Arrays.MixedArrayKeyTypes.ImplicitNumericKey
465 'compare' => 'NOT EXISTS',
466 'key' => 'is_system',
467 'value' => 'yes',
468 ],
469 [ // phpcs:ignore Universal.Arrays.MixedKeyedUnkeyedArray.Found, Universal.Arrays.MixedArrayKeyTypes.ImplicitNumericKey
470 'compare' => '!=',
471 'key' => 'is_system',
472 'value' => 'yes',
473 ],
474 ],
475 'no_found_rows' => true,
476 'numberposts' => -1,
477 'order' => 'ASC',
478 'orderby' => 'post_title',
479 'post_type' => 'epi_embed',
480 'update_post_term_cache' => false,
481 ], $args ) );
482 $google_provider = \get_posts( \array_merge( [
483 'meta_key' => 'is_system',
484 'meta_value' => 'yes',
485 'name' => 'google-maps',
486 'no_found_rows' => true,
487 'post_type' => 'epi_embed',
488 'update_post_term_cache' => false,
489 ], $args ) );
490
491 if ( ! empty( $hash ) ) {
492 $this->embeds[ $hash ] = \array_merge( $custom_providers, $google_provider );
493 }
494 else {
495 $this->embeds[ $type ] = \array_merge( $custom_providers, $google_provider );
496 }
497 break;
498 case 'oembed':
499 $embed_providers = \get_posts( \array_merge( [
500 'meta_key' => 'is_system',
501 'meta_value' => 'yes',
502 'no_found_rows' => true,
503 'numberposts' => -1,
504 'order' => 'ASC',
505 'orderby' => 'post_title',
506 'post_type' => 'epi_embed',
507 'update_post_term_cache' => false,
508 ], $args ) );
509
510 if ( ! empty( $hash ) ) {
511 $this->embeds[ $hash ] = $embed_providers;
512 }
513 else {
514 $this->embeds[ $type ] = $embed_providers;
515 }
516 break;
517 case 'all':
518 default:
519 $embed_providers = \get_posts( \array_merge( [
520 'no_found_rows' => true,
521 'numberposts' => -1,
522 'order' => 'ASC',
523 'orderby' => 'post_title',
524 'post_type' => 'epi_embed',
525 'update_post_term_cache' => false,
526 ], $args ) );
527
528 if ( ! empty( $hash ) ) {
529 $this->embeds[ $hash ] = $embed_providers;
530 }
531 else {
532 $this->embeds['all'] = $embed_providers;
533 }
534 break;
535 }
536 // phpcs:enable
537
538 if ( ! empty( $hash ) ) {
539 return $this->embeds[ $hash ];
540 }
541
542 return $this->embeds[ $type ];
543 }
544
545 /**
546 * Get a list with ignored shortcodes.
547 *
548 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\Shortcode::get_ignored() instead
549 * @since 1.6.0
550 *
551 * @return string[] List with ignored shortcodes
552 */
553 public function get_ignored_shortcodes() {
554 \_doing_it_wrong(
555 __METHOD__,
556 \sprintf(
557 /* translators: alternative method */
558 \esc_html__( 'Use %s instead', 'embed-privacy' ),
559 'epiphyt\Embed_Privacy\Shortcode::get_ignored()'
560 ),
561 '1.10.0'
562 );
563
564 return $this->shortcode->get_ignored();
565 }
566
567 /**
568 * Get a unique instance of the class.
569 *
570 * @since 1.1.0
571 *
572 * @return \epiphyt\Embed_Privacy\Embed_Privacy The single instance of this class
573 */
574 public static function get_instance() {
575 if ( self::$instance === null ) {
576 self::$instance = new self();
577 }
578
579 return self::$instance;
580 }
581
582 /**
583 * Output a complete template of the overlay.
584 *
585 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\embed\Template::get() instead
586 * @since 1.1.0
587 *
588 * @param string $embed_provider The embed provider
589 * @param string $embed_provider_lowercase The embed provider without spaces and in lowercase
590 * @param string $output The output before replacing it
591 * @param array $args Additional arguments
592 * @return string The overlay template
593 */
594 public function get_output_template( $embed_provider, $embed_provider_lowercase, $output, $args = [] ) {
595 \_doing_it_wrong(
596 __METHOD__,
597 \sprintf(
598 /* translators: alternative method */
599 \esc_html__( 'Use %s instead', 'embed-privacy' ),
600 'epiphyt\Embed_Privacy\embed\Template::get()'
601 ),
602 '1.10.0'
603 );
604
605 return Template::get( $embed_provider, $embed_provider_lowercase, $output, $args );
606 }
607
608 /**
609 * Get a single overlay for all matching embeds.
610 *
611 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\embed\Replacement::get() instead
612 * @since 1.2.0
613 *
614 * @param string $content The original content
615 * @param string $embed_provider The embed provider
616 * @param string $embed_provider_lowercase The embed provider without spaces and in lowercase
617 * @param array $args Additional arguments
618 * @return string The updated content
619 */
620 public function get_single_overlay( $content, $embed_provider, $embed_provider_lowercase, $args ) {
621 \_doing_it_wrong(
622 __METHOD__,
623 \sprintf(
624 /* translators: alternative method */
625 \esc_html__( 'Use %s instead', 'embed-privacy' ),
626 'epiphyt\Embed_Privacy\embed\Replacement::get()'
627 ),
628 '1.10.0'
629 );
630
631 $overlay = new Replacement( $content );
632
633 return $overlay->get( $args );
634 }
635
636 /**
637 * Get dynamically generated style.
638 *
639 * @deprecated 1.10.0
640 *
641 * @return string Dynamically generated style
642 */
643 public function get_style() {
644 \_doing_it_wrong(
645 __METHOD__,
646 \esc_html__( 'This method has no more functionality.', 'embed-privacy' ),
647 '1.10.0'
648 );
649
650 /**
651 * Filter the style properties before generating dynamic styles.
652 *
653 * @deprecated 1.10.0
654 * @since 1.9.0
655 *
656 * @param array $style_properties Style properties array
657 */
658 $this->style = (array) \apply_filters_deprecated( 'embed_privacy_dynamic_style_properties', $this->style, '1.10.0' );
659
660 /**
661 * Filter dynamic generated style.
662 *
663 * @deprecated 1.10.0
664 * @since 1.9.0
665 *
666 * @param string $style Generated style
667 * @param array $style_properties Style properties array
668 */
669 $style = \apply_filters_deprecated( 'embed_privacy_dynamic_style', '', $this->style, '1.10.0' ); // phpcs:ignore SlevomatCodingStandard.Variables.UselessVariable.UselessVariable
670
671 return $style;
672 }
673
674 /**
675 * Check if a post contains an embed.
676 *
677 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Post::has_embed() instead
678 * @since 1.3.0
679 *
680 * @param \WP_Post|int|null $post A post object, post ID or null
681 * @return bool True if a post contains an embed, false otherwise
682 */
683 public function has_embed( $post = null ) {
684 \_doing_it_wrong(
685 __METHOD__,
686 \sprintf(
687 /* translators: alternative method */
688 \esc_html__( 'Use %s instead', 'embed-privacy' ),
689 'epiphyt\Embed_Privacy\handler\Post::has_embed()'
690 ),
691 '1.10.0'
692 );
693
694 return Post::has_embed( $post );
695 }
696
697 /**
698 * Check if a provider is always active.
699 *
700 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Providers::is_always_active() instead
701 * @since 1.1.0
702 *
703 * @param string $provider The embed provider in lowercase
704 * @return bool True if provider is always active, false otherwise
705 */
706 public function is_always_active_provider( $provider ) {
707 \_doing_it_wrong(
708 __METHOD__,
709 \sprintf(
710 /* translators: alternative method */
711 \esc_html__( 'Use %s instead', 'embed-privacy' ),
712 'epiphyt\Embed_Privacy\data\Providers::is_always_active()'
713 ),
714 '1.10.0'
715 );
716
717 return Providers::is_always_active( $provider );
718 }
719
720 /**
721 * Check if a post is written in Elementor.
722 *
723 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\integration\Elementor::is_used() instead
724 * @since 1.3.5
725 *
726 * @return bool True if Elementor is used, false otherwise
727 */
728 public function is_elementor() {
729 \_doing_it_wrong(
730 __METHOD__,
731 \sprintf(
732 /* translators: alternative method */
733 \esc_html__( 'Use %s instead', 'embed-privacy' ),
734 'epiphyt\Embed_Privacy\integration\Elementor::is_used()'
735 ),
736 '1.10.0'
737 );
738
739 return Elementor::is_used();
740 }
741
742 /**
743 * Check if the current theme is matching your name.
744 *
745 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Theme::is() instead
746 * @since 1.3.5
747 *
748 * @param string $name The theme name to test
749 * @return bool True if the current theme is matching, false otherwise
750 */
751 public function is_theme( $name ) {
752 \_doing_it_wrong(
753 __METHOD__,
754 \sprintf(
755 /* translators: alternative method */
756 \esc_html__( 'Use %s instead', 'embed-privacy' ),
757 'epiphyt\Embed_Privacy\handler\Theme::is()'
758 ),
759 '1.10.0'
760 );
761
762 return Theme::is( $name );
763 }
764
765 /**
766 * Get the WP_Filesystem object
767 *
768 * @return \WP_Filesystem_Direct WP_Filesystem object
769 */
770 public static function get_wp_filesystem() {
771 /** @var \WP_Filesystem_Direct $wp_filesystem */
772 global $wp_filesystem;
773
774 // initialize the WP filesystem if not exists
775 if ( empty( $wp_filesystem ) ) {
776 require_once \ABSPATH . 'wp-admin/includes/file.php';
777
778 \WP_Filesystem();
779 }
780
781 return $wp_filesystem;
782 }
783
784 /**
785 * Load the translation files.
786 */
787 public function load_textdomain() {
788 \load_plugin_textdomain( 'embed-privacy', false, \dirname( \plugin_basename( $this->plugin_file ) ) . '/languages' );
789 }
790
791 /**
792 * Callback for the page output buffer.
793 *
794 * @deprecated 1.10.0
795 *
796 * @param string $buffer Current buffer
797 * @return string Updated buffer
798 */
799 public function output_buffer_callback( $buffer ) {
800 \_doing_it_wrong(
801 __METHOD__,
802 \esc_html__( 'This method has no more functionality.', 'embed-privacy' ),
803 '1.10.0'
804 );
805
806 return $buffer;
807 }
808
809 /**
810 * Preserve backslashes in regex field.
811 *
812 * @since 1.4.0
813 */
814 public function preserve_backslashes() {
815 // phpcs:disable WordPress.Security.NonceVerification.Missing
816 if ( ! isset( $_POST['regex_default'] ) ) {
817 return;
818 }
819
820 $_POST['regex_default'] = \wp_slash( $_POST['regex_default'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
821 // phpcs:enable
822 }
823
824 /**
825 * Handle printing assets.
826 *
827 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\Frontend::print_assets() instead
828 * @since 1.3.0
829 */
830 public function print_assets() {
831 \_doing_it_wrong(
832 __METHOD__,
833 \sprintf(
834 /* translators: alternative method */
835 \esc_html__( 'Use %s instead', 'embed-privacy' ),
836 'epiphyt\Embed_Privacy\Frontend::print_assets()'
837 ),
838 '1.10.0'
839 );
840 $this->frontend->print_assets();
841 }
842
843 /**
844 * Register our assets for the frontend.
845 *
846 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\Frontend::register_assets() instead
847 * @since 1.4.4
848 */
849 public function register_assets() {
850 \_doing_it_wrong(
851 __METHOD__,
852 \sprintf(
853 /* translators: alternative method */
854 \esc_html__( 'Use %s instead', 'embed-privacy' ),
855 'epiphyt\Embed_Privacy\Frontend::register_assets()'
856 ),
857 '1.10.0'
858 );
859 $this->frontend->register_assets();
860 }
861
862 /**
863 * Register post type in Polylang to allow translation.
864 *
865 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\integration\Polylang::register_post_type() instead
866 * @since 1.5.0
867 *
868 * @param array $post_types List of current translatable custom post types
869 * @param bool $is_settings Whether the current page is the settings page
870 * @return array Updated list of translatable custom post types
871 */
872 public function register_polylang_post_type( array $post_types, $is_settings ) {
873 \_doing_it_wrong(
874 __METHOD__,
875 \sprintf(
876 /* translators: alternative method */
877 \esc_html__( 'Use %s instead', 'embed-privacy' ),
878 'epiphyt\Embed_Privacy\integration\Polylang::register_post_type()'
879 ),
880 '1.10.0'
881 );
882
883 return Polylang::register_post_type( $post_types, $is_settings );
884 }
885
886 /**
887 * Register post type.
888 *
889 * @since 1.10.0
890 */
891 public static function register_post_type() {
892 \register_post_type(
893 'epi_embed',
894 [ // phpcs:ignore SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys.IncorrectKeyOrder
895 'label' => \__( 'Embeds', 'embed-privacy' ),
896 'description' => \__( 'Embeds from Embed Privacy', 'embed-privacy' ),
897 'supports' => [
898 'custom-fields',
899 'editor',
900 'revisions',
901 'thumbnail',
902 'title',
903 ],
904 'hierarchical' => false,
905 'public' => false,
906 'menu_icon' => 'dashicons-format-video',
907 'show_in_admin_bar' => false,
908 'show_in_menu' => false,
909 'show_in_nav_menus' => false,
910 'show_in_rest' => false,
911 'show_ui' => true,
912 'can_export' => true,
913 'has_archive' => false,
914 'exclude_from_search' => true,
915 'publicly_queryable' => false,
916 'rewrite' => [
917 'pages' => false,
918 'with_front' => false,
919 ],
920 ]
921 );
922 }
923
924 /**
925 * Replace embeds with a container and hide the embed with an HTML comment.
926 *
927 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Replacer::replace_embeds() instead
928 * @since 1.2.0 Changed behavior of the method
929 * @since 1.6.0 Added optional $tag parameter
930 *
931 * @param string $content The original content
932 * @param string $tag The shortcode tag if called via do_shortcode
933 * @return string The updated content
934 */
935 public function replace_embeds( $content, $tag = '' ) {
936 \_doing_it_wrong(
937 __METHOD__,
938 \sprintf(
939 /* translators: alternative method */
940 \esc_html__( 'Use %s instead', 'embed-privacy' ),
941 'epiphyt\Embed_Privacy\data\Replacer::replace_embeds()'
942 ),
943 '1.10.0'
944 );
945
946 return Replacer::replace_embeds( $content, $tag );
947 }
948
949 /**
950 * Replace oembed embeds with a container and hide the embed with an HTML comment.
951 *
952 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Replacer::replace_oembed() instead
953 * @since 1.2.0
954 *
955 * @param string $output The original output
956 * @param string $url The URL to the embed
957 * @param array $args Additional arguments of the embed
958 * @return string The updated embed code
959 */
960 public function replace_embeds_oembed( $output, $url, $args ) {
961 \_doing_it_wrong(
962 __METHOD__,
963 \sprintf(
964 /* translators: alternative method */
965 \esc_html__( 'Use %s instead', 'embed-privacy' ),
966 'epiphyt\Embed_Privacy\data\Replacer::replace_oembed()'
967 ),
968 '1.10.0'
969 );
970
971 return Replacer::replace_oembed( $output, $url, $args );
972 }
973
974 /**
975 * Replace embeds in Divi Builder.
976 *
977 * @deprecated 1.10.0
978 * @since 1.2.0
979 * @since 1.6.0 Deprecated second parameter
980 *
981 * @param string $item_embed The original output
982 * @param string $url The URL of the embed
983 * @return string The updated embed code
984 */
985 public function replace_embeds_divi( $item_embed, $url ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
986 \_doing_it_wrong(
987 __METHOD__,
988 \esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ),
989 '1.10.0'
990 );
991
992 return $item_embed;
993 }
994
995 /**
996 * Replace X embeds.
997 *
998 * @deprecated 1.6.3
999 * @since 1.6.1
1000 *
1001 * @param string $output The original output
1002 * @param string $url The URL to the embed
1003 * @param array $args Additional arguments of the embed
1004 * @return string The updated embed code
1005 */
1006 public function replace_embeds_twitter( $output, $url, $args ) {
1007 \_doing_it_wrong(
1008 __METHOD__,
1009 \esc_html__( 'This method is outdated and will be removed in the future.', 'embed-privacy' ),
1010 '1.6.3'
1011 );
1012
1013 // do nothing in admin
1014 if ( ! $this->use_cache ) {
1015 return $output;
1016 }
1017
1018 $provider = Providers::get_instance()->get_by_name( 'x' );
1019
1020 if ( ! $provider->is_matching( $url ) ) {
1021 return $output;
1022 }
1023
1024 // check for local tweets
1025 if ( \get_option( 'embed_privacy_local_tweets' ) ) {
1026 return X::get_local_tweet( $output );
1027 }
1028
1029 $args['embed_url'] = $url;
1030 $args['ignore_aspect_ratio'] = true;
1031 $args['strip_newlines'] = true;
1032
1033 return Template::get( $provider, $output, $args );
1034 }
1035
1036 /**
1037 * Replace Google Maps iframes.
1038 *
1039 * @deprecated 1.2.0 Use epiphyt\Embed_Privacy\embed\Replacement::get() instead
1040 * @since 1.1.0
1041 *
1042 * @param string $content The post content
1043 * @return string The post content
1044 */
1045 public function replace_google_maps( $content ) {
1046 \_doing_it_wrong(
1047 __METHOD__,
1048 \sprintf(
1049 /* translators: alternative method */
1050 \esc_html__( 'Use %s instead.', 'embed-privacy' ),
1051 'epiphyt\Embed_Privacy\embed\Replacement::get()'
1052 ),
1053 '1.2.0'
1054 );
1055
1056 $overlay = new Replacement( $content );
1057
1058 return $overlay->get();
1059 }
1060
1061 /**
1062 * Replace Maps Marker (Pro) shortcodes.
1063 *
1064 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\integration\Maps_Marker::replace() instead
1065 * @since 1.5.0
1066 *
1067 * @param string $output Shortcode output
1068 * @param string $tag Shortcode tag
1069 * @return string Updated shortcode output
1070 */
1071 public function replace_maps_marker( $output, $tag ) {
1072 \_doing_it_wrong(
1073 __METHOD__,
1074 \sprintf(
1075 /* translators: alternative method */
1076 \esc_html__( 'Use %s instead', 'embed-privacy' ),
1077 'epiphyt\Embed_Privacy\integration\Maps_Marker::replace()'
1078 ),
1079 '1.10.0'
1080 );
1081
1082 return Maps_Marker::replace( $output, $tag );
1083 }
1084
1085 /**
1086 * Replace video shortcode embeds.
1087 *
1088 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Replacer::replace_video_shortcode() instead
1089 * @since 1.7.0
1090 *
1091 * @param string $output Video shortcode HTML output
1092 * @param array $atts Array of video shortcode attributes
1093 * @return string Updated embed code
1094 */
1095 public function replace_video_shortcode( $output, $atts ) {
1096 \_doing_it_wrong(
1097 __METHOD__,
1098 \sprintf(
1099 /* translators: alternative method */
1100 \esc_html__( 'Use %s instead', 'embed-privacy' ),
1101 'epiphyt\Embed_Privacy\data\Replacer::replace_video_shortcode()'
1102 ),
1103 '1.10.0'
1104 );
1105
1106 return Replacer::replace_video_shortcode( $output, $atts );
1107 }
1108
1109 /**
1110 * Run a compare check.
1111 *
1112 * @since 1.4.4
1113 *
1114 * @param mixed $value1 First value to compare
1115 * @param mixed $value2 Second value to compare
1116 * @param string $compare Compare operator
1117 * @return bool Result of comparing the values
1118 */
1119 private function run_check_compare( $value1, $value2, $compare ) {
1120 switch ( $compare ) {
1121 case '===':
1122 return $value1 === $value2;
1123 case '==':
1124 return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1125 case '!==':
1126 return $value1 !== $value2;
1127 case '!=':
1128 return $value1 != $value2; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1129 case '>':
1130 return $value1 > $value2;
1131 case '>=':
1132 return $value1 >= $value2;
1133 case '<':
1134 return $value1 < $value2;
1135 case '<=':
1136 return $value1 <= $value2;
1137 default:
1138 return false;
1139 }
1140 }
1141
1142 /**
1143 * Run additional for a DOM node checks.
1144 *
1145 * @since 1.4.4
1146 * @since 1.10.0 Method is now public
1147 *
1148 * @param array $checks A list of checks
1149 * @param \DOMElement $element The DOM Element
1150 * @return bool Whether all checks are successful
1151 */
1152 public function run_checks( $checks, $element ) {
1153 if ( empty( $checks ) ) {
1154 return true;
1155 }
1156
1157 foreach ( $checks as $check ) {
1158 if ( $check['type'] === 'attribute' ) {
1159 $compared = $this->run_check_compare( $element->getAttribute( $check['attribute'] ), $check['value'], $check['compare'] );
1160
1161 if ( ! $compared ) {
1162 return false;
1163 }
1164 }
1165 }
1166
1167 return true;
1168 }
1169
1170 /**
1171 * Check whether this request should be ignored by Embed Privacy.
1172 *
1173 * @since 1.10.0
1174 */
1175 public function set_ignored_request() {
1176 /**
1177 * Filter whether the current request should be ignored.
1178 *
1179 * @since 1.10.0
1180 *
1181 * @param bool $is_ignored_request Whether the current request should be ignored
1182 */
1183 $this->is_ignored_request = (bool) \apply_filters( 'embed_privacy_is_ignored_request', $this->is_ignored_request );
1184 }
1185
1186 /**
1187 * Set the plugin file.
1188 *
1189 * @deprecated 1.10.0 Use \EPI_EMBED_PRIVACY_FILE instead
1190 * @since 1.1.0
1191 *
1192 * @param string $file The path to the file
1193 */
1194 public function set_plugin_file( $file ) {
1195 if ( \file_exists( $file ) ) {
1196 $this->plugin_file = $file;
1197 }
1198 }
1199
1200 /**
1201 * Register post type.
1202 *
1203 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy:\Embed_Privacy:register_post_type() instead
1204 * @since 1.2.0
1205 */
1206 public function set_post_type() {
1207 \_doing_it_wrong(
1208 __METHOD__,
1209 \sprintf(
1210 /* translators: alternative method */
1211 \esc_html__( 'Use %s instead', 'embed-privacy' ),
1212 'epiphyt\Embed_Privacy\Embed_Privacy::register_post_type()'
1213 ),
1214 '1.10.0'
1215 );
1216 self::register_post_type();
1217 }
1218
1219 /**
1220 * Display an Opt-out shortcode.
1221 *
1222 * @deprecated 1.10.0 Use epiphyt\Embed_Privacy\handler\Shortcode::opt_out() instead
1223 * @since 1.2.0
1224 *
1225 * @param array $attributes Shortcode attributes
1226 * @return string The shortcode output
1227 */
1228 public function shortcode_opt_out( $attributes ) {
1229 \_doing_it_wrong(
1230 __METHOD__,
1231 \sprintf(
1232 /* translators: alternative method */
1233 \esc_html__( 'Use %s instead', 'embed-privacy' ),
1234 'epiphyt\Embed_Privacy\handler\Shortcode::opt_out()'
1235 ),
1236 '1.10.0'
1237 );
1238
1239 return Shortcode::opt_out( $attributes );
1240 }
1241
1242 /**
1243 * Start an output buffer.
1244 *
1245 * @deprecated 1.10.0
1246 */
1247 public function start_output_buffer() {
1248 \_doing_it_wrong(
1249 __METHOD__,
1250 \esc_html__( 'This method has no more functionality.', 'embed-privacy' ),
1251 '1.10.0'
1252 );
1253 }
1254 }
1255