Plugins only working for logged in users ?
-
Hi guys,
A site i am currently working on needs to be able to display “future posts” so that certain events/parties can be shown with ample ‘heads up’ to their userbase.
Now i have found the support posts and suggestions here in the forums to get WP to show ‘all’ posts in the future via a plugin (by Michael Moncur), this plugin was only designed for users that were logged in.
So I went about and created my own little plugin that would allow anyone to see posts in future for a certain timeframe ahead (i.e. 30 days)
My question is, WHY is this plugin only executed for someone that is logged into WP?
I have just tried this in multiple setups, if i am not logged in the plugin below (even though it’s active) is completely disregarded by WP, I even made the SQL it replaces invalid to see if it would break .. nada.
I then logged in (with the incorrect SQL replacement still in the active plugin and tada it broke the query.
I fixed up the preg_replace again and the plugin works absolutely find as long as i am logged in. I can change the days in the future it should grab posts up to, to anything i please with the result instantly showing
up in any section of the site.Now I do know of the ‘hack’ for classes.php which lets me fix this problem for any user, logged in or not but i’d much rather do this the ‘proper’ way so that i can upgrade WP in the future without breaking core files.
If anyone knows WHY this plugin is only executed when you’re logged in OR how to fix this ‘problem’, PLEASE let me know.
function x_futureposts_plugin($content){
//amount of days in the future post will be retrieved for;
//i.e. 30 to grab everything from now +30 days ahead
$daysAhead = 30;//don't edit below (unless you know what you're doing
$date_daysAhead = gmdate('Y-m-d H:i:59',mktime(0, 0, 0, gmdate("m"), gmdate("d")+$daysAhead, gmdate("Y")));$content = preg_replace("/AND post_date_gmt <= '.+')/", "AND post_date_gmt <= '$date_daysAhead'", $content);
return $content;
}
add_filter('posts_where', 'x_futureposts_plugin');Thanks,
Ragnar
- The topic ‘Plugins only working for logged in users ?’ is closed to new replies.