PluginProbe
Embed Privacy / 1.11.0
Embed Privacy v1.11.0
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.11.0, at inc/class-embed-privacy.php

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