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

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