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

Nikola Nikolov nikolov.tmw at gmail.com
Wed Jan 15 15:00:05 UTC 2014


That's true I forgot that there for a second.


On Wed, Jan 15, 2014 at 4:43 PM, Otto <otto at ottodestruct.com> wrote:

> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list