diff --git a/includes/Frontend/PrivacyEmbeds.php b/includes/Frontend/PrivacyEmbeds.php
new file mode 100644
index 0000000..6708107
--- /dev/null
+++ b/includes/Frontend/PrivacyEmbeds.php
@@ -0,0 +1,119 @@
+ opening tags are
+ * touched. Every URL-carrying attribute in them is rewritten — src, plus
+ * lazy-load copies such as data-src or WP Rocket's data-lazy-src — so
+ * lazy-loaded embeds are covered too.
+ *
+ * @since 1.0.3
+ */
+class PrivacyEmbeds {
+
+ /**
+ * Constructor.
+ */
+ public function __construct() {
+ if ( is_admin() ) {
+ return;
+ }
+
+ add_action( 'template_redirect', array( $this, 'maybe_start_output_buffer' ) );
+ }
+
+ /**
+ * Whether YouTube/Vimeo iframes are switched to their cookieless modes.
+ *
+ * Only while the Cookie Notice is enabled: with it off, FrontConsent
+ * leaves the page output untouched.
+ *
+ * @return bool
+ */
+ public static function is_enabled() {
+ $options = get_option( 'frontconsent_settings', array() );
+ $enabled = (bool) ( $options['enable_cookie_notice'] ?? false );
+
+ /**
+ * Filters whether FrontConsent rewrites YouTube embeds to
+ * youtube-nocookie.com and adds Vimeo's "dnt=1" flag.
+ *
+ * @param bool $enabled Default true while the Cookie Notice is enabled.
+ */
+ return (bool) apply_filters( 'frcn_privacy_enhanced_embeds', $enabled );
+ }
+
+ /**
+ * Start buffering the frontend HTML output, only for regular page
+ * requests and only when the feature is enabled.
+ *
+ * @return void
+ */
+ public function maybe_start_output_buffer() {
+ if ( is_admin() || wp_doing_ajax() || wp_doing_cron() || ( function_exists( 'wp_is_json_request' ) && wp_is_json_request() ) || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) {
+ return;
+ }
+
+ if ( ! self::is_enabled() ) {
+ return;
+ }
+
+ ob_start( array( __CLASS__, 'rewrite_html' ) );
+ }
+
+ /**
+ * Switch YouTube and Vimeo iframes in the given HTML to their cookieless
+ * modes.
+ *
+ * Public static so it's directly unit-testable.
+ *
+ * @param string $html HTML to scan.
+ * @return string Rewritten HTML.
+ */
+ public static function rewrite_html( $html ) {
+ if ( '' === $html || false === stripos( $html, '';
+
+ $result = PrivacyEmbeds::rewrite_html( $html );
+
+ $this->assertStringContainsString( 'src="https://www.youtube-nocookie.com/embed/abc123?rel=0"', $result );
+ $this->assertStringContainsString( 'data-lazy-src="https://www.youtube-nocookie.com/embed/abc123"', $result );
+ $this->assertStringNotContainsString( '//www.youtube.com/embed', $result );
+ }
+
+ /**
+ * The oEmbed markup WordPress stores for a pasted YouTube link keeps every
+ * other attribute untouched; only the domain changes.
+ */
+ public function test_oembed_markup_only_changes_the_domain() {
+ $html = '';
+
+ $this->assertSame(
+ str_replace( 'www.youtube.com', 'www.youtube-nocookie.com', $html ),
+ PrivacyEmbeds::rewrite_html( $html )
+ );
+ }
+
+ /**
+ * A Vimeo player embed gets dnt=1, appended to an existing query string
+ * when there is one, and is left alone when it already carries it.
+ */
+ public function test_vimeo_iframe_gets_do_not_track_flag_once() {
+ $this->assertStringContainsString(
+ 'src="https://player.vimeo.com/video/123?dnt=1"',
+ PrivacyEmbeds::rewrite_html( '' )
+ );
+ $this->assertStringContainsString(
+ 'src="https://player.vimeo.com/video/123?h=abc&dnt=1"',
+ PrivacyEmbeds::rewrite_html( '' )
+ );
+
+ $already = '';
+ $this->assertSame( $already, PrivacyEmbeds::rewrite_html( $already ) );
+ }
+
+ /**
+ * Only iframes are rewritten: a plain link to a YouTube video stays as is.
+ */
+ public function test_youtube_links_outside_iframes_are_untouched() {
+ $html = 'Watch';
+
+ $this->assertSame( $html, PrivacyEmbeds::rewrite_html( $html ) );
+ }
+
+ /**
+ * The rewrite follows the Cookie Notice: off while it is disabled, on
+ * while it is enabled, and the filter can still turn it off.
+ */
+ public function test_is_enabled_follows_the_cookie_notice_and_the_filter() {
+ $this->assertFalse( PrivacyEmbeds::is_enabled() );
+
+ update_option( 'frontconsent_settings', array( 'enable_cookie_notice' => true ) );
+ $this->assertTrue( PrivacyEmbeds::is_enabled() );
+
+ add_filter( 'frcn_privacy_enhanced_embeds', '__return_false' );
+ $this->assertFalse( PrivacyEmbeds::is_enabled() );
+ remove_filter( 'frcn_privacy_enhanced_embeds', '__return_false' );
+ }
+}