Support » Plugin: Code Snippets » Snippet description styles issue in 3.0.x

  • Resolved Alexandre Froger

    (@frogerme)


    
    <span style="display: none;"><br>
    <span style="padding: 2px 5px;font-weight: bold;background-color: #db1212;color: #fff">IMPORTANT</span><br>
    <span style="background-color: #202124;color: #e8eaed;font-family: menlo, monospace;font-size: 11px">some code</span><br></span>
    

    I use the markup above in my template snippets’ description to reuse after cloning.
    Before 3.0.x, it would not be displayed as expected in the snippets’ list.
    After update, it is displayed, and looking at the inspector, the display: none css property is now stripped from the first span at rendering, like so:

    
    <span><br>
    <span style="padding: 2px 5px;font-weight: bold;background-color: #db1212;color: #fff">IMPORTANT</span><br>
    <span style="background-color: #202124;color: #e8eaed;font-family: menlo, monospace;font-size: 11px">some code</span><br>
    </span>
    

    Please advise.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    This looks like it is due to the wp_kses_post filter that’s run on the snippet description.

    I’m not sure why wp_kses_post is messing with your markup, but it seems to be the culprit.

    If you want to remove it, you can add this as a snippet:

    add_action( 'admin_head', function () {
    	remove_filter( 'code_snippets/list_table/column_description', 'wp_kses_post' );
    } );
    Thread Starter Alexandre Froger

    (@frogerme)

    Thanks for the filter @bungeshea !
    Works like a charm ; I’m not sure this qualifies as “Resolved” because it’s more of a hotfix adding an unnecessary database record, and the plugin itself still has a feature regression issue, but that solved my immediate problem!

    Plugin Author Shea Bunge

    (@bungeshea)

    It’s definitely something to address in the plugin itself, I’m just unsure how to do so, as wp_kses_post is definitely something we should be running on the description output, and it’s a function that is included with WordPress itself, so if there is a bug with how it handles that sort of markup then that’s where it should be addressed.

    I’ll do some digging into the function and see if I can figure out why this is happening. It seems strange that style would be stripped from one span tag and not the others.

    Thread Starter Alexandre Froger

    (@frogerme)

    I think I have a lead:

    https://wordpress.stackexchange.com/questions/173526/why-is-wp-kses-not-keeping-style-attributes-as-expected

    As indicated in the post, using that filter before applying the wp_kses_post in Code Snippets code base and removing it right after should do the trick:

    
    add_filter( 'safe_style_css', function( $styles ) {
        $styles[] = 'display';
        return $styles;
    } );
    
    Plugin Author Shea Bunge

    (@bungeshea)

    Ah, I should have remembered that wp_kses also checks through the styles. Good catch!

    I’ll make sure I include something that allows for this more permissive markup in snippet descriptions in the next release.

    Plugin Author Shea Bunge

    (@bungeshea)

    Added this change in v3.1.0.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.