Skip to:
Content
Pages
Categories
Search
Top
Bottom

Confused about filter bb_current_user_can

  • @burtadsit

    Member

    It’s not the first time and it won’t be the last. I’m confused.

    I’m trying to add forum moderator capabilities to the currently logged in user in a specific forum only. I don’t want to give them the moderator role. I just need to give them additional caps in a specific forum. When the user is tooling ’round in the forum I want to give mod rights to, assign them dynamicly. When they are no longer in that forum, take ’em away on the fly.

    If found a couple of things to guide me. One was forum-moderators.php by Aditya Naik. This give specific users a forum moderator role thru the bbpress backend. That stores the rights to those caps as a meta value and assigns them when the user is on the forums. Great. There’s a fn in there that determines what forum the user is in and responds to a filter called ‘bb_user_has_cap’. I can’t find neither hide nor hair of using this filter anywhere except in a couple of plugins by sambauers. http-authentication and ldap-authentication.

    So, I found the filter ‘bb_current_user_can’. It looks to me like everyone on the planet is using this filter. The comment in the fn bb_currrent_user_can() says use ‘bb_user_has_cap’. Well, nothing is using that as far as I can determine.

    Anyway, my confusion comes in when I try to implement my filter. I’m gonna give the user the following caps:

    $forum_mod_caps = array(
    'manage_topics' ,
    'edit_closed' ,
    'edit_deleted' ,
    'browse_deleted' ,
    'edit_others_tags' ,
    'edit_others_topics' ,
    'manage_posts' ,
    'ignore_edit_lock' ,
    'edit_others_posts'
    );

    For me, reading the code for bb_current_user_can() is like the time I got curious about implementing tcp/ip for the Atari ST. I got a headache. My skill level is not up to understanding what is going on down there. Some guidance would be appreciated.

    We have 3 args to this filter:

    $retvalue, $capability, $args

    Looks like $retvalue is being passed up the filter chain. If I don’t want to touch the call I just pass $retvalue back.

    I was digging ’round and looks like $capabilities is the cap being queried. $args is specific to each call and may vary depending on what cap is queried.

    These are questions in case you haven’t noticed. My understanding breaks down when I get to what I’m being passed and what I’m supposed to do with them other than return ‘true’ if it’s a cap I want to let the user have.

    I should just return true if it’s a cap I want the user to have. It’s up to me to determine if it’s appropriate at their location in the universe. Yes?

Viewing 3 replies - 1 through 3 (of 3 total)
  • @_ck_

    Participant

    Um, forum-moderators does exactly what you want, but it probably needs to be updated for 0.9 and 1.0

    I have an unreleased plugin called “extra privileges” that does something like what you are asking but it won’t be released anytime soon.

    You can see how filters on bb_current_user_can work by studying this mini-plugin I wrote to allow users to delete their own posts

    function delete_own_post($retvalue, $capability, $args) {
    global $bb_current_user, $bb_post;
    if ($capability=="delete_post" && $bb_current_user->ID && $bb_post && $bb_post->post_id && $bb_post->post_id ==intval($args[1]) &&
    $bb_post->poster_id && $bb_post->poster_id==$bb_current_user->ID && bb_current_user_can( 'edit_post', $bb_post->post_id) {return true;} // lots and lots of double checks
    return $retvalue;
    }
    add_filter('bb_current_user_can', 'delete_own_post',10,3);

    or simplier version:

    function delete_own_post($retvalue, $capability, $args) {
    if ($capability=="delete_post") {return bb_current_user_can( 'edit_post', $args[1]);}
    return $retvalue;
    }
    add_filter('bb_current_user_can', 'delete_own_post',10,3);

    @burtadsit

    Member

    Thanks _ck_ i’ll study these.

    Damn _ck_. I do believe that’s the longest compound ‘and’ statement I’ve seen in awhile. :) Whatever works ‘eh?

    Thanks again.

    @burtadsit

    Member

    k. Think I got this licked. Wasn’t working there for about 4 hrs though. I wanted to assign various mod caps to a user in specific forums. I did that and the template goodies for a mod popped up all over the place. Well this was easy. Wrong.

    Deleting a post is an ajax maneuver. The ajax code calls bb_current_user_can() again. So what’s the prob? I’m still returning ‘ok’ as a cap for ‘delete_post’. Well I’m also checking for a forum_id as part of the validation process. ajax calls exist outside in the twilight zone where there are no valid forums. Poor things.

    Had to check for DOING_AJAX, determine what forum the post was in and then say ‘ok’.

    To think my mother wanted me to be a plumber. Plumbers don’t have this kind of fun.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar