• Resolved mocha365

    (@mocha365)


    I’ve created a custom slide excerpt length (to be separate from the excerpt length for the blog). I did this:

    if ( ! function_exists( 'slide_excerpt' ) ) {
    	function slide_excerpt( $limit = 50 ) {
    	    echo '<p>'. wp_trim_words(get_the_excerpt(), $limit) .'</p>';
    	}
    }

    After testing with the NS Theme Check plugin, I get this:

    Expected next thing to be an escaping function (see Codex for ‘Data Validation’), not ‘wp_trim_words’

    Obviously it thinks this needs escaping somehow, but I’ve tried different methods; does anyone know if this test is a false positive, or is there a way to actually escape that one line with the wp_trim_words….?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    I don’t know what the theme check is really checking for, but it’s not a false positive. Your output should be escaped. I suspect theme check is expecting to see something like this:
    echo esc_html( get_the_excerpt());

    For your specific code, something like this is acceptable:
    echo '<p>'. esc_html( wp_trim_words( get_the_excerpt(), $limit)) .'</p>';

    If that does not satisfy theme check, then it is now a false positive.

    @bibekpradhan1 – it appears you replied to the wrong topic. I’ll leave it up for a few hours for your reference, but it will then be archived for being off topic. Thank you for helping out in the forums. Silly mistakes happen to all of us, no worries there.

    Thread Starter mocha365

    (@mocha365)

    Hi @bcworkz …thanks for the reply. Your suggestion is one I did before but it did not work. However, what is really odd is that I tried it again after seeing what you posted with the suggested code, and now it worked.

    Now I have just 3 more warnings from the NS theme check to try and find a solution for fixing. I will work on these ones but if no luck, I will post them in a new topic.

    Anyway, thanks for the reply and solution.
    Cheers!

    Moderator bcworkz

    (@bcworkz)

    Happy to help. That is odd. Maybe you were seeing a cached response that threw you off. It happens to me once in a while. It’s hard to remember to flush everything when you are getting unexpected results.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp_trim_words escaping?’ is closed to new replies.