• thezman

    (@thezman)


    In “theory” the has_excerpt() function is supposed to return FALSE when a post_excerpt is empty, however it does not consider the possibility of “empty white space”.

    Ergo, consider the following mod to the function:

    
    function has_excerpt( $post = 0 ) {
        $post = get_post( $post );
        // check if its just empty white-space
        $post_excerpt = trim(preg_replace('/\s+/', ' ', $post->post_excerpt));
        // then return it
        return ( ! empty(  $post_excerpt ) );
    }
    

    TO RECREATE:
    Simply add a few empty spaces into an “excerpt” in a post and then check it using has_excerpt(), you will see the has_excerpt() returns TRUE, even though to us as humans its clearly “not true”.

    EXPECTED BEHAVIOR:
    When a $post->post_excerpt is “only empty white-space” then has_excerpt() should return FALSE.

    • This topic was modified 5 years ago by thezman.
    • This topic was modified 5 years ago by thezman.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Joy

    (@joyously)

    In theory, the user can put whatever they want as the excerpt, including some spaces, so adding your change would not be backward compatible.
    I interpret the function name has_excerpt to mean “Did the user type something in the excerpt?”

Viewing 1 replies (of 1 total)
  • The topic ‘Patch suggestion – has_excerpt() does not check for empty white space’ is closed to new replies.