• Resolved Bjarne Oldrup

    (@oldrup)


    Final question today, I promise 😉

    So besides the already hidden core embeds, at the time of writing:

    Amazon Kindle, Animoto, Cloudup, Crowd Signal, Daily Motion, Hulu, Mixcloud, Polldaddy, Reverbnation, Smugmug, Speaker, VideoPress, Wolfram Cloud, and WordPress.tv

    How do I hide more embeds? Say, I’d like to hide SoundCloud, Twitter and Spotify. I experimented with the following, which is not working, but maybe could give you an idea of what I’m trying to achieve:

    // MRW Simplified Editor - Hide Additional Embeds
    
    add_filter( 'mrw_hidden_embeds', 'mrw_hide_additional_embeds', 10, 2 );
    function mrw_hide_additional_embeds( $hidden_embeds ) {
    	$hidden_embeds[] = array('soundcloud','twitter','spotify');
    	return $hidden_embeds;
    }

    And can it be turned around, to be a positive list instead of a negative list? Like, only allow, say, YouTube and Vimeo embeds, disable all the others?

    Again, thanks for the help. And no stress!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author mrwweb

    (@mrwweb)

    Good question. All the code examples take the approach of modifying the existing list and even accounting for the possibility that additional plugins or theme files are also filtering that list elsewhere.

    To hide additional embeds, you need to add them individually to the array or merge the existing array with a new one.

    Not tested, but this should work:

    add_filter( 'mrw_hidden_embeds', 'wp17244821_hide_embeds', 10, 2 );
    function wp17244821_hide_embeds( $hidden_embeds ) {
    	$new_embeds_to_hide = array('soundcloud','twitter','spotify');
    	return array_merge( $hidden_embeds, $new_embeds_to_hide );
    }

    Since the filter takes the approaching of explicitly hiding each embed, there’s not really a way to create an “allowlist” of embeds. That’s an interesting request though, and I wouldn’t immediately dismiss adding it at a future date. If you’d like me to consider doing that, please open a new issue in the Github repository and include a bit of background/use case for it.

    And just in case it’s relevant, note that there’s a separate filter for hiding Jetpack embeds.

    Let me know if that works for you!

    Thread Starter Bjarne Oldrup

    (@oldrup)

    Hey. Thank you for the help! The snippet indeed works as intended. Now, only the embeds I support, are listed in the block inserter:

    Screenshot: Only Embed, YouTube and Vimeo are available.

    Here is the complete code, that I, at the time of writing, use to hide all the embeds I’m not using:

    // MRW Simplified Editor - Hide specific embedes in block editor
    
    add_filter("mrw_hidden_embeds", "wp231202_hide_embeds", 10, 2);
    function wp231202_hide_embeds($hidden_embeds)
    {
        $new_embeds_to_hide = [
            "flickr",
            "imgur",
            "issuu",
            "kickstarter",
            "pinterest",
            "reddit",
            "screencast",
            "scribd",
            "slideshare",
            "soundcloud",
            "speaker-deck",
            "spotify",
            "ted",
            "tiktok",
            "tumblr",
            "twitter",
            "wordpress",
        ];
        return array_merge($hidden_embeds, $new_embeds_to_hide);
    }
    
    // Plugin URL: https://wordpress.org/plugins/mrw-web-design-simple-tinymce/

    It’s not difficult to add or remove embeds from the list now that it’s so don’t spend more time on the suggested “allow-list” approach. No need for that anymore.

    Thank you again! I look forward to a simple and safer editing experience 😊

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to hide additional embeds?’ is closed to new replies.