[wp-hackers] glitch with the_content filter and password-protected posts
David F. Carr
david at carrcommunications.com
Sun Jan 19 00:57:35 UTC 2014
Thanks for your help.
Otto, why do you use $post = get_post() in your example code?
I usually put global $post at the top of the function definition.
On Wed, Jan 15, 2014 at 10:00 AM, Nikola Nikolov <nikolov.tmw at gmail.com>wrote:
> 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
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
--
David F. Carr
Author, Social Collaboration for Dummies
http://www.wiley.com/buy/9781118658543
InformationWeek http://www.informationweek.com/authors/David-Carr
david at carrcommunications.com
Direct: (954) 757-5827
Mobile: (954) 290-6788
LinkedIn - http://www.linkedin.com/in/davidfcarr
Facebook - http://www.facebook.com/carrcomm
David F. Carr
971 NW 124 Ave.
Coral Springs FL 33071-5082
More information about the wp-hackers
mailing list