What is $context in wp_kses_allowed_html()?

[ad_1]

This reference has a bit more info on the function: https://developer.projectdmc.org/reference/functions/wp_kses_allowed_html/

Thanks @gappiah George. That is definitely a hint in the right direction!

From your link I learned that “post” is the most permissive and changing the context to “post” fixed the issue and let me iframes finally render dynamically from ACF fields 🙂

Looks like the codex had some good notes about the contexts and what each is for, but those didn’t get incorporated into the the API docs, but got attached as a user comment:

// strips all html (empty array)
$allowed_html = wp_kses_allowed_html( 'strip' );

// allows all most inline elements and strips all block level elements except blockquote
$allowed_html = wp_kses_allowed_html( 'data' );

// very permissive: allows pretty much all HTML to pass - same as what's normally applied to the_content by default
$allowed_html = wp_kses_allowed_html( 'post' );

// allows a list of HTML Entities such as  
$allowed_html = wp_kses_allowed_html( 'entities' );

Super stoked this is working now!

Here is the code I ended up using for future reference:

add_filter( 'wp_kses_allowed_html', 'acf_add_allowed_iframe_tag', 10, 2 );
function acf_add_allowed_iframe_tag( $tags, $context ) {
    if ( $context === 'post' ) {
        $tags['script'] = array(
            'src'             => true,
            'height'          => true,
            'width'           => true,
            'frameborder'     => true,
            'allowfullscreen' => true,
        );
    }

    return $tags;
}

`

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer