[wp-hackers] glitch with the_content filter and password-protected posts

Otto otto at ottodestruct.com
Wed Jan 15 14:43:39 UTC 2014


On Wed, Jan 15, 2014 at 7:58 AM, Nikola Nikolov <nikolov.tmw at gmail.com> wrote:
> So it seems like what you should do in your function that adds extra output
> is something like this:
>
> if ( post_password_required( $post ) ) {
>     return '';
> }

Actually, you want to return the content unchanged, so that the
password form is properly displayed. Filters that do nothing need to
return whatever input they were given, not an empty string.

So, something like this:

add_filter('the_content','example');
function example( $content ) {
  $post = get_post();
  if ( post_password_required( $post ) ) {
    return $content;
  }

  // .. rest of your filter code here
}


-Otto


More information about the wp-hackers mailing list