| 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.8.0'; |
| 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 = Thumbnails::get_instance()->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 avalable 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.7.3': |
| 200 |
$this->migrate_1_8_0(); |
| 201 |
break; |
| 202 |
case '1.7.0': |
| 203 |
$this->migrate_1_8_0(); |
| 204 |
$this->migrate_1_7_3(); |
| 205 |
break; |
| 206 |
case '1.6.0': |
| 207 |
$this->migrate_1_8_0(); |
| 208 |
$this->migrate_1_7_3(); |
| 209 |
$this->migrate_1_7_0(); |
| 210 |
break; |
| 211 |
case '1.5.0': |
| 212 |
$this->migrate_1_8_0(); |
| 213 |
$this->migrate_1_7_3(); |
| 214 |
$this->migrate_1_7_0(); |
| 215 |
$this->migrate_1_6_0(); |
| 216 |
break; |
| 217 |
case '1.4.7': |
| 218 |
$this->migrate_1_8_0(); |
| 219 |
$this->migrate_1_7_0(); |
| 220 |
$this->migrate_1_6_0(); |
| 221 |
$this->migrate_1_5_0(); |
| 222 |
break; |
| 223 |
case '1.4.0': |
| 224 |
$this->migrate_1_8_0(); |
| 225 |
$this->migrate_1_7_0(); |
| 226 |
$this->migrate_1_6_0(); |
| 227 |
$this->migrate_1_5_0(); |
| 228 |
$this->migrate_1_4_7(); |
| 229 |
break; |
| 230 |
case '1.3.0': |
| 231 |
$this->migrate_1_8_0(); |
| 232 |
$this->migrate_1_7_0(); |
| 233 |
$this->migrate_1_6_0(); |
| 234 |
$this->migrate_1_5_0(); |
| 235 |
$this->migrate_1_4_0(); |
| 236 |
break; |
| 237 |
case '1.2.2': |
| 238 |
$this->migrate_1_8_0(); |
| 239 |
$this->migrate_1_7_0(); |
| 240 |
$this->migrate_1_6_0(); |
| 241 |
$this->migrate_1_5_0(); |
| 242 |
$this->migrate_1_4_0(); |
| 243 |
$this->migrate_1_3_0(); |
| 244 |
break; |
| 245 |
case '1.2.1': |
| 246 |
$this->migrate_1_8_0(); |
| 247 |
$this->migrate_1_7_0(); |
| 248 |
$this->migrate_1_6_0(); |
| 249 |
$this->migrate_1_5_0(); |
| 250 |
$this->migrate_1_4_0(); |
| 251 |
$this->migrate_1_3_0(); |
| 252 |
$this->migrate_1_2_2(); |
| 253 |
break; |
| 254 |
case '1.2.0': |
| 255 |
$this->migrate_1_8_0(); |
| 256 |
$this->migrate_1_7_0(); |
| 257 |
$this->migrate_1_6_0(); |
| 258 |
$this->migrate_1_5_0(); |
| 259 |
$this->migrate_1_4_0(); |
| 260 |
$this->migrate_1_3_0(); |
| 261 |
$this->migrate_1_2_2(); |
| 262 |
$this->migrate_1_2_1(); |
| 263 |
break; |
| 264 |
default: |
| 265 |
// run all migrations |
| 266 |
$this->migrate_1_2_0(); |
| 267 |
break; |
| 268 |
} |
| 269 |
|
| 270 |
// migration done |
| 271 |
$this->update_option( 'migrate_version', $this->version ); |
| 272 |
$this->delete_option( 'is_migrating' ); |
| 273 |
$this->delete_option( 'migration_count' ); |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Migrations for version 1.2.0. |
| 278 |
* |
| 279 |
* @since 1.2.0 |
| 280 |
* @since 1.5.0 Create thumbnails directory |
| 281 |
* |
| 282 |
* - Add default embed providers |
| 283 |
* - Add thumbnails directory |
| 284 |
*/ |
| 285 |
private function migrate_1_2_0() { |
| 286 |
// add embeds |
| 287 |
foreach ( $this->providers as $embed ) { |
| 288 |
$this->add_embed( $embed ); |
| 289 |
} |
| 290 |
|
| 291 |
$this->create_thumbnails_dir(); |
| 292 |
} |
| 293 |
|
| 294 |
/** |
| 295 |
* Migrations for version 1.2.1. |
| 296 |
* |
| 297 |
* @since 1.2.1 |
| 298 |
* |
| 299 |
* - Add missing meta data |
| 300 |
*/ |
| 301 |
private function migrate_1_2_1() { |
| 302 |
global $wp_filesystem; |
| 303 |
|
| 304 |
// initialize the WP filesystem if not exists |
| 305 |
if ( empty( $wp_filesystem ) ) { |
| 306 |
require_once \ABSPATH . 'wp-admin/includes/file.php'; |
| 307 |
\WP_Filesystem(); |
| 308 |
} |
| 309 |
|
| 310 |
$available_providers = \get_posts( [ |
| 311 |
'no_found_rows' => true, |
| 312 |
'numberposts' => -1, |
| 313 |
'post_type' => 'epi_embed', |
| 314 |
'update_post_term_cache' => false, |
| 315 |
] ); |
| 316 |
|
| 317 |
foreach ( $available_providers as $provider ) { |
| 318 |
// get according default provider |
| 319 |
$key = \array_search( $provider->post_title, \array_column( $this->providers, 'post_title' ), true ); |
| 320 |
|
| 321 |
// if no default provider, continue with next available provider |
| 322 |
if ( $key === false ) { |
| 323 |
continue; |
| 324 |
} |
| 325 |
|
| 326 |
// update default meta data, if missing |
| 327 |
foreach ( [ 'is_system', 'privacy_policy_url', 'regex_default' ] as $meta_key ) { |
| 328 |
if ( ! \get_post_meta( $provider->ID, $meta_key, true ) ) { |
| 329 |
\update_post_meta( $provider->ID, $meta_key, $this->providers[ $key ]['meta_input'][ $meta_key ] ); |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
/** |
| 336 |
* Migrations for version 1.2.2. |
| 337 |
* |
| 338 |
* @since 1.2.2 |
| 339 |
* |
| 340 |
* - Update regex for Amazon Kindle |
| 341 |
*/ |
| 342 |
private function migrate_1_2_2() { |
| 343 |
$amazon_provider = \get_posts( [ |
| 344 |
'meta_key' => 'is_system', |
| 345 |
'meta_value' => 'yes', |
| 346 |
'name' => 'amazon-kindle', |
| 347 |
'no_found_rows' => true, |
| 348 |
'post_type' => 'epi_embed', |
| 349 |
'update_post_term_cache' => false, |
| 350 |
] ); |
| 351 |
|
| 352 |
if ( ! empty( $amazon_provider ) ) { |
| 353 |
$amazon_provider = \reset( $amazon_provider ); |
| 354 |
} |
| 355 |
|
| 356 |
if ( ! $amazon_provider instanceof WP_Post ) { |
| 357 |
return; |
| 358 |
} |
| 359 |
|
| 360 |
\update_post_meta( $amazon_provider->ID, 'regex_default', '/\\\.?(ama?zo?n\\\.|a\\\.co\\\/|z\\\.cn\\\/)/' ); |
| 361 |
} |
| 362 |
|
| 363 |
/** |
| 364 |
* Migrations for version 1.3.0. |
| 365 |
* |
| 366 |
* @since 1.3.0 |
| 367 |
* |
| 368 |
* - Delete post thumbnails |
| 369 |
* - Update regex for Google Maps |
| 370 |
*/ |
| 371 |
private function migrate_1_3_0() { |
| 372 |
$providers = Embed_Privacy::get_instance()->get_embeds( 'oembed' ); |
| 373 |
$google_provider = \get_posts( [ |
| 374 |
'meta_key' => 'is_system', |
| 375 |
'meta_value' => 'yes', |
| 376 |
'name' => 'google-maps', |
| 377 |
'no_found_rows' => true, |
| 378 |
'post_type' => 'epi_embed', |
| 379 |
'update_post_term_cache' => false, |
| 380 |
] ); |
| 381 |
$providers = \array_merge( $providers, $google_provider ); |
| 382 |
|
| 383 |
foreach ( $providers as $provider ) { |
| 384 |
if ( ! $provider instanceof WP_Post ) { |
| 385 |
continue; |
| 386 |
} |
| 387 |
|
| 388 |
// delete post thumbnails |
| 389 |
// see https://github.com/epiphyt/embed-privacy/issues/32 |
| 390 |
$thumbnail_id = \get_post_thumbnail_id( $provider->ID ); |
| 391 |
|
| 392 |
if ( $thumbnail_id ) { |
| 393 |
\delete_post_thumbnail( $provider ); |
| 394 |
\wp_delete_attachment( $thumbnail_id, true ); |
| 395 |
} |
| 396 |
|
| 397 |
// make regex ungreedy |
| 398 |
// see https://github.com/epiphyt/embed-privacy/issues/31 |
| 399 |
if ( $provider->post_name === 'google-maps' ) { |
| 400 |
\update_post_meta( $provider->ID, 'regex_default', '/google\\\.com\\\/maps\\\/embed/' ); |
| 401 |
} |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
/** |
| 406 |
* Migrations for version 1.4.0. |
| 407 |
* |
| 408 |
* @since 1.4.0 |
| 409 |
* |
| 410 |
* - Replace duplicate embed providers |
| 411 |
* - Add missing default embed providers (this also adds new Wolfram Cloud) |
| 412 |
*/ |
| 413 |
private function migrate_1_4_0() { |
| 414 |
$providers = Embed_Privacy::get_instance()->get_embeds(); |
| 415 |
$missing_providers = $this->providers; |
| 416 |
$processed_providers = []; |
| 417 |
|
| 418 |
foreach ( $providers as $provider ) { |
| 419 |
if ( ! $provider instanceof WP_Post ) { |
| 420 |
continue; |
| 421 |
} |
| 422 |
|
| 423 |
// check only system providers |
| 424 |
if ( \get_post_meta( $provider->ID, 'is_system', true ) !== 'yes' ) { |
| 425 |
continue; |
| 426 |
} |
| 427 |
|
| 428 |
// since post name differs, use post title to get duplicates |
| 429 |
if ( \in_array( $provider->post_title, $processed_providers, true ) ) { |
| 430 |
// delete duplicate providers |
| 431 |
\wp_delete_post( $provider->ID, true ); |
| 432 |
} |
| 433 |
else { |
| 434 |
$processed_providers[] = $provider->post_title; |
| 435 |
} |
| 436 |
|
| 437 |
$key = false; |
| 438 |
|
| 439 |
// delete provider from list of missing providers if it already exists |
| 440 |
foreach ( $missing_providers as $provider_key => $missing_provider ) { |
| 441 |
if ( $provider->post_title === $missing_provider['post_title'] ) { |
| 442 |
$key = $provider_key; |
| 443 |
break; |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
if ( $key !== false ) { |
| 448 |
unset( $missing_providers[ $key ] ); |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
// add missing default providers |
| 453 |
foreach ( $missing_providers as $missing_provider ) { |
| 454 |
$this->add_embed( $missing_provider ); |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
/** |
| 459 |
* Migrations for version 1.4.7. |
| 460 |
* |
| 461 |
* @see https://github.com/epiphyt/embed-privacy/issues/120 |
| 462 |
* @since 1.4.7 |
| 463 |
* |
| 464 |
* - Update regex for Google Maps |
| 465 |
*/ |
| 466 |
private function migrate_1_4_7() { |
| 467 |
$google_provider = \get_posts( [ |
| 468 |
'meta_key' => 'is_system', |
| 469 |
'meta_value' => 'yes', |
| 470 |
'name' => 'google-maps', |
| 471 |
'no_found_rows' => true, |
| 472 |
'post_type' => 'epi_embed', |
| 473 |
'update_post_term_cache' => false, |
| 474 |
] ); |
| 475 |
$google_provider = \reset( $google_provider ); |
| 476 |
|
| 477 |
\update_post_meta( $google_provider->ID, 'regex_default', '/google\\\.com\\\/maps\\\/(d\\\/)?embed/' ); |
| 478 |
} |
| 479 |
|
| 480 |
/** |
| 481 |
* Migrations for version 1.5.0. |
| 482 |
* |
| 483 |
* @see https://github.com/epiphyt/embed-privacy/issues/124 |
| 484 |
* @since 1.5.0 |
| 485 |
* |
| 486 |
* - Add new embed provider Pocket Casts |
| 487 |
* - Add new embed provider Maps Marker |
| 488 |
* - Add thumbnails directory |
| 489 |
* - Update Google Maps regex |
| 490 |
*/ |
| 491 |
private function migrate_1_5_0() { |
| 492 |
$this->add_embed( [ |
| 493 |
'meta_input' => [ |
| 494 |
'is_system' => 'yes', |
| 495 |
'privacy_policy_url' => \__( 'https://support.pocketcasts.com/article/privacy-policy/', 'embed-privacy' ), |
| 496 |
'regex_default' => '/pca\\\.st/', |
| 497 |
], |
| 498 |
/* translators: embed provider */ |
| 499 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Pocket Casts', 'embed provider', 'embed-privacy' ) ), |
| 500 |
'post_status' => 'publish', |
| 501 |
'post_title' => \_x( 'Pocket Casts', 'embed provider', 'embed-privacy' ), |
| 502 |
'post_type' => 'epi_embed', |
| 503 |
] ); |
| 504 |
$this->add_embed( [ |
| 505 |
'meta_input' => [ |
| 506 |
'is_system' => 'yes', |
| 507 |
'privacy_policy_url' => '', |
| 508 |
'regex_default' => '', |
| 509 |
], |
| 510 |
/* translators: embed provider */ |
| 511 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Maps Marker', 'embed provider', 'embed-privacy' ) ), |
| 512 |
'post_status' => 'publish', |
| 513 |
'post_title' => \_x( 'Maps Marker', 'embed provider', 'embed-privacy' ), |
| 514 |
'post_type' => 'epi_embed', |
| 515 |
] ); |
| 516 |
$this->create_thumbnails_dir(); |
| 517 |
|
| 518 |
$google_provider = \get_posts( [ |
| 519 |
'meta_key' => 'is_system', |
| 520 |
'meta_value' => 'yes', |
| 521 |
'name' => 'google-maps', |
| 522 |
'no_found_rows' => true, |
| 523 |
'post_type' => 'epi_embed', |
| 524 |
'update_post_term_cache' => false, |
| 525 |
] ); |
| 526 |
$google_provider = \reset( $google_provider ); |
| 527 |
|
| 528 |
if ( $google_provider instanceof WP_Post ) { |
| 529 |
\update_post_meta( $google_provider->ID, 'regex_default', '/(google\\\.com\\\/maps\\\/embed|maps\\\.google\\\.com\\\/(maps)?)/' ); |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
/** |
| 534 |
* Migrations for version 1.6.0. |
| 535 |
* |
| 536 |
* @see https://github.com/epiphyt/embed-privacy/issues/124 |
| 537 |
* @since 1.6.0 |
| 538 |
* |
| 539 |
* - Update Google Maps regex |
| 540 |
*/ |
| 541 |
private function migrate_1_6_0() { |
| 542 |
$google_provider = \get_posts( [ |
| 543 |
'meta_key' => 'is_system', |
| 544 |
'meta_value' => 'yes', |
| 545 |
'name' => 'google-maps', |
| 546 |
'no_found_rows' => true, |
| 547 |
'post_type' => 'epi_embed', |
| 548 |
'update_post_term_cache' => false, |
| 549 |
] ); |
| 550 |
$google_provider = \reset( $google_provider ); |
| 551 |
|
| 552 |
if ( $google_provider instanceof WP_Post ) { |
| 553 |
\update_post_meta( $google_provider->ID, 'regex_default', '/(google\\\.com\\\/maps\\\/embed|maps\\\.google\\\.com\\\/(maps)?)/' ); |
| 554 |
} |
| 555 |
} |
| 556 |
|
| 557 |
/** |
| 558 |
* Migrations for version 1.7.0. |
| 559 |
* |
| 560 |
* @see https://github.com/epiphyt/embed-privacy/issues/163 |
| 561 |
* @since 1.7.0 |
| 562 |
* |
| 563 |
* - Update Google Maps regex |
| 564 |
*/ |
| 565 |
private function migrate_1_7_0() { |
| 566 |
$crowdsignal_provider = \get_posts( [ |
| 567 |
'meta_key' => 'is_system', |
| 568 |
'meta_value' => 'yes', |
| 569 |
'name' => 'crowdsignal', |
| 570 |
'no_found_rows' => true, |
| 571 |
'post_type' => 'epi_embed', |
| 572 |
'update_post_term_cache' => false, |
| 573 |
] ); |
| 574 |
$crowdsignal_provider = \reset( $crowdsignal_provider ); |
| 575 |
|
| 576 |
if ( $crowdsignal_provider instanceof WP_Post ) { |
| 577 |
\update_post_meta( $crowdsignal_provider->ID, 'regex_default', '/((poll(\\\.fm|daddy\\\.com))|crowdsignal\\\.(com|net)|survey\\\.fm)/' ); |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* Migrations for version 1.7.3. |
| 583 |
* |
| 584 |
* @since 1.7.3 |
| 585 |
* |
| 586 |
* - Copy thumbnails to different directory |
| 587 |
*/ |
| 588 |
private function migrate_1_7_3() { |
| 589 |
$this->create_thumbnails_dir(); |
| 590 |
|
| 591 |
$new_dir = Thumbnail::get_directory()['base_dir']; |
| 592 |
$old_dir = \WP_CONTENT_DIR . '/uploads/embed-privacy/thumbnails'; |
| 593 |
|
| 594 |
// directories are identical, don't do anything |
| 595 |
if ( $new_dir === $old_dir ) { |
| 596 |
return; |
| 597 |
} |
| 598 |
|
| 599 |
if ( \file_exists( $old_dir ) ) { |
| 600 |
$post_args = [ |
| 601 |
'fields' => 'ids', |
| 602 |
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query |
| 603 |
[ |
| 604 |
'compare' => '!=', |
| 605 |
'compare_key' => 'LIKE', |
| 606 |
'key' => 'embed_privacy_thumbnail_', |
| 607 |
'value' => '', |
| 608 |
], |
| 609 |
], |
| 610 |
'no_found_rows' => true, |
| 611 |
'offset' => 0, |
| 612 |
'post_type' => 'any', |
| 613 |
'update_post_term_cache' => false, |
| 614 |
]; |
| 615 |
$posts = \get_posts( $post_args ); |
| 616 |
|
| 617 |
// iterate through posts to get metadata |
| 618 |
while ( \count( $posts ) ) { |
| 619 |
foreach ( $posts as $post_id ) { |
| 620 |
$metadata = \get_post_meta( $post_id ); |
| 621 |
|
| 622 |
foreach ( $metadata as $meta_key => $meta_value ) { |
| 623 |
if ( ! \str_contains( $meta_key, 'embed_privacy_thumbnail_' ) ) { |
| 624 |
continue; |
| 625 |
} |
| 626 |
|
| 627 |
if ( \str_contains( $meta_key, '_url' ) ) { |
| 628 |
continue; |
| 629 |
} |
| 630 |
|
| 631 |
$filename = \reset( $meta_value ); |
| 632 |
|
| 633 |
// move thumbnail |
| 634 |
if ( \file_exists( $old_dir . '/' . $filename ) ) { |
| 635 |
\rename( $old_dir . '/' . $filename, $new_dir . '/' . $filename ); |
| 636 |
} |
| 637 |
} |
| 638 |
} |
| 639 |
|
| 640 |
$post_args['offset'] += 5; |
| 641 |
$posts = \get_posts( $post_args ); |
| 642 |
} |
| 643 |
|
| 644 |
// remove old directory if it's empty |
| 645 |
if ( ! ( new FilesystemIterator( $old_dir ) )->valid() ) { |
| 646 |
\rmdir( $old_dir ); |
| 647 |
|
| 648 |
if ( ! ( new FilesystemIterator( \dirname( $old_dir ) ) )->valid() ) { |
| 649 |
\rmdir( \dirname( $old_dir ) ); |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
/** |
| 656 |
* Migrations for version 1.8.0. |
| 657 |
* |
| 658 |
* @since 1.8.0 |
| 659 |
* |
| 660 |
* - Add new embed provider Anghami |
| 661 |
*/ |
| 662 |
private function migrate_1_8_0() { |
| 663 |
$this->add_embed( [ |
| 664 |
'meta_input' => [ |
| 665 |
'is_system' => 'yes', |
| 666 |
'privacy_policy_url' => \__( 'https://www.anghami.com/legal', 'embed-privacy' ), |
| 667 |
'regex_default' => '/anghami\\\.com/', |
| 668 |
], |
| 669 |
/* translators: embed provider */ |
| 670 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Anghami', 'embed provider', 'embed-privacy' ) ), |
| 671 |
'post_status' => 'publish', |
| 672 |
'post_title' => \_x( 'Anghami', 'embed provider', 'embed-privacy' ), |
| 673 |
'post_type' => 'epi_embed', |
| 674 |
] ); |
| 675 |
} |
| 676 |
|
| 677 |
/** |
| 678 |
* Register default embed providers. |
| 679 |
*/ |
| 680 |
public function register_default_embed_providers() { |
| 681 |
$this->providers = [ |
| 682 |
[ |
| 683 |
'meta_input' => [ |
| 684 |
'is_system' => 'yes', |
| 685 |
'privacy_policy_url' => \__( 'https://www.amazon.com/gp/help/customer/display.html?nodeId=GX7NJQ4ZB8MHFRNJ', 'embed-privacy' ), |
| 686 |
'regex_default' => '/\\\.?(ama?zo?n\\\.|a\\\.co\\\/|z\\\.cn\\\/)/', |
| 687 |
], |
| 688 |
/* translators: embed provider */ |
| 689 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Amazon Kindle', 'embed provider', 'embed-privacy' ) ), |
| 690 |
'post_status' => 'publish', |
| 691 |
'post_title' => \_x( 'Amazon Kindle', 'embed provider', 'embed-privacy' ), |
| 692 |
'post_type' => 'epi_embed', |
| 693 |
], |
| 694 |
[ |
| 695 |
'meta_input' => [ |
| 696 |
'is_system' => 'yes', |
| 697 |
'privacy_policy_url' => \__( 'https://www.anghami.com/legal', 'embed-privacy' ), |
| 698 |
'regex_default' => '/anghami\\\.com/', |
| 699 |
], |
| 700 |
/* translators: embed provider */ |
| 701 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Anghami', 'embed provider', 'embed-privacy' ) ), |
| 702 |
'post_status' => 'publish', |
| 703 |
'post_title' => \_x( 'Anghami', 'embed provider', 'embed-privacy' ), |
| 704 |
'post_type' => 'epi_embed', |
| 705 |
], |
| 706 |
[ |
| 707 |
'meta_input' => [ |
| 708 |
'is_system' => 'yes', |
| 709 |
'privacy_policy_url' => \__( 'https://animoto.com/legal/privacy_policy', 'embed-privacy' ), |
| 710 |
'regex_default' => '/animoto\\\.com/', |
| 711 |
], |
| 712 |
/* translators: embed provider */ |
| 713 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Animoto', 'embed provider', 'embed-privacy' ) ), |
| 714 |
'post_status' => 'publish', |
| 715 |
'post_title' => \_x( 'Animoto', 'embed provider', 'embed-privacy' ), |
| 716 |
'post_type' => 'epi_embed', |
| 717 |
], |
| 718 |
[ |
| 719 |
'meta_input' => [ |
| 720 |
'is_system' => 'yes', |
| 721 |
'privacy_policy_url' => \__( 'https://automattic.com/privacy/', 'embed-privacy' ), |
| 722 |
'regex_default' => '/cloudup\\\.com/', |
| 723 |
], |
| 724 |
/* translators: embed provider */ |
| 725 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Cloudup', 'embed provider', 'embed-privacy' ) ), |
| 726 |
'post_status' => 'publish', |
| 727 |
'post_title' => \_x( 'Cloudup', 'embed provider', 'embed-privacy' ), |
| 728 |
'post_type' => 'epi_embed', |
| 729 |
], |
| 730 |
[ |
| 731 |
'meta_input' => [ |
| 732 |
'is_system' => 'yes', |
| 733 |
'privacy_policy_url' => \__( 'https://automattic.com/privacy/', 'embed-privacy' ), |
| 734 |
'regex_default' => '/((poll(\\\.fm|daddy\\\.com))|crowdsignal\\\.(com|net)|survey\\\.fm)/', |
| 735 |
], |
| 736 |
/* translators: embed provider */ |
| 737 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Crowdsignal', 'embed provider', 'embed-privacy' ) ), |
| 738 |
'post_status' => 'publish', |
| 739 |
'post_title' => \_x( 'Crowdsignal', 'embed provider', 'embed-privacy' ), |
| 740 |
'post_type' => 'epi_embed', |
| 741 |
], |
| 742 |
[ |
| 743 |
'meta_input' => [ |
| 744 |
'is_system' => 'yes', |
| 745 |
'privacy_policy_url' => \__( 'https://www.dailymotion.com/legal/privacy?localization=en', 'embed-privacy' ), |
| 746 |
'regex_default' => '/dailymotion\\\.com/', |
| 747 |
], |
| 748 |
/* translators: embed provider */ |
| 749 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'DailyMotion', 'embed provider', 'embed-privacy' ) ), |
| 750 |
'post_status' => 'publish', |
| 751 |
'post_title' => \_x( 'DailyMotion', 'embed provider', 'embed-privacy' ), |
| 752 |
'post_type' => 'epi_embed', |
| 753 |
], |
| 754 |
[ |
| 755 |
'meta_input' => [ |
| 756 |
'is_system' => 'yes', |
| 757 |
'privacy_policy_url' => \__( 'https://www.facebook.com/privacy/explanation', 'embed-privacy' ), |
| 758 |
'regex_default' => '/facebook\\\.com/', |
| 759 |
], |
| 760 |
/* translators: embed provider */ |
| 761 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Facebook', 'embed provider', 'embed-privacy' ) ), |
| 762 |
'post_status' => 'publish', |
| 763 |
'post_title' => \_x( 'Facebook', 'embed provider', 'embed-privacy' ), |
| 764 |
'post_type' => 'epi_embed', |
| 765 |
], |
| 766 |
[ |
| 767 |
'meta_input' => [ |
| 768 |
'is_system' => 'yes', |
| 769 |
'privacy_policy_url' => \__( 'https://www.flickr.com/help/privacy', 'embed-privacy' ), |
| 770 |
'regex_default' => '/flickr\\\.com/', |
| 771 |
], |
| 772 |
/* translators: embed provider */ |
| 773 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Flickr', 'embed provider', 'embed-privacy' ) ), |
| 774 |
'post_status' => 'publish', |
| 775 |
'post_title' => \_x( 'Flickr', 'embed provider', 'embed-privacy' ), |
| 776 |
'post_type' => 'epi_embed', |
| 777 |
], |
| 778 |
[ |
| 779 |
'meta_input' => [ |
| 780 |
'is_system' => 'yes', |
| 781 |
'privacy_policy_url' => \__( 'https://www.funnyordie.com/legal/privacy-notice', 'embed-privacy' ), |
| 782 |
'regex_default' => '/funnyordie\\\.com/', |
| 783 |
], |
| 784 |
/* translators: embed provider */ |
| 785 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Funny Or Die', 'embed provider', 'embed-privacy' ) ), |
| 786 |
'post_status' => 'publish', |
| 787 |
'post_title' => \_x( 'Funny Or Die', 'embed provider', 'embed-privacy' ), |
| 788 |
'post_type' => 'epi_embed', |
| 789 |
], |
| 790 |
[ |
| 791 |
'meta_input' => [ |
| 792 |
'is_system' => 'yes', |
| 793 |
'privacy_policy_url' => \__( 'https://policies.google.com/privacy?hl=en', 'embed-privacy' ), |
| 794 |
'regex_default' => '/(google\\\.com\\\/maps\\\/embed|maps\\\.google\\\.com\\\/(maps)?)/', |
| 795 |
], |
| 796 |
/* translators: embed provider */ |
| 797 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Google Maps', 'embed provider', 'embed-privacy' ) ), |
| 798 |
'post_status' => 'publish', |
| 799 |
'post_title' => \_x( 'Google Maps', 'embed provider', 'embed-privacy' ), |
| 800 |
'post_type' => 'epi_embed', |
| 801 |
], |
| 802 |
[ |
| 803 |
'meta_input' => [ |
| 804 |
'is_system' => 'yes', |
| 805 |
'privacy_policy_url' => \__( 'https://imgur.com/privacy', 'embed-privacy' ), |
| 806 |
'regex_default' => '/imgur\\\.com/', |
| 807 |
], |
| 808 |
/* translators: embed provider */ |
| 809 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Imgur', 'embed provider', 'embed-privacy' ) ), |
| 810 |
'post_status' => 'publish', |
| 811 |
'post_title' => \_x( 'Imgur', 'embed provider', 'embed-privacy' ), |
| 812 |
'post_type' => 'epi_embed', |
| 813 |
], |
| 814 |
[ |
| 815 |
'meta_input' => [ |
| 816 |
'is_system' => 'yes', |
| 817 |
'privacy_policy_url' => \__( 'https://www.instagram.com/legal/privacy/', 'embed-privacy' ), |
| 818 |
'regex_default' => '/instagram\\\.com/', |
| 819 |
], |
| 820 |
/* translators: embed provider */ |
| 821 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Instagram', 'embed provider', 'embed-privacy' ) ), |
| 822 |
'post_status' => 'publish', |
| 823 |
'post_title' => \_x( 'Instagram', 'embed provider', 'embed-privacy' ), |
| 824 |
'post_type' => 'epi_embed', |
| 825 |
], |
| 826 |
[ |
| 827 |
'meta_input' => [ |
| 828 |
'is_system' => 'yes', |
| 829 |
'privacy_policy_url' => \__( 'https://issuu.com/legal/privacy', 'embed-privacy' ), |
| 830 |
'regex_default' => '/issuu\\\.com/', |
| 831 |
], |
| 832 |
/* translators: embed provider */ |
| 833 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Issuu', 'embed provider', 'embed-privacy' ) ), |
| 834 |
'post_status' => 'publish', |
| 835 |
'post_title' => \_x( 'Issuu', 'embed provider', 'embed-privacy' ), |
| 836 |
'post_type' => 'epi_embed', |
| 837 |
], |
| 838 |
[ |
| 839 |
'meta_input' => [ |
| 840 |
'is_system' => 'yes', |
| 841 |
'privacy_policy_url' => \__( 'https://www.kickstarter.com/privacy', 'embed-privacy' ), |
| 842 |
'regex_default' => '/kickstarter\\\.com/', |
| 843 |
], |
| 844 |
/* translators: embed provider */ |
| 845 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Kickstarter', 'embed provider', 'embed-privacy' ) ), |
| 846 |
'post_status' => 'publish', |
| 847 |
'post_title' => \_x( 'Kickstarter', 'embed provider', 'embed-privacy' ), |
| 848 |
'post_type' => 'epi_embed', |
| 849 |
], |
| 850 |
[ |
| 851 |
'meta_input' => [ |
| 852 |
'is_system' => 'yes', |
| 853 |
'privacy_policy_url' => '', |
| 854 |
'regex_default' => '', |
| 855 |
], |
| 856 |
/* translators: embed provider */ |
| 857 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Maps Marker', 'embed provider', 'embed-privacy' ) ), |
| 858 |
'post_status' => 'publish', |
| 859 |
'post_title' => \_x( 'Maps Marker', 'embed provider', 'embed-privacy' ), |
| 860 |
'post_type' => 'epi_embed', |
| 861 |
], |
| 862 |
[ |
| 863 |
'meta_input' => [ |
| 864 |
'is_system' => 'yes', |
| 865 |
'privacy_policy_url' => \__( 'https://www.meetup.com/privacy/', 'embed-privacy' ), |
| 866 |
'regex_default' => '/meetup\\\.com/', |
| 867 |
], |
| 868 |
/* translators: embed provider */ |
| 869 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Meetup', 'embed provider', 'embed-privacy' ) ), |
| 870 |
'post_status' => 'publish', |
| 871 |
'post_title' => \_x( 'Meetup', 'embed provider', 'embed-privacy' ), |
| 872 |
'post_type' => 'epi_embed', |
| 873 |
], |
| 874 |
[ |
| 875 |
'meta_input' => [ |
| 876 |
'is_system' => 'yes', |
| 877 |
'privacy_policy_url' => \__( 'https://www.mixcloud.com/privacy/', 'embed-privacy' ), |
| 878 |
'regex_default' => '/mixcloud\\\.com/', |
| 879 |
], |
| 880 |
/* translators: embed provider */ |
| 881 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Mixcloud', 'embed provider', 'embed-privacy' ) ), |
| 882 |
'post_status' => 'publish', |
| 883 |
'post_title' => \_x( 'Mixcloud', 'embed provider', 'embed-privacy' ), |
| 884 |
'post_type' => 'epi_embed', |
| 885 |
], |
| 886 |
[ |
| 887 |
'meta_input' => [ |
| 888 |
'is_system' => 'yes', |
| 889 |
'privacy_policy_url' => \__( 'https://app.photobucket.com/privacy', 'embed-privacy' ), |
| 890 |
'regex_default' => '/photobucket\\\.com/', |
| 891 |
], |
| 892 |
/* translators: embed provider */ |
| 893 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Photobucket', 'embed provider', 'embed-privacy' ) ), |
| 894 |
'post_status' => 'publish', |
| 895 |
'post_title' => \_x( 'Photobucket', 'embed provider', 'embed-privacy' ), |
| 896 |
'post_type' => 'epi_embed', |
| 897 |
], |
| 898 |
[ |
| 899 |
'meta_input' => [ |
| 900 |
'is_system' => 'yes', |
| 901 |
'privacy_policy_url' => \__( 'https://policy.pinterest.com/en/privacy-policy', 'embed-privacy' ), |
| 902 |
'regex_default' => '/pinterest\\\./', |
| 903 |
], |
| 904 |
/* translators: embed provider */ |
| 905 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Pinterest', 'embed provider', 'embed-privacy' ) ), |
| 906 |
'post_status' => 'publish', |
| 907 |
'post_title' => \_x( 'Pinterest', 'embed provider', 'embed-privacy' ), |
| 908 |
'post_type' => 'epi_embed', |
| 909 |
], |
| 910 |
[ |
| 911 |
'meta_input' => [ |
| 912 |
'is_system' => 'yes', |
| 913 |
'privacy_policy_url' => \__( 'https://support.pocketcasts.com/article/privacy-policy/', 'embed-privacy' ), |
| 914 |
'regex_default' => '/pca\\\.st/', |
| 915 |
], |
| 916 |
/* translators: embed provider */ |
| 917 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Pocket Casts', 'embed provider', 'embed-privacy' ) ), |
| 918 |
'post_status' => 'publish', |
| 919 |
'post_title' => \_x( 'Pocket Casts', 'embed provider', 'embed-privacy' ), |
| 920 |
'post_type' => 'epi_embed', |
| 921 |
], |
| 922 |
[ |
| 923 |
'meta_input' => [ |
| 924 |
'is_system' => 'yes', |
| 925 |
'privacy_policy_url' => \__( 'https://www.reddit.com/help/privacypolicy', 'embed-privacy' ), |
| 926 |
'regex_default' => '/reddit\\\.com/', |
| 927 |
], |
| 928 |
/* translators: embed provider */ |
| 929 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Reddit', 'embed provider', 'embed-privacy' ) ), |
| 930 |
'post_status' => 'publish', |
| 931 |
'post_title' => \_x( 'Reddit', 'embed provider', 'embed-privacy' ), |
| 932 |
'post_type' => 'epi_embed', |
| 933 |
], |
| 934 |
[ |
| 935 |
'meta_input' => [ |
| 936 |
'is_system' => 'yes', |
| 937 |
'privacy_policy_url' => \__( 'https://www.reverbnation.com/privacy', 'embed-privacy' ), |
| 938 |
'regex_default' => '/reverbnation\\\.com/', |
| 939 |
], |
| 940 |
/* translators: embed provider */ |
| 941 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'ReverbNation', 'embed provider', 'embed-privacy' ) ), |
| 942 |
'post_status' => 'publish', |
| 943 |
'post_title' => \_x( 'ReverbNation', 'embed provider', 'embed-privacy' ), |
| 944 |
'post_type' => 'epi_embed', |
| 945 |
], |
| 946 |
[ |
| 947 |
'meta_input' => [ |
| 948 |
'is_system' => 'yes', |
| 949 |
'privacy_policy_url' => \__( 'https://scribd.com/privacy', 'embed-privacy' ), |
| 950 |
'regex_default' => '/scribd\\\.com/', |
| 951 |
], |
| 952 |
/* translators: embed provider */ |
| 953 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Scribd', 'embed provider', 'embed-privacy' ) ), |
| 954 |
'post_status' => 'publish', |
| 955 |
'post_title' => \_x( 'Scribd', 'embed provider', 'embed-privacy' ), |
| 956 |
'post_type' => 'epi_embed', |
| 957 |
], |
| 958 |
[ |
| 959 |
'meta_input' => [ |
| 960 |
'is_system' => 'yes', |
| 961 |
'privacy_policy_url' => \__( 'https://sketchfab.com/privacy', 'embed-privacy' ), |
| 962 |
'regex_default' => '/sketchfab\\\.com/', |
| 963 |
], |
| 964 |
/* translators: embed provider */ |
| 965 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Sketchfab', 'embed provider', 'embed-privacy' ) ), |
| 966 |
'post_status' => 'publish', |
| 967 |
'post_title' => \_x( 'Sketchfab', 'embed provider', 'embed-privacy' ), |
| 968 |
'post_type' => 'epi_embed', |
| 969 |
], |
| 970 |
[ |
| 971 |
'meta_input' => [ |
| 972 |
'is_system' => 'yes', |
| 973 |
'privacy_policy_url' => \__( 'https://www.slideshare.net/privacy', 'embed-privacy' ), |
| 974 |
'regex_default' => '/slideshare\\\.net/', |
| 975 |
], |
| 976 |
/* translators: embed provider */ |
| 977 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'SlideShare', 'embed provider', 'embed-privacy' ) ), |
| 978 |
'post_status' => 'publish', |
| 979 |
'post_title' => \_x( 'SlideShare', 'embed provider', 'embed-privacy' ), |
| 980 |
'post_type' => 'epi_embed', |
| 981 |
], |
| 982 |
[ |
| 983 |
'meta_input' => [ |
| 984 |
'is_system' => 'yes', |
| 985 |
'privacy_policy_url' => \__( 'https://www.smugmug.com/about/privacy', 'embed-privacy' ), |
| 986 |
'regex_default' => '/smugmug\\\.com/', |
| 987 |
], |
| 988 |
/* translators: embed provider */ |
| 989 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'SmugMug', 'embed provider', 'embed-privacy' ) ), |
| 990 |
'post_status' => 'publish', |
| 991 |
'post_title' => \_x( 'SmugMug', 'embed provider', 'embed-privacy' ), |
| 992 |
'post_type' => 'epi_embed', |
| 993 |
], |
| 994 |
[ |
| 995 |
'meta_input' => [ |
| 996 |
'is_system' => 'yes', |
| 997 |
'privacy_policy_url' => \__( 'https://soundcloud.com/pages/privacy', 'embed-privacy' ), |
| 998 |
'regex_default' => '/soundcloud\\\.com/', |
| 999 |
], |
| 1000 |
/* translators: embed provider */ |
| 1001 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'SoundCloud', 'embed provider', 'embed-privacy' ) ), |
| 1002 |
'post_status' => 'publish', |
| 1003 |
'post_title' => \_x( 'SoundCloud', 'embed provider', 'embed-privacy' ), |
| 1004 |
'post_type' => 'epi_embed', |
| 1005 |
], |
| 1006 |
[ |
| 1007 |
'meta_input' => [ |
| 1008 |
'is_system' => 'yes', |
| 1009 |
'privacy_policy_url' => \__( 'https://speakerdeck.com/privacy', 'embed-privacy' ), |
| 1010 |
'regex_default' => '/speakerdeck\\\.com/', |
| 1011 |
], |
| 1012 |
/* translators: embed provider */ |
| 1013 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Speaker Deck', 'embed provider', 'embed-privacy' ) ), |
| 1014 |
'post_status' => 'publish', |
| 1015 |
'post_title' => \_x( 'Speaker Deck', 'embed provider', 'embed-privacy' ), |
| 1016 |
'post_type' => 'epi_embed', |
| 1017 |
], |
| 1018 |
[ |
| 1019 |
'meta_input' => [ |
| 1020 |
'is_system' => 'yes', |
| 1021 |
'privacy_policy_url' => \__( 'https://www.spotify.com/privacy/', 'embed-privacy' ), |
| 1022 |
'regex_default' => '/spotify\\\.com/', |
| 1023 |
], |
| 1024 |
/* translators: embed provider */ |
| 1025 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Spotify', 'embed provider', 'embed-privacy' ) ), |
| 1026 |
'post_status' => 'publish', |
| 1027 |
'post_title' => \_x( 'Spotify', 'embed provider', 'embed-privacy' ), |
| 1028 |
'post_type' => 'epi_embed', |
| 1029 |
], |
| 1030 |
[ |
| 1031 |
'meta_input' => [ |
| 1032 |
'is_system' => 'yes', |
| 1033 |
'privacy_policy_url' => \__( 'https://www.tiktok.com/legal/privacy-policy?lang=en-US', 'embed-privacy' ), |
| 1034 |
'regex_default' => '/tiktok\\\.com/', |
| 1035 |
], |
| 1036 |
/* translators: embed provider */ |
| 1037 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'TikTok', 'embed provider', 'embed-privacy' ) ), |
| 1038 |
'post_status' => 'publish', |
| 1039 |
'post_title' => \_x( 'TikTok', 'embed provider', 'embed-privacy' ), |
| 1040 |
'post_type' => 'epi_embed', |
| 1041 |
], |
| 1042 |
[ |
| 1043 |
'meta_input' => [ |
| 1044 |
'is_system' => 'yes', |
| 1045 |
'privacy_policy_url' => \__( 'https://www.ted.com/about/our-organization/our-policies-terms/privacy-policy', 'embed-privacy' ), |
| 1046 |
'regex_default' => '/ted\\\.com/', |
| 1047 |
], |
| 1048 |
/* translators: embed provider */ |
| 1049 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'TED', 'embed provider', 'embed-privacy' ) ), |
| 1050 |
'post_status' => 'publish', |
| 1051 |
'post_title' => \_x( 'TED', 'embed provider', 'embed-privacy' ), |
| 1052 |
'post_type' => 'epi_embed', |
| 1053 |
], |
| 1054 |
[ |
| 1055 |
'meta_input' => [ |
| 1056 |
'is_system' => 'yes', |
| 1057 |
'privacy_policy_url' => \__( 'https://www.tumblr.com/privacy_policy', 'embed-privacy' ), |
| 1058 |
'regex_default' => '/tumblr\\\.com/', |
| 1059 |
], |
| 1060 |
/* translators: embed provider */ |
| 1061 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Tumblr', 'embed provider', 'embed-privacy' ) ), |
| 1062 |
'post_status' => 'publish', |
| 1063 |
'post_title' => \_x( 'Tumblr', 'embed provider', 'embed-privacy' ), |
| 1064 |
'post_type' => 'epi_embed', |
| 1065 |
], |
| 1066 |
[ |
| 1067 |
'meta_input' => [ |
| 1068 |
'is_system' => 'yes', |
| 1069 |
'privacy_policy_url' => \__( 'https://twitter.com/privacy', 'embed-privacy' ), |
| 1070 |
'regex_default' => '/twitter\\\.com/', |
| 1071 |
], |
| 1072 |
/* translators: embed provider */ |
| 1073 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Twitter', 'embed provider', 'embed-privacy' ) ), |
| 1074 |
'post_status' => 'publish', |
| 1075 |
'post_title' => \_x( 'Twitter', 'embed provider', 'embed-privacy' ), |
| 1076 |
'post_type' => 'epi_embed', |
| 1077 |
], |
| 1078 |
[ |
| 1079 |
'meta_input' => [ |
| 1080 |
'is_system' => 'yes', |
| 1081 |
'privacy_policy_url' => \__( 'https://automattic.com/privacy/', 'embed-privacy' ), |
| 1082 |
'regex_default' => '/videopress\\\.com/', |
| 1083 |
], |
| 1084 |
/* translators: embed provider */ |
| 1085 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'VideoPress', 'embed provider', 'embed-privacy' ) ), |
| 1086 |
'post_status' => 'publish', |
| 1087 |
'post_title' => \_x( 'VideoPress', 'embed provider', 'embed-privacy' ), |
| 1088 |
'post_type' => 'epi_embed', |
| 1089 |
], |
| 1090 |
[ |
| 1091 |
'meta_input' => [ |
| 1092 |
'is_system' => 'yes', |
| 1093 |
'privacy_policy_url' => \__( 'https://vimeo.com/privacy', 'embed-privacy' ), |
| 1094 |
'regex_default' => '/vimeo\\\.com/', |
| 1095 |
], |
| 1096 |
/* translators: embed provider */ |
| 1097 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Vimeo', 'embed provider', 'embed-privacy' ) ), |
| 1098 |
'post_status' => 'publish', |
| 1099 |
'post_title' => \_x( 'Vimeo', 'embed provider', 'embed-privacy' ), |
| 1100 |
'post_type' => 'epi_embed', |
| 1101 |
], |
| 1102 |
[ |
| 1103 |
'meta_input' => [ |
| 1104 |
'is_system' => 'yes', |
| 1105 |
'privacy_policy_url' => \__( 'https://www.wolfram.com/legal/privacy/wolfram/', 'embed-privacy' ), |
| 1106 |
'regex_default' => '/wolframcloud\\\.com/', |
| 1107 |
], |
| 1108 |
/* translators: embed provider */ |
| 1109 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Wolfram Cloud', 'embed provider', 'embed-privacy' ) ), |
| 1110 |
'post_status' => 'publish', |
| 1111 |
'post_title' => \_x( 'Wolfram Cloud', 'embed provider', 'embed-privacy' ), |
| 1112 |
'post_type' => 'epi_embed', |
| 1113 |
], |
| 1114 |
[ |
| 1115 |
'meta_input' => [ |
| 1116 |
'is_system' => 'yes', |
| 1117 |
'privacy_policy_url' => \__( 'https://wordpress.org/about/privacy/', 'embed-privacy' ), |
| 1118 |
'regex_default' => '/wordpress\\\.org\\\/plugins/', |
| 1119 |
], |
| 1120 |
/* translators: embed provider */ |
| 1121 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'WordPress.org', 'embed provider', 'embed-privacy' ) ), |
| 1122 |
'post_status' => 'publish', |
| 1123 |
'post_title' => \_x( 'WordPress.org', 'embed provider', 'embed-privacy' ), |
| 1124 |
'post_type' => 'epi_embed', |
| 1125 |
], |
| 1126 |
[ |
| 1127 |
'meta_input' => [ |
| 1128 |
'is_system' => 'yes', |
| 1129 |
'privacy_policy_url' => \__( 'https://wordpress.org/about/privacy/', 'embed-privacy' ), |
| 1130 |
'regex_default' => '/wordpress\\\.tv\/', |
| 1131 |
], |
| 1132 |
/* translators: embed provider */ |
| 1133 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'WordPress.tv', 'embed provider', 'embed-privacy' ) ), |
| 1134 |
'post_status' => 'publish', |
| 1135 |
'post_title' => \_x( 'WordPress.tv', 'embed provider', 'embed-privacy' ), |
| 1136 |
'post_type' => 'epi_embed', |
| 1137 |
], |
| 1138 |
[ |
| 1139 |
'meta_input' => [ |
| 1140 |
'is_system' => 'yes', |
| 1141 |
'privacy_policy_url' => \__( 'https://policies.google.com/privacy?hl=en', 'embed-privacy' ), |
| 1142 |
'regex_default' => '/https?:\\\/\\\/(?:.+?.)?youtu(?:.be|be.com)/', |
| 1143 |
], |
| 1144 |
/* translators: embed provider */ |
| 1145 |
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'YouTube', 'embed provider', 'embed-privacy' ) ), |
| 1146 |
'post_status' => 'publish', |
| 1147 |
'post_title' => \_x( 'YouTube', 'embed provider', 'embed-privacy' ), |
| 1148 |
'post_type' => 'epi_embed', |
| 1149 |
], |
| 1150 |
]; |
| 1151 |
} |
| 1152 |
|
| 1153 |
/** |
| 1154 |
* Add a notice if migration failed. |
| 1155 |
* |
| 1156 |
* @since 1.5.0 |
| 1157 |
*/ |
| 1158 |
public function register_migration_failed_notice() { |
| 1159 |
if ( (int) $this->get_option( 'migration_count' ) < 3 ) { |
| 1160 |
return; |
| 1161 |
} |
| 1162 |
?> |
| 1163 |
<div class="notice notice-error" data-notice="embed_privacy_migration_failed_notice"> |
| 1164 |
<p> |
| 1165 |
<?php |
| 1166 |
\printf( |
| 1167 |
/* translators: 1: current migration version, 2: target migration version, 3: starting HTML anchor, 4: ending HTML anchor */ |
| 1168 |
\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' ), |
| 1169 |
\esc_html( $this->get_option( 'migrate_version' ) ), |
| 1170 |
\esc_html( $this->version ), |
| 1171 |
'<a href="' . \esc_url( \__( 'https://wordpress.org/support/plugin/embed-privacy/#new-topic-0', 'embed-privacy' ) ) . '">', |
| 1172 |
'</a>' |
| 1173 |
); ?> |
| 1174 |
</p> |
| 1175 |
</div> |
| 1176 |
<?php |
| 1177 |
} |
| 1178 |
|
| 1179 |
/** |
| 1180 |
* Update an option either from the global multisite settings or the regular site. |
| 1181 |
* |
| 1182 |
* @param string $option The option name |
| 1183 |
* @param mixed $value The value to update |
| 1184 |
* @return bool Whether the update was successful |
| 1185 |
*/ |
| 1186 |
private function update_option( $option, $value ) { |
| 1187 |
return \update_option( 'embed_privacy_' . $option, $value ); |
| 1188 |
} |
| 1189 |
} |
| 1190 |
|