diff --git a/class-opengraph-fallback-embed.php b/class-opengraph-fallback-embed.php index 18a8fe5..d9db322 100644 --- a/class-opengraph-fallback-embed.php +++ b/class-opengraph-fallback-embed.php @@ -23,6 +23,9 @@ class OpenGraph_Fallback_Embed { /** @var int Cache duration in seconds (default 7 days). */ const CACHE_TTL = 604800; + /** @var string Transient key prefix for cached OG data. */ + const CACHE_KEY_PREFIX = 'opengraph_fallback_embed_'; + /* ------------------------------------------------------------------ * Bootstrap * ----------------------------------------------------------------*/ @@ -104,8 +107,10 @@ public static function intercept_oembed_proxy( $response, $handler, $request ) { $site_name = ! empty( $og['site_name'] ) ? $og['site_name'] : wp_parse_url( $url, PHP_URL_HOST ); - // The editor renders "rich" embeds inside a sandboxed iframe, - // so styles must be inlined. + // The block editor renders "rich" type oEmbed responses inside a sandboxed + // iframe (wp.components.SandBox). The Embed block does not forward styles + // to SandBox, so wp_enqueue_style() / wp_add_inline_style() cannot reach + // the iframe. Inline styles in the oEmbed HTML are the only option. $css_file = plugin_dir_path( __FILE__ ) . 'build/og-embed/style-index.css'; $css = file_exists( $css_file ) ? file_get_contents( $css_file ) : ''; // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $card_html = self::render_card( $og, $url ); @@ -252,7 +257,7 @@ public static function rest_preview( WP_REST_Request $request ): WP_REST_Respons * @return array Associative array of OG properties. */ public static function get_og_data( string $url ): array { - $cache_key = 'og_embed_' . md5( $url ); + $cache_key = self::CACHE_KEY_PREFIX . md5( $url ); $cached = get_transient( $cache_key ); if ( is_array( $cached ) ) { diff --git a/readme.txt b/readme.txt index 545c829..cec32d5 100644 --- a/readme.txt +++ b/readme.txt @@ -36,8 +36,20 @@ No. This plugin only activates when WordPress has no other embed handler for the The card uses the `.og-fallback-embed` CSS class. You can override styles in your theme. +== Development == + +The source code for this plugin, including unminified JavaScript and CSS, is available on GitHub: + +https://github.com/pento/opengraph-fallback-embed + +The plugin uses [@wordpress/scripts](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/) for building. Source files are in the `src/` directory. See the repository README for build instructions. + == Changelog == += 1.3.5 = +* Add source code repository link to readme. +* Use plugin-specific prefix for transient cache keys. + = 1.3.4 = * Tweak the plugin header. diff --git a/tests/EmbedBlockFallbackTest.php b/tests/EmbedBlockFallbackTest.php index bc18c74..35afde7 100644 --- a/tests/EmbedBlockFallbackTest.php +++ b/tests/EmbedBlockFallbackTest.php @@ -27,8 +27,8 @@ class EmbedBlockFallbackTest extends WP_UnitTestCase { public function tear_down(): void { parent::tear_down(); - delete_transient( 'og_embed_' . md5( self::TEST_URL ) ); - delete_transient( 'og_embed_' . md5( self::YOUTUBE_URL ) ); + delete_transient( OpenGraph_Fallback_Embed::CACHE_KEY_PREFIX . md5( self::TEST_URL ) ); + delete_transient( OpenGraph_Fallback_Embed::CACHE_KEY_PREFIX . md5( self::YOUTUBE_URL ) ); } /* ------------------------------------------------------------------ diff --git a/tests/MaybeEmbedTest.php b/tests/MaybeEmbedTest.php index e421711..28273c6 100644 --- a/tests/MaybeEmbedTest.php +++ b/tests/MaybeEmbedTest.php @@ -7,7 +7,7 @@ class MaybeEmbedTest extends WP_UnitTestCase { public function tear_down(): void { parent::tear_down(); - delete_transient( 'og_embed_' . md5( 'https://example.com/article' ) ); + delete_transient( OpenGraph_Fallback_Embed::CACHE_KEY_PREFIX . md5( 'https://example.com/article' ) ); } public function test_url_with_og_data_returns_card(): void { diff --git a/tests/ParseOgTagsTest.php b/tests/ParseOgTagsTest.php index 0f6313d..be0a727 100644 --- a/tests/ParseOgTagsTest.php +++ b/tests/ParseOgTagsTest.php @@ -7,7 +7,7 @@ class ParseOgTagsTest extends WP_UnitTestCase { public function tear_down(): void { parent::tear_down(); - delete_transient( 'og_embed_' . md5( 'https://example.com/article' ) ); + delete_transient( OpenGraph_Fallback_Embed::CACHE_KEY_PREFIX . md5( 'https://example.com/article' ) ); } /**