PluginProbe
Embed Privacy / 1.10.9
Embed Privacy v1.10.9
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.10.9, at inc/class-migration.php

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