• Resolved Eric Hepperle

    (@codeslayer2010)


    I didn’t not find any way to submit this question to https://developer.wordpress.org/, so it looks like this is next best relevant place.

    What does the $context variable do / mean in the wp_kses_allowed_html() function? The documentation rather unhelpfully says, for the $context parameter description, “Context name.

    Ok, but what is a context?

    Please direct me to the correct WordPress forum if this in not it. Thanks for any help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • This reference has a bit more info on the function: https://developer.wordpress.org/reference/functions/wp_kses_allowed_html/

    Thread Starter Eric Hepperle

    (@codeslayer2010)

    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;
    }

    `

    Thread Starter Eric Hepperle

    (@codeslayer2010)

    Marking as solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘What is $context in wp_kses_allowed_html()?’ is closed to new replies.