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

Otto otto at ottodestruct.com
Sun Jan 19 01:15:56 UTC 2014


On Sat, Jan 18, 2014 at 6:57 PM, David F. Carr
<david at carrcommunications.com> wrote:
> 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.

No particular reason, other than avoiding direct use of globals when
you don't actually need them is always a pretty good idea.

Using a global means that you might modify the global accidentally,
and in this case, I had no need to modify the $post global.  On the
other hand, get_post() returns the same global post object anyway, but
now the $post variable is in the function context space, so if I did
accidentally modify it, then the result of that change would not
affect anything else.

-Otto


More information about the wp-hackers mailing list