From 46c2c32119afc816a2b631ec6d5df0e81fabd4c6 Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Wed, 11 Sep 2024 17:02:35 -0400 Subject: [PATCH] Add a shortcode for nocookie youtube embeds (#651) * Add a shortcode for nocookie youtube embeds * Remove the unused tag parameter --- mu-plugins/plugin-tweaks/index.php | 1 + .../plugin-tweaks/youtube-shortcode.php | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 mu-plugins/plugin-tweaks/youtube-shortcode.php diff --git a/mu-plugins/plugin-tweaks/index.php b/mu-plugins/plugin-tweaks/index.php index acd96df30..b77aa9295 100644 --- a/mu-plugins/plugin-tweaks/index.php +++ b/mu-plugins/plugin-tweaks/index.php @@ -13,3 +13,4 @@ require_once __DIR__ . '/stream.php'; require_once __DIR__ . '/incompatible-plugins.php'; require_once __DIR__ . '/gutenberg.php'; +require_once __DIR__ . '/youtube-shortcode.php'; diff --git a/mu-plugins/plugin-tweaks/youtube-shortcode.php b/mu-plugins/plugin-tweaks/youtube-shortcode.php new file mode 100644 index 000000000..5db4837bc --- /dev/null +++ b/mu-plugins/plugin-tweaks/youtube-shortcode.php @@ -0,0 +1,54 @@ + '100%', + 'height' => false, + 'title' => 'YouTube video player', + ); + $args = shortcode_atts( $defaults, $attr ); + + $html_attrs = ''; + foreach ( $args as $name => $value ) { + if ( $value ) { + $html_attrs .= $name . '="' . esc_attr( $value ) . '" '; + } + } + + return sprintf( + // `allow` settings copied from youtube-provided embed code. + '', + esc_url( $content ), + $html_attrs + ); +}