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-migration.php

class-migration.php in Embed Privacy 1.11.2, at inc/class-migration.php

1,409 lines 50.0 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\data\Providers;
5 use epiphyt\Embed_Privacy\thumbnail\Thumbnail;
6 use FilesystemIterator;
7 use WP_Post;
8
9 /**
10 * Migration class to update data in the database on upgrades.
11 *
12 * @since 1.2.0
13 *
14 * @author Epiphyt
15 * @license GPL2
16 * @package epiphyt\Embed_Privacy
17 */
18 class Migration {
19 /**
20 * @var \epiphyt\Embed_Privacy\Migration
21 */
22 private static $instance;
23
24 /**
25 * @var array Default embed providers
26 */
27 private $providers = [];
28
29 /**
30 * @var string Current migration version
31 * @since 1.2.2
32 */
33 private $version = '1.11.0';
34
35 /**
36 * Migration constructor.
37 */
38 public function __construct() {
39 self::$instance = $this;
40 }
41
42 /**
43 * Initialize functions.
44 */
45 public function init() {
46 // since upgrader_process_complete hook runs the old plugin code,
47 // it is useless for real migrations, unfortunately
48 // thus, we need to check on every page load in the admin if there are
49 // new migrations
50 \add_action( 'admin_init', [ $this, 'migrate' ], 10, 0 );
51 \add_action( 'admin_notices', [ $this, 'register_migration_failed_notice' ] );
52 }
53
54 /**
55 * Add an embed provider post.
56 *
57 * @param array $embed Embed provider information
58 */
59 private function add_embed( array $embed ) {
60 // since meta_input doesn't work on every multisite (I don't know why)
61 // extract metadata and use add_post_meta() afterwards
62 // see: https://github.com/epiphyt/embed-privacy/issues/14
63 if ( ! empty( $embed['meta_input'] ) ) {
64 $meta_data = $embed['meta_input'];
65 unset( $embed['meta_input'] );
66 }
67
68 $post_id = \wp_insert_post( $embed );
69
70 // add meta data
71 if ( \is_int( $post_id ) && isset( $meta_data ) ) {
72 foreach ( $meta_data as $meta_key => $meta_value ) {
73 \add_post_meta( $post_id, $meta_key, $meta_value );
74 }
75 }
76 }
77
78 /**
79 * Create thumbnails directory.
80 *
81 * @since 1.5.0
82 */
83 private function create_thumbnails_dir() {
84 $directory = Thumbnail::get_directory();
85
86 if ( empty( $directory['base_dir'] ) ) {
87 return;
88 }
89
90 if ( \file_exists( $directory['base_dir'] ) && ! \is_dir( $directory['base_dir'] ) ) {
91 return;
92 }
93
94 if ( ! \is_dir( $directory['base_dir'] ) ) {
95 \wp_mkdir_p( $directory['base_dir'] );
96 }
97 }
98
99 /**
100 * Delete an option either from the global multisite settings or the regular site.
101 *
102 * @param string $option The option name
103 * @return bool True if the option was deleted, false otherwise
104 */
105 private function delete_option( $option ) {
106 return \delete_option( 'embed_privacy_' . $option );
107 }
108
109 /**
110 * Get a unique instance of the class.
111 *
112 * @return \epiphyt\Embed_Privacy\Migration The single instance of this class
113 */
114 public static function get_instance() {
115 if ( self::$instance === null ) {
116 self::$instance = new self();
117 }
118
119 return self::$instance;
120 }
121
122 /**
123 * Get an option either from the global multisite settings or the regular site.
124 *
125 * @param string $option The option name
126 * @param mixed $default_value The default value if the option is not set
127 * @return mixed Value set for the option
128 */
129 private function get_option( $option, $default_value = false ) {
130 return \get_option( 'embed_privacy_' . $option, $default_value );
131 }
132
133 /**
134 * Run migrations.
135 *
136 * @param null $deprecated Deprecated, has no function anymore
137 * @param null $deprecated2 Deprecated, has no function anymore
138 */
139 public function migrate( $deprecated = null, $deprecated2 = null ) {
140 if ( $deprecated !== null ) {
141 \_doing_it_wrong(
142 __METHOD__,
143 \sprintf(
144 /* translators: parameter */
145 \esc_html__( 'The function does not support the parameter "%s" anymore.', 'embed-privacy' ),
146 '$plugin'
147 ),
148 '1.4.0'
149 );
150 }
151
152 if ( $deprecated2 !== null ) {
153 \_doing_it_wrong(
154 __METHOD__,
155 \sprintf(
156 /* translators: parameter */
157 \esc_html__( 'The function does not support the parameter "%s" anymore.', 'embed-privacy' ),
158 '$network_wide'
159 ),
160 '1.4.0'
161 );
162 }
163
164 if ( \wp_doing_ajax() ) {
165 return;
166 }
167
168 // check for active migration
169 if (
170 \is_numeric( $this->get_option( 'is_migrating' ) )
171 && $this->get_option( 'is_migrating' ) !== '1' // possible legacy value
172 && (int) $this->get_option( 'is_migrating' ) > \time() - \MINUTE_IN_SECONDS
173 ) {
174 return;
175 }
176
177 $version = $this->get_option( 'migrate_version', 'initial' );
178
179 // get legacy network option
180 if ( $version === 'initial' && \is_multisite() ) {
181 $version = \get_site_option( 'embed_privacy_migrate_version', 'initial' );
182 }
183
184 if ( $version === $this->version ) {
185 return;
186 }
187
188 // start the migration
189 $this->update_option( 'is_migrating', \time() );
190 $this->update_option( 'migration_count', (int) $this->get_option( 'migration_count' ) + 1 );
191 // load textdomain early for migrations
192 \load_plugin_textdomain( 'embed-privacy', false, \dirname( \plugin_basename( \EPI_EMBED_PRIVACY_FILE ) ) . '/languages' );
193 // make sure all default embed providers are available and translated
194 $this->register_default_embed_providers();
195
196 switch ( $version ) {
197 case '1.2.0':
198 $this->migrate_1_2_1();
199 case '1.2.1':
200 $this->migrate_1_2_2();
201 case '1.2.2':
202 $this->migrate_1_3_0();
203 case '1.3.0':
204 $this->migrate_1_4_0();
205 case '1.4.0':
206 $this->migrate_1_4_7();
207 case '1.4.7':
208 $this->migrate_1_5_0();
209 case '1.5.0':
210 $this->migrate_1_6_0();
211 case '1.6.0':
212 $this->migrate_1_7_0();
213 case '1.7.0':
214 $this->migrate_1_7_3();
215 case '1.7.3':
216 $this->migrate_1_8_0();
217 case '1.8.0':
218 $this->migrate_1_10_5();
219 case '1.10.5':
220 $this->migrate_1_10_6();
221 case '1.10.6':
222 case '1.10.7':
223 $this->migrate_1_10_7();
224 case '1.10.9':
225 $this->migrate_1_11_0();
226 case $this->version:
227 // most recent version, do nothing
228 break;
229 default:
230 // run all migrations
231 $this->migrate_1_2_0();
232 break;
233 }
234
235 // migration done
236 $this->update_option( 'migrate_version', $this->version );
237 $this->delete_option( 'is_migrating' );
238 $this->delete_option( 'migration_count' );
239 }
240
241 /**
242 * Migrations for version 1.2.0.
243 *
244 * @since 1.2.0
245 * @since 1.5.0 Create thumbnails directory
246 *
247 * - Add default embed providers
248 * - Add thumbnails directory
249 */
250 private function migrate_1_2_0() {
251 // add embeds
252 foreach ( $this->providers as $embed ) {
253 $this->add_embed( $embed );
254 }
255
256 $this->create_thumbnails_dir();
257 }
258
259 /**
260 * Migrations for version 1.2.1.
261 *
262 * @since 1.2.1
263 *
264 * - Add missing meta data
265 */
266 private function migrate_1_2_1() {
267 global $wp_filesystem;
268
269 // initialize the WP filesystem if not exists
270 if ( empty( $wp_filesystem ) ) {
271 require_once \ABSPATH . 'wp-admin/includes/file.php';
272 \WP_Filesystem();
273 }
274
275 $available_providers = \get_posts( [
276 'no_found_rows' => true,
277 'numberposts' => -1,
278 'post_type' => 'epi_embed',
279 'update_post_term_cache' => false,
280 ] );
281
282 foreach ( $available_providers as $provider ) {
283 // get according default provider
284 $key = \array_search( $provider->post_title, \array_column( $this->providers, 'post_title' ), true );
285
286 // if no default provider, continue with next available provider
287 if ( $key === false ) {
288 continue;
289 }
290
291 // update default meta data, if missing
292 foreach ( [ 'is_system', 'privacy_policy_url', 'regex_default' ] as $meta_key ) {
293 if ( ! \get_post_meta( $provider->ID, $meta_key, true ) ) {
294 \update_post_meta( $provider->ID, $meta_key, $this->providers[ $key ]['meta_input'][ $meta_key ] );
295 }
296 }
297 }
298 }
299
300 /**
301 * Migrations for version 1.2.2.
302 *
303 * @since 1.2.2
304 *
305 * - Update regex for Amazon Kindle
306 */
307 private function migrate_1_2_2() {
308 $amazon_provider = \get_posts( [
309 'meta_key' => 'is_system',
310 'meta_value' => 'yes',
311 'name' => 'amazon-kindle',
312 'no_found_rows' => true,
313 'post_type' => 'epi_embed',
314 'update_post_term_cache' => false,
315 ] );
316
317 if ( ! empty( $amazon_provider ) ) {
318 $amazon_provider = \reset( $amazon_provider );
319 }
320
321 if ( ! $amazon_provider instanceof WP_Post ) {
322 return;
323 }
324
325 \update_post_meta( $amazon_provider->ID, 'regex_default', '/\\\.?(ama?zo?n\\\.|a\\\.co\\\/|z\\\.cn\\\/)/' );
326 }
327
328 /**
329 * Migrations for version 1.3.0.
330 *
331 * @since 1.3.0
332 *
333 * - Delete post thumbnails
334 * - Update regex for Google Maps
335 */
336 private function migrate_1_3_0() {
337 $providers = Embed_Privacy::get_instance()->get_embeds( 'oembed' );
338 $google_provider = \get_posts( [
339 'meta_key' => 'is_system',
340 'meta_value' => 'yes',
341 'name' => 'google-maps',
342 'no_found_rows' => true,
343 'post_type' => 'epi_embed',
344 'update_post_term_cache' => false,
345 ] );
346 $providers = \array_merge( $providers, $google_provider );
347
348 foreach ( $providers as $provider ) {
349 if ( ! $provider instanceof WP_Post ) {
350 continue;
351 }
352
353 // delete post thumbnails
354 // see https://github.com/epiphyt/embed-privacy/issues/32
355 $thumbnail_id = \get_post_thumbnail_id( $provider->ID );
356
357 if ( $thumbnail_id ) {
358 \delete_post_thumbnail( $provider );
359 \wp_delete_attachment( $thumbnail_id, true );
360 }
361
362 // make regex ungreedy
363 // see https://github.com/epiphyt/embed-privacy/issues/31
364 if ( $provider->post_name === 'google-maps' ) {
365 \update_post_meta( $provider->ID, 'regex_default', '/google\\\.com\\\/maps\\\/embed/' );
366 }
367 }
368 }
369
370 /**
371 * Migrations for version 1.4.0.
372 *
373 * @since 1.4.0
374 *
375 * - Replace duplicate embed providers
376 * - Add missing default embed providers (this also adds new Wolfram Cloud)
377 */
378 private function migrate_1_4_0() {
379 $providers = Embed_Privacy::get_instance()->get_embeds();
380 $missing_providers = $this->providers;
381 $processed_providers = [];
382
383 foreach ( $providers as $provider ) {
384 if ( ! $provider instanceof WP_Post ) {
385 continue;
386 }
387
388 // check only system providers
389 if ( \get_post_meta( $provider->ID, 'is_system', true ) !== 'yes' ) {
390 continue;
391 }
392
393 // since post name differs, use post title to get duplicates
394 if ( \in_array( $provider->post_title, $processed_providers, true ) ) {
395 // delete duplicate providers
396 \wp_delete_post( $provider->ID, true );
397 }
398 else {
399 $processed_providers[] = $provider->post_title;
400 }
401
402 $key = false;
403
404 // delete provider from list of missing providers if it already exists
405 foreach ( $missing_providers as $provider_key => $missing_provider ) {
406 if ( $provider->post_title === $missing_provider['post_title'] ) {
407 $key = $provider_key;
408 break;
409 }
410 }
411
412 if ( $key !== false ) {
413 unset( $missing_providers[ $key ] );
414 }
415 }
416
417 // add missing default providers
418 foreach ( $missing_providers as $missing_provider ) {
419 $this->add_embed( $missing_provider );
420 }
421 }
422
423 /**
424 * Migrations for version 1.4.7.
425 *
426 * @see https://github.com/epiphyt/embed-privacy/issues/120
427 * @since 1.4.7
428 *
429 * - Update regex for Google Maps
430 */
431 private function migrate_1_4_7() {
432 $google_provider = \get_posts( [
433 'meta_key' => 'is_system',
434 'meta_value' => 'yes',
435 'name' => 'google-maps',
436 'no_found_rows' => true,
437 'post_type' => 'epi_embed',
438 'update_post_term_cache' => false,
439 ] );
440 $google_provider = \reset( $google_provider );
441
442 \update_post_meta( $google_provider->ID, 'regex_default', '/google\\\.com\\\/maps\\\/(d\\\/)?embed/' );
443 }
444
445 /**
446 * Migrations for version 1.5.0.
447 *
448 * @see https://github.com/epiphyt/embed-privacy/issues/124
449 * @since 1.5.0
450 *
451 * - Add new embed provider Pocket Casts
452 * - Add new embed provider Maps Marker
453 * - Add thumbnails directory
454 * - Update Google Maps regex
455 */
456 private function migrate_1_5_0() {
457 $this->add_embed( [
458 'meta_input' => [
459 'is_system' => 'yes',
460 'privacy_policy_url' => \__( 'https://support.pocketcasts.com/article/privacy-policy/', 'embed-privacy' ),
461 'regex_default' => '/pca\\\.st/',
462 ],
463 /* translators: embed provider */
464 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Pocket Casts', 'embed provider', 'embed-privacy' ) ),
465 'post_status' => 'publish',
466 'post_title' => \_x( 'Pocket Casts', 'embed provider', 'embed-privacy' ),
467 'post_type' => 'epi_embed',
468 ] );
469 $this->add_embed( [
470 'meta_input' => [
471 'is_system' => 'yes',
472 'privacy_policy_url' => '',
473 'regex_default' => '',
474 ],
475 /* translators: embed provider */
476 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Maps Marker Pro', 'embed provider', 'embed-privacy' ) ),
477 'post_status' => 'publish',
478 'post_title' => \_x( 'Maps Marker Pro', 'embed provider', 'embed-privacy' ),
479 'post_type' => 'epi_embed',
480 ] );
481 $this->create_thumbnails_dir();
482
483 $google_provider = \get_posts( [
484 'meta_key' => 'is_system',
485 'meta_value' => 'yes',
486 'name' => 'google-maps',
487 'no_found_rows' => true,
488 'post_type' => 'epi_embed',
489 'update_post_term_cache' => false,
490 ] );
491 $google_provider = \reset( $google_provider );
492
493 if ( $google_provider instanceof WP_Post ) {
494 \update_post_meta( $google_provider->ID, 'regex_default', '/(google\\\.com\\\/maps\\\/embed|maps\\\.google\\\.com\\\/(maps)?)/' );
495 }
496 }
497
498 /**
499 * Migrations for version 1.6.0.
500 *
501 * @see https://github.com/epiphyt/embed-privacy/issues/124
502 * @since 1.6.0
503 *
504 * - Update Google Maps regex
505 */
506 private function migrate_1_6_0() {
507 $google_provider = \get_posts( [
508 'meta_key' => 'is_system',
509 'meta_value' => 'yes',
510 'name' => 'google-maps',
511 'no_found_rows' => true,
512 'post_type' => 'epi_embed',
513 'update_post_term_cache' => false,
514 ] );
515 $google_provider = \reset( $google_provider );
516
517 if ( $google_provider instanceof WP_Post ) {
518 \update_post_meta( $google_provider->ID, 'regex_default', '/(google\\\.com\\\/maps\\\/embed|maps\\\.google\\\.com\\\/(maps)?)/' );
519 }
520 }
521
522 /**
523 * Migrations for version 1.7.0.
524 *
525 * @see https://github.com/epiphyt/embed-privacy/issues/163
526 * @since 1.7.0
527 *
528 * - Update CrowdSignal regex
529 */
530 private function migrate_1_7_0() {
531 $crowdsignal_provider = \get_posts( [
532 'meta_key' => 'is_system',
533 'meta_value' => 'yes',
534 'name' => 'crowdsignal',
535 'no_found_rows' => true,
536 'post_type' => 'epi_embed',
537 'update_post_term_cache' => false,
538 ] );
539 $crowdsignal_provider = \reset( $crowdsignal_provider );
540
541 if ( $crowdsignal_provider instanceof WP_Post ) {
542 \update_post_meta( $crowdsignal_provider->ID, 'regex_default', '/((poll(\\\.fm|daddy\\\.com))|crowdsignal\\\.(com|net)|survey\\\.fm)/' );
543 }
544 }
545
546 /**
547 * Migrations for version 1.7.3.
548 *
549 * @since 1.7.3
550 *
551 * - Copy thumbnails to different directory
552 */
553 private function migrate_1_7_3() {
554 $this->create_thumbnails_dir();
555
556 $new_dir = Thumbnail::get_directory()['base_dir'];
557 $old_dir = \WP_CONTENT_DIR . '/uploads/embed-privacy/thumbnails';
558
559 // directories are identical, don't do anything
560 if ( $new_dir === $old_dir ) {
561 return;
562 }
563
564 if ( \file_exists( $old_dir ) ) {
565 $post_args = [
566 'fields' => 'ids',
567 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
568 [
569 'compare' => '!=',
570 'compare_key' => 'LIKE',
571 'key' => 'embed_privacy_thumbnail_',
572 'value' => '',
573 ],
574 ],
575 'no_found_rows' => true,
576 'offset' => 0,
577 'post_type' => 'any',
578 'update_post_term_cache' => false,
579 ];
580 $posts = \get_posts( $post_args );
581
582 // iterate through posts to get metadata
583 while ( \count( $posts ) ) {
584 foreach ( $posts as $post_id ) {
585 $metadata = \get_post_meta( $post_id );
586
587 foreach ( $metadata as $meta_key => $meta_value ) {
588 if ( ! \str_contains( $meta_key, 'embed_privacy_thumbnail_' ) ) {
589 continue;
590 }
591
592 if ( \str_contains( $meta_key, '_url' ) ) {
593 continue;
594 }
595
596 $filename = \reset( $meta_value );
597
598 // move thumbnail
599 if ( \file_exists( $old_dir . '/' . $filename ) ) {
600 Embed_Privacy::get_wp_filesystem()->move( $old_dir . '/' . $filename, $new_dir . '/' . $filename );
601 }
602 }
603 }
604
605 $post_args['offset'] += 5;
606 $posts = \get_posts( $post_args );
607 }
608
609 // remove old directory
610 if ( ! ( new FilesystemIterator( $old_dir ) )->valid() ) {
611 Embed_Privacy::get_wp_filesystem()->rmdir( $old_dir, true );
612 }
613 }
614 }
615
616 /**
617 * Migrations for version 1.8.0.
618 *
619 * @since 1.8.0
620 *
621 * - Add new embed provider Anghami
622 */
623 private function migrate_1_8_0() {
624 $this->add_embed( [
625 'meta_input' => [
626 'is_system' => 'yes',
627 'privacy_policy_url' => \__( 'https://www.anghami.com/legal', 'embed-privacy' ),
628 'regex_default' => '/anghami\\\.com/',
629 ],
630 /* translators: embed provider */
631 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Anghami', 'embed provider', 'embed-privacy' ) ),
632 'post_status' => 'publish',
633 'post_title' => \_x( 'Anghami', 'embed provider', 'embed-privacy' ),
634 'post_type' => 'epi_embed',
635 ] );
636 }
637
638 /**
639 * Migrations for version 1.10.5.
640 *
641 * @see https://github.com/epiphyt/embed-privacy/issues/235
642 * @since 1.10.5
643 *
644 * - Rename Twitter to X
645 */
646 private function migrate_1_10_5() {
647 $twitter_provider = \get_posts( [
648 'meta_key' => 'is_system',
649 'meta_value' => 'yes',
650 'name' => 'twitter',
651 'no_found_rows' => true,
652 'post_type' => 'epi_embed',
653 'update_post_term_cache' => false,
654 ] );
655 $twitter_provider = \reset( $twitter_provider );
656
657 if ( $twitter_provider instanceof WP_Post ) {
658 $x_provider = [
659 'ID' => $twitter_provider->ID,
660 'post_name' => \sanitize_title( \_x( 'X', 'embed provider', 'embed-privacy' ) ),
661 'post_title' => \_x( 'X', 'embed provider', 'embed-privacy' ),
662 ];
663
664 /* translators: embed provider */
665 if ( $twitter_provider->post_content === \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Twitter', 'embed provider', 'embed-privacy' ) ) ) {
666 /* translators: embed provider */
667 $x_provider['post_content'] = \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'X', 'embed provider', 'embed-privacy' ) );
668 }
669
670 \wp_update_post( $x_provider );
671 \update_post_meta( $twitter_provider->ID, 'privacy_policy_url', \__( 'https://x.com/privacy', 'embed-privacy' ) );
672 \update_post_meta( $twitter_provider->ID, 'regex_default', '/\\\/\\\/(www\\\.)?(twitter|x)\\\.com/' );
673 \update_post_meta( $twitter_provider->ID, 'is_system', 'yes' );
674 }
675 }
676
677 /**
678 * Migrations for version 1.10.6.
679 *
680 * @since 1.10.6
681 *
682 * - Rename Maps Marker to Maps Marker Pro
683 */
684 private function migrate_1_10_6() {
685 $maps_marker_provider = \get_posts( [
686 'meta_key' => 'is_system',
687 'meta_value' => 'yes',
688 'name' => 'maps-marker',
689 'no_found_rows' => true,
690 'post_type' => 'epi_embed',
691 'update_post_term_cache' => false,
692 ] );
693 $maps_marker_provider = \reset( $maps_marker_provider );
694
695 if ( $maps_marker_provider instanceof WP_Post ) {
696 $maps_marker_pro_provider = [
697 'ID' => $maps_marker_provider->ID,
698 'post_name' => \sanitize_title( \_x( 'Maps Marker Pro', 'embed provider', 'embed-privacy' ) ),
699 'post_title' => \_x( 'Maps Marker Pro', 'embed provider', 'embed-privacy' ),
700 ];
701
702 /* translators: embed provider */
703 if ( $maps_marker_provider->post_content === \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Maps Marker', 'embed provider', 'embed-privacy' ) ) ) {
704 /* translators: embed provider */
705 $maps_marker_pro_provider['post_content'] = \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Maps Marker Pro', 'embed provider', 'embed-privacy' ) );
706 }
707
708 \wp_update_post( $maps_marker_pro_provider );
709 }
710 }
711
712 /**
713 * Migrations for version 1.10.7.
714 *
715 * @since 1.10.7
716 *
717 * - Improve X regular expression
718 */
719 private function migrate_1_10_7() {
720 $x_provider = \get_posts( [
721 'meta_key' => 'is_system',
722 'meta_value' => 'yes',
723 'name' => 'x',
724 'no_found_rows' => true,
725 'post_type' => 'epi_embed',
726 'update_post_term_cache' => false,
727 ] );
728 $x_provider = \reset( $x_provider );
729
730 if ( $x_provider instanceof WP_Post ) {
731 \update_post_meta( $x_provider->ID, 'regex_default', '/\\\/\\\/(www\\\.)?(twitter|x)\\\.com/' );
732 }
733
734 \delete_option( 'embed_privacy_javascript_detection' );
735 }
736
737 /**
738 * Migrations for version 1.11.0
739 *
740 * @since 1.11.0
741 *
742 * - Add Bluesky embed provider
743 * - Add Canva embed provider
744 * - Add default content item names
745 * - Make https: optional for YouTube regular expression
746 */
747 private function migrate_1_11_0() {
748 foreach ( Providers::get_instance()->get_list() as $provider ) {
749 if ( ! $provider->get_post_object() ) {
750 continue;
751 }
752
753 switch ( $provider->get_title() ) {
754 case \_x( 'Instagram', 'embed provider', 'embed-privacy' ):
755 case \_x( 'TikTok', 'embed provider', 'embed-privacy' ):
756 $content_item_name = \_x( 'post', 'content item name', 'embed-privacy' );
757 break;
758 case \_x( 'Flickr', 'embed provider', 'embed-privacy' ):
759 case \_x( 'Imgur', 'embed provider', 'embed-privacy' ):
760 $content_item_name = \_x( 'image', 'content item name', 'embed-privacy' );
761 break;
762 case \_x( 'Maps Marker Pro', 'embed provider', 'embed-privacy' ):
763 $content_item_name = \_x( 'map', 'content item name', 'embed-privacy' );
764 break;
765 case \_x( 'Meetup', 'embed provider', 'embed-privacy' ):
766 $content_item_name = \_x( 'event', 'content item name', 'embed-privacy' );
767 break;
768 case \_x( 'Photobucket', 'embed provider', 'embed-privacy' ):
769 $content_item_name = \_x( 'photo', 'content item name', 'embed-privacy' );
770 break;
771 case \_x( 'X', 'embed provider', 'embed-privacy' ):
772 $content_item_name = \_x( 'tweet', 'content item name', 'embed-privacy' );
773 break;
774 case \_x( 'DailyMotion', 'embed provider', 'embed-privacy' ):
775 case \_x( 'VideoPress', 'embed provider', 'embed-privacy' ):
776 case \_x( 'Vimeo', 'embed provider', 'embed-privacy' ):
777 case \_x( 'WordPress.tv', 'embed provider', 'embed-privacy' ):
778 case \_x( 'YouTube', 'embed provider', 'embed-privacy' ):
779 $content_item_name = \_x( 'video', 'content item name', 'embed-privacy' );
780 break;
781 default:
782 $content_item_name = \_x( 'content', 'content item name', 'embed-privacy' );
783 break;
784 }
785
786 \add_post_meta( $provider->get_post_object()->ID, 'content_item_name', $content_item_name, true );
787 }
788
789 $youtube_provider = \get_posts( [
790 'meta_key' => 'is_system',
791 'meta_value' => 'yes',
792 'name' => 'youtube',
793 'no_found_rows' => true,
794 'post_type' => 'epi_embed',
795 'update_post_term_cache' => false,
796 ] );
797 $youtube_provider = \reset( $youtube_provider );
798
799 if ( $youtube_provider instanceof WP_Post ) {
800 \update_post_meta( $youtube_provider->ID, 'regex_default', '/(https?:)?\\\/\\\/(?:.+?.)?youtu(?:.be|be.com)/' );
801 }
802
803 $this->add_embed( [
804 'meta_input' => [
805 'content_item_name' => \_x( 'post', 'content item name', 'embed-privacy' ),
806 'is_system' => 'yes',
807 'privacy_policy_url' => \__( 'https://bsky.social/about/support/privacy-policy', 'embed-privacy' ),
808 'regex_default' => '/bsky\\\.app/',
809 ],
810 /* translators: embed provider */
811 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Bluesky', 'embed provider', 'embed-privacy' ) ),
812 'post_status' => 'publish',
813 'post_title' => \_x( 'Bluesky', 'embed provider', 'embed-privacy' ),
814 'post_type' => 'epi_embed',
815 ] );
816 $this->add_embed( [
817 'meta_input' => [
818 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
819 'is_system' => 'yes',
820 'privacy_policy_url' => \__( 'https://www.canva.com/policies/privacy-policy/', 'embed-privacy' ),
821 'regex_default' => '/canva\\\.com/',
822 ],
823 /* translators: embed provider */
824 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Canva', 'embed provider', 'embed-privacy' ) ),
825 'post_status' => 'publish',
826 'post_title' => \_x( 'Canva', 'embed provider', 'embed-privacy' ),
827 'post_type' => 'epi_embed',
828 ] );
829 }
830
831 /**
832 * Register default embed providers.
833 */
834 public function register_default_embed_providers() {
835 $this->providers = [
836 [
837 'meta_input' => [
838 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
839 'is_system' => 'yes',
840 'privacy_policy_url' => \__( 'https://www.amazon.com/gp/help/customer/display.html?nodeId=GX7NJQ4ZB8MHFRNJ', 'embed-privacy' ),
841 'regex_default' => '/\\\.?(ama?zo?n\\\.|a\\\.co\\\/|z\\\.cn\\\/)/',
842 ],
843 /* translators: embed provider */
844 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Amazon Kindle', 'embed provider', 'embed-privacy' ) ),
845 'post_status' => 'publish',
846 'post_title' => \_x( 'Amazon Kindle', 'embed provider', 'embed-privacy' ),
847 'post_type' => 'epi_embed',
848 ],
849 [
850 'meta_input' => [
851 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
852 'is_system' => 'yes',
853 'privacy_policy_url' => \__( 'https://www.anghami.com/legal', 'embed-privacy' ),
854 'regex_default' => '/anghami\\\.com/',
855 ],
856 /* translators: embed provider */
857 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Anghami', 'embed provider', 'embed-privacy' ) ),
858 'post_status' => 'publish',
859 'post_title' => \_x( 'Anghami', 'embed provider', 'embed-privacy' ),
860 'post_type' => 'epi_embed',
861 ],
862 [
863 'meta_input' => [
864 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
865 'is_system' => 'yes',
866 'privacy_policy_url' => \__( 'https://animoto.com/legal/privacy_policy', 'embed-privacy' ),
867 'regex_default' => '/animoto\\\.com/',
868 ],
869 /* translators: embed provider */
870 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Animoto', 'embed provider', 'embed-privacy' ) ),
871 'post_status' => 'publish',
872 'post_title' => \_x( 'Animoto', 'embed provider', 'embed-privacy' ),
873 'post_type' => 'epi_embed',
874 ],
875 [
876 'meta_input' => [
877 'content_item_name' => \_x( 'post', 'content item name', 'embed-privacy' ),
878 'is_system' => 'yes',
879 'privacy_policy_url' => \__( 'https://bsky.social/about/support/privacy-policy', 'embed-privacy' ),
880 'regex_default' => '/bsky\\\.app/',
881 ],
882 /* translators: embed provider */
883 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Bluesky', 'embed provider', 'embed-privacy' ) ),
884 'post_status' => 'publish',
885 'post_title' => \_x( 'Bluesky', 'embed provider', 'embed-privacy' ),
886 'post_type' => 'epi_embed',
887 ],
888 [
889 'meta_input' => [
890 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
891 'is_system' => 'yes',
892 'privacy_policy_url' => \__( 'https://www.canva.com/policies/privacy-policy/', 'embed-privacy' ),
893 'regex_default' => '/canva\\\.com/',
894 ],
895 /* translators: embed provider */
896 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Canva', 'embed provider', 'embed-privacy' ) ),
897 'post_status' => 'publish',
898 'post_title' => \_x( 'Canva', 'embed provider', 'embed-privacy' ),
899 'post_type' => 'epi_embed',
900 ],
901 [
902 'meta_input' => [
903 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
904 'is_system' => 'yes',
905 'privacy_policy_url' => \__( 'https://automattic.com/privacy/', 'embed-privacy' ),
906 'regex_default' => '/cloudup\\\.com/',
907 ],
908 /* translators: embed provider */
909 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Cloudup', 'embed provider', 'embed-privacy' ) ),
910 'post_status' => 'publish',
911 'post_title' => \_x( 'Cloudup', 'embed provider', 'embed-privacy' ),
912 'post_type' => 'epi_embed',
913 ],
914 [
915 'meta_input' => [
916 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
917 'is_system' => 'yes',
918 'privacy_policy_url' => \__( 'https://automattic.com/privacy/', 'embed-privacy' ),
919 'regex_default' => '/((poll(\\\.fm|daddy\\\.com))|crowdsignal\\\.(com|net)|survey\\\.fm)/',
920 ],
921 /* translators: embed provider */
922 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Crowdsignal', 'embed provider', 'embed-privacy' ) ),
923 'post_status' => 'publish',
924 'post_title' => \_x( 'Crowdsignal', 'embed provider', 'embed-privacy' ),
925 'post_type' => 'epi_embed',
926 ],
927 [
928 'meta_input' => [
929 'content_item_name' => \_x( 'video', 'content item name', 'embed-privacy' ),
930 'is_system' => 'yes',
931 'privacy_policy_url' => \__( 'https://www.dailymotion.com/legal/privacy?localization=en', 'embed-privacy' ),
932 'regex_default' => '/dailymotion\\\.com/',
933 ],
934 /* translators: embed provider */
935 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'DailyMotion', 'embed provider', 'embed-privacy' ) ),
936 'post_status' => 'publish',
937 'post_title' => \_x( 'DailyMotion', 'embed provider', 'embed-privacy' ),
938 'post_type' => 'epi_embed',
939 ],
940 [
941 'meta_input' => [
942 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
943 'is_system' => 'yes',
944 'privacy_policy_url' => \__( 'https://www.facebook.com/privacy/explanation', 'embed-privacy' ),
945 'regex_default' => '/facebook\\\.com/',
946 ],
947 /* translators: embed provider */
948 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Facebook', 'embed provider', 'embed-privacy' ) ),
949 'post_status' => 'publish',
950 'post_title' => \_x( 'Facebook', 'embed provider', 'embed-privacy' ),
951 'post_type' => 'epi_embed',
952 ],
953 [
954 'meta_input' => [
955 'content_item_name' => \_x( 'image', 'content item name', 'embed-privacy' ),
956 'is_system' => 'yes',
957 'privacy_policy_url' => \__( 'https://www.flickr.com/help/privacy', 'embed-privacy' ),
958 'regex_default' => '/flickr\\\.com/',
959 ],
960 /* translators: embed provider */
961 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Flickr', 'embed provider', 'embed-privacy' ) ),
962 'post_status' => 'publish',
963 'post_title' => \_x( 'Flickr', 'embed provider', 'embed-privacy' ),
964 'post_type' => 'epi_embed',
965 ],
966 [
967 'meta_input' => [
968 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
969 'is_system' => 'yes',
970 'privacy_policy_url' => \__( 'https://www.funnyordie.com/legal/privacy-notice', 'embed-privacy' ),
971 'regex_default' => '/funnyordie\\\.com/',
972 ],
973 /* translators: embed provider */
974 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Funny Or Die', 'embed provider', 'embed-privacy' ) ),
975 'post_status' => 'publish',
976 'post_title' => \_x( 'Funny Or Die', 'embed provider', 'embed-privacy' ),
977 'post_type' => 'epi_embed',
978 ],
979 [
980 'meta_input' => [
981 'content_item_name' => '',
982 'is_system' => 'yes',
983 'privacy_policy_url' => \__( 'https://policies.google.com/privacy?hl=en', 'embed-privacy' ),
984 'regex_default' => '/(google\\\.com\\\/maps\\\/embed|maps\\\.google\\\.com\\\/(maps)?)/',
985 ],
986 /* translators: embed provider */
987 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Google Maps', 'embed provider', 'embed-privacy' ) ),
988 'post_status' => 'publish',
989 'post_title' => \_x( 'Google Maps', 'embed provider', 'embed-privacy' ),
990 'post_type' => 'epi_embed',
991 ],
992 [
993 'meta_input' => [
994 'content_item_name' => \_x( 'image', 'content item name', 'embed-privacy' ),
995 'is_system' => 'yes',
996 'privacy_policy_url' => \__( 'https://imgur.com/privacy', 'embed-privacy' ),
997 'regex_default' => '/imgur\\\.com/',
998 ],
999 /* translators: embed provider */
1000 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Imgur', 'embed provider', 'embed-privacy' ) ),
1001 'post_status' => 'publish',
1002 'post_title' => \_x( 'Imgur', 'embed provider', 'embed-privacy' ),
1003 'post_type' => 'epi_embed',
1004 ],
1005 [
1006 'meta_input' => [
1007 'content_item_name' => \_x( 'post', 'content item name', 'embed-privacy' ),
1008 'is_system' => 'yes',
1009 'privacy_policy_url' => \__( 'https://www.instagram.com/legal/privacy/', 'embed-privacy' ),
1010 'regex_default' => '/instagram\\\.com/',
1011 ],
1012 /* translators: embed provider */
1013 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Instagram', 'embed provider', 'embed-privacy' ) ),
1014 'post_status' => 'publish',
1015 'post_title' => \_x( 'Instagram', 'embed provider', 'embed-privacy' ),
1016 'post_type' => 'epi_embed',
1017 ],
1018 [
1019 'meta_input' => [
1020 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1021 'is_system' => 'yes',
1022 'privacy_policy_url' => \__( 'https://issuu.com/legal/privacy', 'embed-privacy' ),
1023 'regex_default' => '/issuu\\\.com/',
1024 ],
1025 /* translators: embed provider */
1026 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Issuu', 'embed provider', 'embed-privacy' ) ),
1027 'post_status' => 'publish',
1028 'post_title' => \_x( 'Issuu', 'embed provider', 'embed-privacy' ),
1029 'post_type' => 'epi_embed',
1030 ],
1031 [
1032 'meta_input' => [
1033 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1034 'is_system' => 'yes',
1035 'privacy_policy_url' => \__( 'https://www.kickstarter.com/privacy', 'embed-privacy' ),
1036 'regex_default' => '/kickstarter\\\.com/',
1037 ],
1038 /* translators: embed provider */
1039 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Kickstarter', 'embed provider', 'embed-privacy' ) ),
1040 'post_status' => 'publish',
1041 'post_title' => \_x( 'Kickstarter', 'embed provider', 'embed-privacy' ),
1042 'post_type' => 'epi_embed',
1043 ],
1044 [
1045 'meta_input' => [
1046 'content_item_name' => \_x( 'map', 'content item name', 'embed-privacy' ),
1047 'is_system' => 'yes',
1048 'privacy_policy_url' => '',
1049 'regex_default' => '',
1050 ],
1051 /* translators: embed provider */
1052 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Maps Marker Pro', 'embed provider', 'embed-privacy' ) ),
1053 'post_status' => 'publish',
1054 'post_title' => \_x( 'Maps Marker Pro', 'embed provider', 'embed-privacy' ),
1055 'post_type' => 'epi_embed',
1056 ],
1057 [
1058 'meta_input' => [
1059 'content_item_name' => \_x( 'event', 'content item name', 'embed-privacy' ),
1060 'is_system' => 'yes',
1061 'privacy_policy_url' => \__( 'https://www.meetup.com/privacy/', 'embed-privacy' ),
1062 'regex_default' => '/meetup\\\.com/',
1063 ],
1064 /* translators: embed provider */
1065 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Meetup', 'embed provider', 'embed-privacy' ) ),
1066 'post_status' => 'publish',
1067 'post_title' => \_x( 'Meetup', 'embed provider', 'embed-privacy' ),
1068 'post_type' => 'epi_embed',
1069 ],
1070 [
1071 'meta_input' => [
1072 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1073 'is_system' => 'yes',
1074 'privacy_policy_url' => \__( 'https://www.mixcloud.com/privacy/', 'embed-privacy' ),
1075 'regex_default' => '/mixcloud\\\.com/',
1076 ],
1077 /* translators: embed provider */
1078 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Mixcloud', 'embed provider', 'embed-privacy' ) ),
1079 'post_status' => 'publish',
1080 'post_title' => \_x( 'Mixcloud', 'embed provider', 'embed-privacy' ),
1081 'post_type' => 'epi_embed',
1082 ],
1083 [
1084 'meta_input' => [
1085 'content_item_name' => \_x( 'photo', 'content item name', 'embed-privacy' ),
1086 'is_system' => 'yes',
1087 'privacy_policy_url' => \__( 'https://app.photobucket.com/privacy', 'embed-privacy' ),
1088 'regex_default' => '/photobucket\\\.com/',
1089 ],
1090 /* translators: embed provider */
1091 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Photobucket', 'embed provider', 'embed-privacy' ) ),
1092 'post_status' => 'publish',
1093 'post_title' => \_x( 'Photobucket', 'embed provider', 'embed-privacy' ),
1094 'post_type' => 'epi_embed',
1095 ],
1096 [
1097 'meta_input' => [
1098 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1099 'is_system' => 'yes',
1100 'privacy_policy_url' => \__( 'https://policy.pinterest.com/en/privacy-policy', 'embed-privacy' ),
1101 'regex_default' => '/pinterest\\\./',
1102 ],
1103 /* translators: embed provider */
1104 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Pinterest', 'embed provider', 'embed-privacy' ) ),
1105 'post_status' => 'publish',
1106 'post_title' => \_x( 'Pinterest', 'embed provider', 'embed-privacy' ),
1107 'post_type' => 'epi_embed',
1108 ],
1109 [
1110 'meta_input' => [
1111 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1112 'is_system' => 'yes',
1113 'privacy_policy_url' => \__( 'https://support.pocketcasts.com/article/privacy-policy/', 'embed-privacy' ),
1114 'regex_default' => '/pca\\\.st/',
1115 ],
1116 /* translators: embed provider */
1117 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Pocket Casts', 'embed provider', 'embed-privacy' ) ),
1118 'post_status' => 'publish',
1119 'post_title' => \_x( 'Pocket Casts', 'embed provider', 'embed-privacy' ),
1120 'post_type' => 'epi_embed',
1121 ],
1122 [
1123 'meta_input' => [
1124 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1125 'is_system' => 'yes',
1126 'privacy_policy_url' => \__( 'https://www.reddit.com/help/privacypolicy', 'embed-privacy' ),
1127 'regex_default' => '/reddit\\\.com/',
1128 ],
1129 /* translators: embed provider */
1130 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Reddit', 'embed provider', 'embed-privacy' ) ),
1131 'post_status' => 'publish',
1132 'post_title' => \_x( 'Reddit', 'embed provider', 'embed-privacy' ),
1133 'post_type' => 'epi_embed',
1134 ],
1135 [
1136 'meta_input' => [
1137 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1138 'is_system' => 'yes',
1139 'privacy_policy_url' => \__( 'https://www.reverbnation.com/privacy', 'embed-privacy' ),
1140 'regex_default' => '/reverbnation\\\.com/',
1141 ],
1142 /* translators: embed provider */
1143 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'ReverbNation', 'embed provider', 'embed-privacy' ) ),
1144 'post_status' => 'publish',
1145 'post_title' => \_x( 'ReverbNation', 'embed provider', 'embed-privacy' ),
1146 'post_type' => 'epi_embed',
1147 ],
1148 [
1149 'meta_input' => [
1150 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1151 'is_system' => 'yes',
1152 'privacy_policy_url' => \__( 'https://scribd.com/privacy', 'embed-privacy' ),
1153 'regex_default' => '/scribd\\\.com/',
1154 ],
1155 /* translators: embed provider */
1156 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Scribd', 'embed provider', 'embed-privacy' ) ),
1157 'post_status' => 'publish',
1158 'post_title' => \_x( 'Scribd', 'embed provider', 'embed-privacy' ),
1159 'post_type' => 'epi_embed',
1160 ],
1161 [
1162 'meta_input' => [
1163 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1164 'is_system' => 'yes',
1165 'privacy_policy_url' => \__( 'https://sketchfab.com/privacy', 'embed-privacy' ),
1166 'regex_default' => '/sketchfab\\\.com/',
1167 ],
1168 /* translators: embed provider */
1169 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Sketchfab', 'embed provider', 'embed-privacy' ) ),
1170 'post_status' => 'publish',
1171 'post_title' => \_x( 'Sketchfab', 'embed provider', 'embed-privacy' ),
1172 'post_type' => 'epi_embed',
1173 ],
1174 [
1175 'meta_input' => [
1176 'content_item_name' => \_x( 'slides', 'content item name', 'embed-privacy' ),
1177 'is_system' => 'yes',
1178 'privacy_policy_url' => \__( 'https://www.slideshare.net/privacy', 'embed-privacy' ),
1179 'regex_default' => '/slideshare\\\.net/',
1180 ],
1181 /* translators: embed provider */
1182 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'SlideShare', 'embed provider', 'embed-privacy' ) ),
1183 'post_status' => 'publish',
1184 'post_title' => \_x( 'SlideShare', 'embed provider', 'embed-privacy' ),
1185 'post_type' => 'epi_embed',
1186 ],
1187 [
1188 'meta_input' => [
1189 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1190 'is_system' => 'yes',
1191 'privacy_policy_url' => \__( 'https://www.smugmug.com/about/privacy', 'embed-privacy' ),
1192 'regex_default' => '/smugmug\\\.com/',
1193 ],
1194 /* translators: embed provider */
1195 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'SmugMug', 'embed provider', 'embed-privacy' ) ),
1196 'post_status' => 'publish',
1197 'post_title' => \_x( 'SmugMug', 'embed provider', 'embed-privacy' ),
1198 'post_type' => 'epi_embed',
1199 ],
1200 [
1201 'meta_input' => [
1202 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1203 'is_system' => 'yes',
1204 'privacy_policy_url' => \__( 'https://soundcloud.com/pages/privacy', 'embed-privacy' ),
1205 'regex_default' => '/soundcloud\\\.com/',
1206 ],
1207 /* translators: embed provider */
1208 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'SoundCloud', 'embed provider', 'embed-privacy' ) ),
1209 'post_status' => 'publish',
1210 'post_title' => \_x( 'SoundCloud', 'embed provider', 'embed-privacy' ),
1211 'post_type' => 'epi_embed',
1212 ],
1213 [
1214 'meta_input' => [
1215 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1216 'is_system' => 'yes',
1217 'privacy_policy_url' => \__( 'https://speakerdeck.com/privacy', 'embed-privacy' ),
1218 'regex_default' => '/speakerdeck\\\.com/',
1219 ],
1220 /* translators: embed provider */
1221 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Speaker Deck', 'embed provider', 'embed-privacy' ) ),
1222 'post_status' => 'publish',
1223 'post_title' => \_x( 'Speaker Deck', 'embed provider', 'embed-privacy' ),
1224 'post_type' => 'epi_embed',
1225 ],
1226 [
1227 'meta_input' => [
1228 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1229 'is_system' => 'yes',
1230 'privacy_policy_url' => \__( 'https://www.spotify.com/privacy/', 'embed-privacy' ),
1231 'regex_default' => '/spotify\\\.com/',
1232 ],
1233 /* translators: embed provider */
1234 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Spotify', 'embed provider', 'embed-privacy' ) ),
1235 'post_status' => 'publish',
1236 'post_title' => \_x( 'Spotify', 'embed provider', 'embed-privacy' ),
1237 'post_type' => 'epi_embed',
1238 ],
1239 [
1240 'meta_input' => [
1241 'content_item_name' => \_x( 'post', 'content item name', 'embed-privacy' ),
1242 'is_system' => 'yes',
1243 'privacy_policy_url' => \__( 'https://www.tiktok.com/legal/privacy-policy?lang=en-US', 'embed-privacy' ),
1244 'regex_default' => '/tiktok\\\.com/',
1245 ],
1246 /* translators: embed provider */
1247 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'TikTok', 'embed provider', 'embed-privacy' ) ),
1248 'post_status' => 'publish',
1249 'post_title' => \_x( 'TikTok', 'embed provider', 'embed-privacy' ),
1250 'post_type' => 'epi_embed',
1251 ],
1252 [
1253 'meta_input' => [
1254 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1255 'is_system' => 'yes',
1256 'privacy_policy_url' => \__( 'https://www.ted.com/about/our-organization/our-policies-terms/privacy-policy', 'embed-privacy' ),
1257 'regex_default' => '/ted\\\.com/',
1258 ],
1259 /* translators: embed provider */
1260 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'TED', 'embed provider', 'embed-privacy' ) ),
1261 'post_status' => 'publish',
1262 'post_title' => \_x( 'TED', 'embed provider', 'embed-privacy' ),
1263 'post_type' => 'epi_embed',
1264 ],
1265 [
1266 'meta_input' => [
1267 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1268 'is_system' => 'yes',
1269 'privacy_policy_url' => \__( 'https://www.tumblr.com/privacy_policy', 'embed-privacy' ),
1270 'regex_default' => '/tumblr\\\.com/',
1271 ],
1272 /* translators: embed provider */
1273 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Tumblr', 'embed provider', 'embed-privacy' ) ),
1274 'post_status' => 'publish',
1275 'post_title' => \_x( 'Tumblr', 'embed provider', 'embed-privacy' ),
1276 'post_type' => 'epi_embed',
1277 ],
1278 [
1279 'meta_input' => [
1280 'content_item_name' => \_x( 'tweet', 'content item name', 'embed-privacy' ),
1281 'is_system' => 'yes',
1282 'privacy_policy_url' => \__( 'https://x.com/privacy', 'embed-privacy' ),
1283 'regex_default' => '\\\/\\\/(www\\\.)?(twitter|x)\\\.com/',
1284 ],
1285 /* translators: embed provider */
1286 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'X', 'embed provider', 'embed-privacy' ) ),
1287 'post_status' => 'publish',
1288 'post_title' => \_x( 'X', 'embed provider', 'embed-privacy' ),
1289 'post_type' => 'epi_embed',
1290 ],
1291 [
1292 'meta_input' => [
1293 'content_item_name' => \_x( 'video', 'content item name', 'embed-privacy' ),
1294 'is_system' => 'yes',
1295 'privacy_policy_url' => \__( 'https://automattic.com/privacy/', 'embed-privacy' ),
1296 'regex_default' => '/videopress\\\.com/',
1297 ],
1298 /* translators: embed provider */
1299 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'VideoPress', 'embed provider', 'embed-privacy' ) ),
1300 'post_status' => 'publish',
1301 'post_title' => \_x( 'VideoPress', 'embed provider', 'embed-privacy' ),
1302 'post_type' => 'epi_embed',
1303 ],
1304 [
1305 'meta_input' => [
1306 'content_item_name' => \_x( 'video', 'content item name', 'embed-privacy' ),
1307 'is_system' => 'yes',
1308 'privacy_policy_url' => \__( 'https://vimeo.com/privacy', 'embed-privacy' ),
1309 'regex_default' => '/vimeo\\\.com/',
1310 ],
1311 /* translators: embed provider */
1312 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Vimeo', 'embed provider', 'embed-privacy' ) ),
1313 'post_status' => 'publish',
1314 'post_title' => \_x( 'Vimeo', 'embed provider', 'embed-privacy' ),
1315 'post_type' => 'epi_embed',
1316 ],
1317 [
1318 'meta_input' => [
1319 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1320 'is_system' => 'yes',
1321 'privacy_policy_url' => \__( 'https://www.wolfram.com/legal/privacy/wolfram/', 'embed-privacy' ),
1322 'regex_default' => '/wolframcloud\\\.com/',
1323 ],
1324 /* translators: embed provider */
1325 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Wolfram Cloud', 'embed provider', 'embed-privacy' ) ),
1326 'post_status' => 'publish',
1327 'post_title' => \_x( 'Wolfram Cloud', 'embed provider', 'embed-privacy' ),
1328 'post_type' => 'epi_embed',
1329 ],
1330 [
1331 'meta_input' => [
1332 'content_item_name' => \_x( 'content', 'content item name', 'embed-privacy' ),
1333 'is_system' => 'yes',
1334 'privacy_policy_url' => \__( 'https://wordpress.org/about/privacy/', 'embed-privacy' ),
1335 'regex_default' => '/wordpress\\\.org\\\/plugins/',
1336 ],
1337 /* translators: embed provider */
1338 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'WordPress.org', 'embed provider', 'embed-privacy' ) ),
1339 'post_status' => 'publish',
1340 'post_title' => \_x( 'WordPress.org', 'embed provider', 'embed-privacy' ),
1341 'post_type' => 'epi_embed',
1342 ],
1343 [
1344 'meta_input' => [
1345 'content_item_name' => \_x( 'video', 'content item name', 'embed-privacy' ),
1346 'is_system' => 'yes',
1347 'privacy_policy_url' => \__( 'https://wordpress.org/about/privacy/', 'embed-privacy' ),
1348 'regex_default' => '/wordpress\\\.tv\/',
1349 ],
1350 /* translators: embed provider */
1351 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'WordPress.tv', 'embed provider', 'embed-privacy' ) ),
1352 'post_status' => 'publish',
1353 'post_title' => \_x( 'WordPress.tv', 'embed provider', 'embed-privacy' ),
1354 'post_type' => 'epi_embed',
1355 ],
1356 [
1357 'meta_input' => [
1358 'content_item_name' => \_x( 'video', 'content item name', 'embed-privacy' ),
1359 'is_system' => 'yes',
1360 'privacy_policy_url' => \__( 'https://policies.google.com/privacy?hl=en', 'embed-privacy' ),
1361 'regex_default' => '/(https?:)?\\\/\\\/(?:.+?.)?youtu(?:.be|be.com)/',
1362 ],
1363 /* translators: embed provider */
1364 'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'YouTube', 'embed provider', 'embed-privacy' ) ),
1365 'post_status' => 'publish',
1366 'post_title' => \_x( 'YouTube', 'embed provider', 'embed-privacy' ),
1367 'post_type' => 'epi_embed',
1368 ],
1369 ];
1370 }
1371
1372 /**
1373 * Add a notice if migration failed.
1374 *
1375 * @since 1.5.0
1376 */
1377 public function register_migration_failed_notice() {
1378 if ( (int) $this->get_option( 'migration_count' ) < 3 ) {
1379 return;
1380 }
1381 ?>
1382 <div class="notice notice-error" data-notice="embed_privacy_migration_failed_notice">
1383 <p>
1384 <?php
1385 \printf(
1386 /* translators: 1: current migration version, 2: target migration version, 3: starting HTML anchor, 4: ending HTML anchor */
1387 \esc_html__( 'Embed Privacy migration from version %1$s to %2$s failed. Please contact the %3$ssupport%4$s for further assistance.', 'embed-privacy' ),
1388 \esc_html( $this->get_option( 'migrate_version' ) ),
1389 \esc_html( $this->version ),
1390 '<a href="' . \esc_url( \__( 'https://wordpress.org/support/plugin/embed-privacy/#new-topic-0', 'embed-privacy' ) ) . '">',
1391 '</a>'
1392 ); ?>
1393 </p>
1394 </div>
1395 <?php
1396 }
1397
1398 /**
1399 * Update an option either from the global multisite settings or the regular site.
1400 *
1401 * @param string $option The option name
1402 * @param mixed $value The value to update
1403 * @return bool Whether the update was successful
1404 */
1405 private function update_option( $option, $value ) {
1406 return \update_option( 'embed_privacy_' . $option, $value );
1407 }
1408 }
1409