Skip to content

Commit

Permalink
🔀 Merge branch 'main' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
MatzeKitt committed Sep 27, 2024
2 parents 345c232 + 83b7d8f commit f97f1f6
Show file tree
Hide file tree
Showing 23 changed files with 395 additions and 242 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 1.10.5
* Improved: Renamed Twitter to X
* Fixed: Check for matching provider
* Fixed: Missing assets for YouTube overlay in Elementor
* Fixed: Hiding providers in the opt-out shortcodes if desired
* Fixed: Potential PHP warning

## 1.10.4
* Fixed: Blocking embeds appearing in the same content after a disabled/always active provider
* Fixed: Cookie lifetime

## 1.10.3
* Fixed: Multiple replacements of the same embed
* Fixed: Replacing unknown embeds
* Fixed: Always return an embed provider via `Providers::get_by_name()`
* Fixed: Warning about potentially non-available asset version

## 1.10.2
* Fixed: Potential fatal error for missing check of the availability of the function `is_plugin_active`

## 1.10.1
* Fixed: Set correct "Tested up to" to WordPress 6.6

## 1.10.0
* Added: Thumbnail support for Polylang
* Added: Filter to prevent orphan thumbnail deletion
Expand Down
Binary file removed assets/images/embed-twitter.png
Binary file not shown.
Binary file added assets/images/embed-x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions assets/js/embed-privacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ document.addEventListener( 'DOMContentLoaded', function() {
if ( cookie !== null && Object.keys( cookie ).length !== 0 && cookie.constructor === Object ) {
cookie[ embedProvider ] = true;

set_cookie( 'embed-privacy', JSON.stringify( cookie ) );
set_cookie( 'embed-privacy', JSON.stringify( cookie ), 365 );
}
else {
set_cookie( 'embed-privacy', '{"' + embedProvider + '":true}', 365 );
Expand Down Expand Up @@ -172,8 +172,8 @@ document.addEventListener( 'DOMContentLoaded', function() {
if ( embedPrivacy.javascriptDetection === 'yes' && alwaysActiveProviders.indexOf( optOutCheckboxes[ i ].getAttribute( 'data-embed-provider' ) ) !== -1 ) {
optOutCheckboxes[ i ].checked = true;
}
else if ( embedPrivacy.javascriptDetection === 'yes' && ! showAll ) {
optOutCheckboxes[ i ].parentNode.classList.add( 'is-hidden' );
else if ( ! showAll ) {
optOutCheckboxes[ i ].parentNode.parentNode.classList.add( 'is-hidden' );

continue;
}
Expand Down
4 changes: 2 additions & 2 deletions embed-privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin Name: Embed Privacy
Plugin URL: https://epiph.yt/en/embed-privacy/
Description: Embed Privacy prevents from loading external embeds directly and lets the user control which one should be loaded.
Version: 1.10.0
Version: 1.10.5
Author: Epiphyt
Author URI: https://epiph.yt/en/
License: GPL2
Expand All @@ -30,7 +30,7 @@
*/
\defined( 'ABSPATH' ) || exit;

\define( 'EMBED_PRIVACY_VERSION', '1.10.0' );
\define( 'EMBED_PRIVACY_VERSION', '1.10.5' );

if ( ! \defined( 'EPI_EMBED_PRIVACY_BASE' ) ) {
\define( 'EPI_EMBED_PRIVACY_BASE', \WP_PLUGIN_DIR . '/embed-privacy/' );
Expand Down
2 changes: 1 addition & 1 deletion inc/admin/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function register() {
'embed_privacy',
'embed_privacy_general',
[
'description' => \__( 'By enabling this option, tweets are embedded locally as text without any connection to Twitter, and no privacy overlay is required.', 'embed-privacy' ),
'description' => \__( 'By enabling this option, tweets are embedded locally as text without any connection to X, and no privacy overlay is required.', 'embed-privacy' ),
'name' => 'embed_privacy_local_tweets',
'option_type' => 'option',
'title' => \__( 'Local tweets', 'embed-privacy' ),
Expand Down
18 changes: 9 additions & 9 deletions inc/class-embed-privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use epiphyt\Embed_Privacy\integration\Maps_Marker;
use epiphyt\Embed_Privacy\integration\Polylang;
use epiphyt\Embed_Privacy\integration\Shortcodes_Ultimate;
use epiphyt\Embed_Privacy\integration\Twitter;
use epiphyt\Embed_Privacy\integration\X;
use epiphyt\Embed_Privacy\thumbnail\Thumbnail;
use ReflectionMethod;

Expand Down Expand Up @@ -91,7 +91,7 @@ class Embed_Privacy {
Maps_Marker::class,
Polylang::class,
Shortcodes_Ultimate::class,
Twitter::class,
X::class,
];

/**
Expand Down Expand Up @@ -410,10 +410,10 @@ public function get_embed_overlay( $provider, $content ) {
return $content;
}

$overlay = new Replacement( $content );
$replacement = new Replacement( $content );

if ( $overlay->get_provider()->is_matching( $content ) ) {
$content = Template::get( $overlay->get_provider(), $overlay );
foreach ( $replacement->get_providers() as $provider ) {
$content = Template::get( $provider, $replacement );
}

return $content;
Expand Down Expand Up @@ -704,7 +704,7 @@ public function has_embed( $post = null ) {
* @deprecated 1.10.0 Use epiphyt\Embed_Privacy\data\Providers::is_always_active() instead
* @since 1.1.0
*
* @param string $provider The embed provider in lowercase
* @param string $provider The embed provider in lowercase
* @return bool True if provider is always active, false otherwise
*/
public function is_always_active_provider( $provider ) {
Expand Down Expand Up @@ -978,7 +978,7 @@ public function replace_embeds_divi( $item_embed, $url ) { // phpcs:ignore Gener
}

/**
* Replace twitter embeds.
* Replace X embeds.
*
* @deprecated 1.6.3
* @since 1.6.1
Expand All @@ -1000,7 +1000,7 @@ public function replace_embeds_twitter( $output, $url, $args ) {
return $output;
}

$provider = Providers::get_instance()->get_by_name( 'twitter' );
$provider = Providers::get_instance()->get_by_name( 'x' );

if ( ! $provider->is_matching( $url ) ) {
return $output;
Expand All @@ -1012,7 +1012,7 @@ public function replace_embeds_twitter( $output, $url, $args ) {

if ( \get_option( 'embed_privacy_local_tweets' ) ) {
// check for local tweets
return Twitter::get_local_tweet( $output );
return X::get_local_tweet( $output );
}

$args['embed_url'] = $url;
Expand Down
4 changes: 0 additions & 4 deletions inc/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ public function print_assets() {
'javascriptDetection' => \get_option( 'embed_privacy_javascript_detection' ),
] );

if ( ! \function_exists( 'is_plugin_active' ) ) {
require_once \ABSPATH . \WPINC . '/plugin.php';
}

/**
* Fires after assets are printed.
*
Expand Down
64 changes: 58 additions & 6 deletions inc/class-migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Migration {
* @var string Current migration version
* @since 1.2.2
*/
private $version = '1.8.0';
private $version = '1.10.5';

/**
* Migration constructor.
Expand Down Expand Up @@ -196,45 +196,56 @@ public function migrate( $deprecated = null, $deprecated2 = null ) {
case $this->version:
// most recent version, do nothing
break;
case '1.8.0':
$this->migrate_1_10_5();
break;
case '1.7.3':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
break;
case '1.7.0':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_3();
break;
case '1.6.0':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_3();
$this->migrate_1_7_0();
break;
case '1.5.0':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_3();
$this->migrate_1_7_0();
$this->migrate_1_6_0();
break;
case '1.4.7':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_0();
$this->migrate_1_6_0();
$this->migrate_1_5_0();
break;
case '1.4.0':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_0();
$this->migrate_1_6_0();
$this->migrate_1_5_0();
$this->migrate_1_4_7();
break;
case '1.3.0':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_0();
$this->migrate_1_6_0();
$this->migrate_1_5_0();
$this->migrate_1_4_0();
break;
case '1.2.2':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_0();
$this->migrate_1_6_0();
Expand All @@ -243,6 +254,7 @@ public function migrate( $deprecated = null, $deprecated2 = null ) {
$this->migrate_1_3_0();
break;
case '1.2.1':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_0();
$this->migrate_1_6_0();
Expand All @@ -252,6 +264,7 @@ public function migrate( $deprecated = null, $deprecated2 = null ) {
$this->migrate_1_2_2();
break;
case '1.2.0':
$this->migrate_1_10_5();
$this->migrate_1_8_0();
$this->migrate_1_7_0();
$this->migrate_1_6_0();
Expand Down Expand Up @@ -560,7 +573,7 @@ private function migrate_1_6_0() {
* @see https://github.com/epiphyt/embed-privacy/issues/163
* @since 1.7.0
*
* - Update Google Maps regex
* - Update CrowdSignal regex
*/
private function migrate_1_7_0() {
$crowdsignal_provider = \get_posts( [
Expand Down Expand Up @@ -674,6 +687,45 @@ private function migrate_1_8_0() {
] );
}

/**
* Migrations for version 1.10.5.
*
* @see https://github.com/epiphyt/embed-privacy/issues/235
* @since 1.10.5
*
* - Rename Twitter to X
*/
private function migrate_1_10_5() {
$twitter_provider = \get_posts( [
'meta_key' => 'is_system',
'meta_value' => 'yes',
'name' => 'twitter',
'no_found_rows' => true,
'post_type' => 'epi_embed',
'update_post_term_cache' => false,
] );
$twitter_provider = \reset( $twitter_provider );

if ( $twitter_provider instanceof WP_Post ) {
$x_provider = [
'ID' => $twitter_provider->ID,
'post_name' => \sanitize_title( \_x( 'X', 'embed provider', 'embed-privacy' ) ),
'post_title' => \_x( 'X', 'embed provider', 'embed-privacy' ),
];

/* translators: embed provider */
if ( $twitter_provider->post_content === \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Twitter', 'embed provider', 'embed-privacy' ) ) ) {
/* translators: embed provider */
$x_provider['post_content'] = \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'X', 'embed provider', 'embed-privacy' ) );
}

\wp_update_post( $x_provider );
\update_post_meta( $twitter_provider->ID, 'privacy_policy_url', \__( 'https://x.com/privacy', 'embed-privacy' ) );
\update_post_meta( $twitter_provider->ID, 'regex_default', '/(twitter|x)\\\.com/' );
\update_post_meta( $twitter_provider->ID, 'is_system', 'yes' );
}
}

/**
* Register default embed providers.
*/
Expand Down Expand Up @@ -1066,13 +1118,13 @@ public function register_default_embed_providers() {
[
'meta_input' => [
'is_system' => 'yes',
'privacy_policy_url' => \__( 'https://twitter.com/privacy', 'embed-privacy' ),
'regex_default' => '/twitter\\\.com/',
'privacy_policy_url' => \__( 'https://x.com/privacy', 'embed-privacy' ),
'regex_default' => '/(twitter|x)\\\.com/',
],
/* translators: embed provider */
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'Twitter', 'embed provider', 'embed-privacy' ) ),
'post_content' => \sprintf( \__( 'Click here to display content from %s.', 'embed-privacy' ), \_x( 'X', 'embed provider', 'embed-privacy' ) ),
'post_status' => 'publish',
'post_title' => \_x( 'Twitter', 'embed provider', 'embed-privacy' ),
'post_title' => \_x( 'X', 'embed provider', 'embed-privacy' ),
'post_type' => 'epi_embed',
],
[
Expand Down
28 changes: 28 additions & 0 deletions inc/class-system.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace epiphyt\Embed_Privacy;

/**
* System functionality.
*
* @author Epiphyt
* @license GPL2
* @package epiphyt\Embed_Privacy
* @since 1.10.2
*/
final class System {
/**
* Determines whether a plugin is active.
*
* Basically a wrapper around core's is_plugin_active(), but with auto-loading.
*
* @param string $plugin Path to the plugin file relative to the plugins directory
* @return bool Whether the plugin is active
*/
public static function is_plugin_active( $plugin ) {
if ( ! \function_exists( 'is_plugin_active' ) ) {
include_once \ABSPATH . 'wp-admin/includes/plugin.php';
}

return \is_plugin_active( $plugin );
}
}
9 changes: 5 additions & 4 deletions inc/data/class-providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ public static function init() {
* Get an embed provider by its name.
*
* @param string $name The name to search for
* @return \epiphyt\Embed_privacy\embed\Provider|null The embed or null
* @return \epiphyt\Embed_privacy\embed\Provider The embed provider
*/
public function get_by_name( $name ) {
$provider = new Provider();

if ( empty( $name ) ) {
return null;
return $provider;
}

$embed_providers = $this->get_list();
$provider = null;
$name = self::sanitize_name( $name );

foreach ( $embed_providers as $embed_provider ) {
Expand Down Expand Up @@ -208,7 +209,7 @@ public function get_list( $type = 'all', $args = [] ) {
* @param string $identifier Current identifier
* @param array $global_list List with all providers of all identifiers
*/
$this->list[ $identifier ] = \apply_filters( 'embed_privacy_provider_list', $this->list[ $identifier ], $identifier, $this->list );
$this->list[ $identifier ] = (array) \apply_filters( 'embed_privacy_provider_list', $this->list[ $identifier ], $identifier, $this->list );

return $this->list[ $identifier ];
}
Expand Down
Loading

0 comments on commit f97f1f6

Please sign in to comment.