Getting forum page name from plugin
-
Hi,
Here’s my situation. I have a site with several forums. Let’s call them Forum A, B and C. All users to the site can view Forum A. Through other actions that happen on the site users collect points. At a certain point total Forum B becomes available. At another point total Forum C becomes available. There is an external webservice I can call to see if the user has the appropriate number of points for the relevant Forum.
As far as I can tell, bbPress doesn’t have the built in capability to handle that particular permissions scenario so I’m building a plugin. My plugin is hooking on the “user_has_cap” filter to determine whether a user can see a particular forum. I don’t want to make an external webservice call on every single current_user_can() call that gets made during a page load, so in my hook function I want to immediately check to see if the current request is a Forum page.
For example, if the requested page was “http://localhost/wordpress/forums/forum/forum-b/” then being able to get the pagename “forums” it would allow me to jump out of my hook function immediately if the request wasn’t for a forum page or topic. Below is a copy of code/pseudocode for what I’m doing in the plugin.
function forum_lock_check($allcaps, $cap) { if (pagename != "forums") return $allcaps; if (webservice says I can) { $allcaps["can-view-forum"] = true; } return $allcaps; } add_filter("user_has_cap", "forum_lock_check", 10, 3);
Is there a wordpress or bbpress function that gives me the pagename the forum is attached to? Of course, if there is an easier way to do what I want, I’m all ears for that as well. Thanks for any help you can give me.
- You must be logged in to reply to this topic.