jyd44 (@jyd44)

Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)

  • jyd44
    Participant

    @jyd44

    Hi,
    your initial question was about replies. In fact, you have exactly the same issues for posting, reading, and so on. You have to use the same kind of trick for every action you want to block.
    The best way to find which filter is key to control an action, is to start from the template files, to see which bb_call is made, read the source code of this function and discover which filter is applied. It’s the same also for the buddypress menus (either in the admin bar, either in the body of the page), depending on your requirements (eg. Do you allow a non member to discover the list of member in a group, and so on.)
    Yes it’s a huge job. When you complain about the way the access control in bbpress is handled, remember that I told you before that blocking the access to replies will not be the only one issue you will have to face. With roughly the same requirements, I have written more than 1800 lines of code (including comments !) to tune the menus and to refine the access control rules. Fortunately, thanks to the filter and action mechanism of WP and the goodwill of their developpers, bbPress and BuddyPress offer many possibilities for this tuning.


    jyd44
    Participant

    @jyd44

    My proposal is based on the hook mechanism proposed by WP and that bbPress use intensely, giving a lot of possibilities for (business) logic customisation. This is not related to the templates files in the theme, which are more related to the presentation (how the informations are displayed). Restricting the possibility to make a reply to the member of a group is a pure “business logic” requirement. You may find few explanations on how it works in the part 5 of the step by step documentation on this site.

    You add the two functions in the functions.php file of your theme.
    In the same file, add the following line, for instance after the two functions or at the end of the file:
    add_filter (‘bbp_current_user_can_publish_replies’, my_bbp_current_user_can_publish_replies, 10);

    This is the way you install filter under WP.

    PS: you can replace the test: if (groups_is_user_admin( $user_id, $groups_id[0])
    || groups_is_user_mod ($user_id, $groups_id[0])
    || groups_is_user_member ($user_id, $groups_id[0]) )

    by this one, which is sufficient for your purpose:
    if ( groups_is_user_member ($user_id, $groups_id[0]) ) return true;


    jyd44
    Participant

    @jyd44

    You are right. Having the same requirement, I was facing the same issue (and you will discover very soon that it is not the only one !).
    As far as I understand, the integration between bbPress and BuddyPress is not fully completed. In bbPress, the user capabilities based on their role in the forums are only mapped to WP capabilities. (see for example the function bbp_current_user_can_publish_replies() or bbp_current_user_can_access_create_reply_form() (invoqued in the form-reply.php part of the bbPress theme) in bbpress/includes/users/template.php .
    My way to overcome this issue is to add my own filter on the ‘bbp_current_user_can_publish_replies’ filter and to check in this function if the current_user is a member of the group associated with the root_forum (the one associated with the group) of the topic currently displayed.

    below my function:

    function my_bbp_current_user_can_publish_replies($input)
    	{
    		$topic_id = bbp_topic_id();
    		$root_forum = alsb_get_post_root_forum($topic_id);
    		$groups_id = bbp_get_forum_group_ids($root_forum);
    		$user_id = get_current_user_id();
    		if (groups_is_user_admin( $user_id, $groups_id[0])
    			|| groups_is_user_mod ($user_id, $groups_id[0]) 
    				|| groups_is_user_member ($user_id, $groups_id[0]) )
    			return true;
    		else return false;
    	}
    
    whith the help function
     	function alsb_get_post_root_forum($post_id)
    	{
    		$post = get_post($post_id);
    		do
    		{
    			$post = get_post($post->post_parent);
    		}while ($post->post_parent != 0);
    		return $post->ID;
    	}
    

    another way is perhaps to setup a filter on the ‘user_has_cap’ WP filter, but I did not test it.
    good luck for your integration !

Viewing 3 replies - 1 through 3 (of 3 total)