Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

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

  • mikeboltonca
    Participant

    @mikeboltonca

    Hey Torben,

    I’m glad to hear this is helpful for you!

    Sorry I don’t have any refinements to give you–I moved on to another company a couple of years ago.

    Best of luck with your project!

    Mike


    mikeboltonca
    Participant

    @mikeboltonca

    Sorry for the delay in replying, @binaryfabric. I just happened to notice your message in my spam folder.

    I didn’t make any more progress with that problem, unfortunately. I’ve also changed jobs and don’t manage that project anymore. Good luck to you!


    mikeboltonca
    Participant

    @mikeboltonca

    I’ve submitted an enhancement Trac here: https://buddypress.trac.wordpress.org/ticket/7489#ticket.

    In the meantime, I’ve implemented the following hack to allow non-members to post on a group’s activity stream:
    In /plugins/buddypress/bp-groups/bp-groups-functions.php, comment out lines 1215 and 1216.

    Original:

    if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) )
    	return false;

    Hacked:

    //if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) )
    	//return false;

    This removes the check for “Is this an admin or a group member?”, allowing anyone to post.


    mikeboltonca
    Participant

    @mikeboltonca

    Shane, I wonder if you can help me stitch together the sequence of events between clicking “Post” on the “What’s new?” form and the moment that groups_is_user_member() is called.

    I’m wondering if there might be an intermediary step I could modify so it doesn’t perform the member check in this particular case.

    I still need groups_is_user_member() intact to keep non-managers out of the Management group, so hacking that function directly (or filtering it across the board) won’t do the job for me.

    Thanks again for your insight. BuddyPress is a gloriously complex system, and it takes a long time to reverse-engineer it by reading docs and looking through the files.


    mikeboltonca
    Participant

    @mikeboltonca

    Thanks for the quick reply, Shane.

    At least I know exactly what obstacle I’m dealing with now. That simplifies my options a lot.

    I might submit an enhancement ticket. It may be denied under the assumption that the filter hook wouldn’t be valuable to enough people, it’s certainly worth a shot.

    I really appreciate your insight. You’ve just saved me a lot of time!


    mikeboltonca
    Participant

    @mikeboltonca

    Hi Slava,

    I tested that code and got no visible effect, but I think we’re in the right territory here.
    I explored both of these functions:

    bp_group_is_member()
    groups_is_user_member()

    It helped me realize that the two specific problems I wanted to solve were as follows:
    – Users can’t create topics in a BuddyPress group’s forum unless they join the group
    – Users can’t reply to topic in a BuddyPress group’s forum unless they join the group

    So I started on the page template itself (form-topic.php).
    Before displaying the “Create a topic” form, the template does a check to see if the user is allowed to create topics:
    if ( bbp_current_user_can_access_create_topic_form() ) : ?
    This was coming back as false, so I checked through each possible path through the function.

    Here’s the whole function for quick reference:

    function bbp_current_user_can_access_create_topic_form() {
    
    	// Users need to earn access
    	$retval = false;
    
    	// Always allow keymasters
    	if ( bbp_is_user_keymaster() ) {
    		$retval = true;
    
    	// Looking at a single forum & forum is open
    	} elseif ( ( bbp_is_single_forum() || is_page() || is_single() ) && bbp_is_forum_open() ) {
    		$retval = bbp_current_user_can_publish_topics();
    
    	// User can edit this topic
    	} elseif ( bbp_is_topic_edit() ) {
    		$retval = current_user_can( 'edit_topic', bbp_get_topic_id() );
    	}
    
    	// Allow access to be filtered
    	return (bool) apply_filters( 'bbp_current_user_can_access_create_topic_form', (bool) $retval );
    }

    Every single path through that function was returning true.
    If I removed the filter and replaced it with a hard-coded true as follows…
    return (bool) true;
    …then the user would have access to the group’s forum without joining the group.

    That told me that something in BuddyPress was filtering the result of this function. It was checking whether the user was a member of the group, and if not, was forcing bbp_current_user_can_access_create_topic_form() to return 0.

    I couldn’t find the portion of BuddyPress that was filtering the result, unfortunately.

    I have a working solution now, but it’s not elegant. I created a plugin with two filters (one for creating topics, one for replying to topics). The content of those filters is identical to the original bbPress functions. Since the plugin is loaded last, it basically overrides whatever BuddyPress says and goes with the original functions instead.

    Here it is:

    /**************************************************
    Part 1: Allow users to create topics
    Allow anyone to create a topic in any forum, even if that forum is inside a group the user hasn't joined.
    If the group is hidden (e.g. "Management"), they still won't have access because that check is done first.
    ***************************************************/
    // define the bbp_current_user_can_access_create_topic_form callback
    function filter_bbp_current_user_can_access_create_topic_form( $retval ) {
    	// Users need to earn access
    	$retval = false;
    
    	// Always allow keymasters
    	if ( bbp_is_user_keymaster() ) {
    		$retval = true;
    
    	// Looking at a single forum & forum is open
    	} elseif ( ( bbp_is_single_forum() || is_page() || is_single() ) && bbp_is_forum_open() ) {
    		$retval = bbp_current_user_can_publish_topics();
    
    	// User can edit this topic
    	} elseif ( bbp_is_topic_edit() ) {
    		$retval = current_user_can( 'edit_topic', bbp_get_topic_id() );
    	}
    return (bool) $retval;
    };
    
    // add the filter
    add_filter( 'bbp_current_user_can_access_create_topic_form', 'filter_bbp_current_user_can_access_create_topic_form', 999, 1 );
    
    /**************************************************
    Part 2: Reply to comments
    Allow anyone to reply to a comment in any forum, even if that forum is inside a group the user hasn't joined.
    If the group is hidden (e.g. "Management"), they still won't have access because that check is done first.
    ***************************************************/
    function filter_bbp_current_user_can_access_create_reply_form( $retval ) {
    
    	// Users need to earn access
    	$retval = false;
    
    	// Always allow keymasters
    	if ( bbp_is_user_keymaster() ) {
    		$retval = true;
    
    	// Looking at a single topic, topic is open, and forum is open
    	} elseif ( ( bbp_is_single_topic() || is_page() || is_single() ) && bbp_is_topic_open() && bbp_is_forum_open() ) {
    		$retval = bbp_current_user_can_publish_replies();
    
    	// User can edit this topic
    	} elseif ( bbp_is_reply_edit() ) {
    		$retval = current_user_can( 'edit_reply', bbp_get_reply_id() );
    	}
    
    return (bool) $retval;
    };
    // add the filter
    add_filter( 'bbp_current_user_can_access_create_reply_form', 'filter_bbp_current_user_can_access_create_reply_form', 999, 1 );

    If I can find where BuddyPress filters bbp_current_user_can_access_create_topic_form() and bbp_current_user_can_access_create_reply_form(), I’ll write a more elegant plugin.


    mikeboltonca
    Participant

    @mikeboltonca

    Hi Slava,
    Thanks for sharing your idea!

    Unfortunately, this approach won’t work for two reasons:

    • Since this is a corporate intranet, the user base is pre-existing and linked to our Active Directory staff list, so there are no “new user sign-ups” to trigger a solution
    • The groups are used to see who’s in a particular department or location; if everyone is a member of every group, the group’s member list won’t be meaningful.

    I really appreciate your attempt!

Viewing 7 replies - 1 through 7 (of 7 total)
Skip to toolbar