Forum Replies Created
I’m not saying there is anything wrong with the members plugin, I just have not needed it. Like you I prefer code as I need to support multiple sites. And looking in the actual DB tends to provide a more reliable view of what is really going on.
The original post of this topic could do with some clarification though, and then put up as proper bbPress doc.
I ended up getting
$user = get_userdata( $user_id );
to work. (I had been using the wrong method to get the $user.)
But it is still messy. And @moonoi points out this will be lost whenever the UI is used, due to the set_role bug.
get_role( ‘author’ )->add_cap( ‘read_private_topics’ );
Still does not work, although it should. It would be a better solution for me because like 90% of sites I only actually need one role per user.
It would be good to fix WP in this regard, and then remove the mess from bbPress. Or in the meantime just make BBPress work like everything else. Mucking about with roles is an orthogonal problem.
@Moonoi I have not played with the Members Plugin, but WP by default does NOT store capabilities against users. It stores Roles agains users, and capabilities against Roles, at least by default.
You say “Capabilities are saved in the database, per user, per site”. That is clearly NOT the (normal) case. The wp_usermeta table wp_2_capabilities row stores ROLES, not capabilities. Those roles appear to index into the wp_2_options tble row wp_2_user_roles row which contains a list of capabilities.
I have no idea what “Dynamic” roles are nor why bbpress contains a vast amount of capability fidling code, including no less than three files called capability.php. If someone could explain it in terms of actual table rows and colums that might help.
I want a simple setup where Authors can access Private forums but only in the site which they are an Author. The simple coupled set up that JJJ says is too simplistic. But now it cannot be done at all?
By default private sites are hidden to users. There is a weird “Auto Role” option that can adds bbp_participant to all users. But that means that users get access to all forums on all sites. Is that the “Dynamic role” feature?
So turn that off. Try to add bbp_participant role explicitly using action ‘add_user_to_blog’
However, that failed to add the user. WordPress really only supports one role per user, certainly set_role() only accepts a single role and purges any others. So I think something is resetting it.
Then I try simply
get_role( ‘author’ )->add_cap( ‘read_private_topics’ ); // for bbpress.
That successfully updates the database (wp_2_user_roles), but has no effect on bbpress. I suspect because one of the capability.php files in bbpress has
case bbp_get_spectator_role() … ‘read_hidden_forums’ => false,
rather than just leaving it out. So capabilities do not merge properly between roles.
I am new to WordPress/bbPress, and having spent many hours in this mess am getting very frustrated. How hard can it be? Users/Roles/Capabilities.
AnthonyIn reply to: How to get a list of forums
Thanks, but I’m not sure how that helps. (I prefer to avoid direct db queries, but it is obvious how to make them.)
I did discover get_pages, which seems to be similar to get_posts but with a completely different implementation. The following now works.
return get_pages( array( ‘post_type’ => bbp_get_forum_post_type(), ‘numberposts’ => 99,
‘post_status’ => array(‘publish’, ‘private’)) );
I would still like an answer to the other part of my question, if anyone knows. Ie where is the output generated for things like Admin All Forums in bbpress. These provide good places to look for API examples.
But silence is better than noise.
(By “plug-in” above I mean bbpress-new-topic-notifications/. Do not seem to be able to edit my entries any more?
Did you get any joy with this, as I have the same issue.
The problem plugin does not do what is required because users cannot subscribe themselves to forums, like they can to topics.