Skip to:
Content
Pages
Categories
Search
Top
Bottom

Role access and stop ‘request access’ button


  • welshlamb10
    Participant

    @welshlamb10

    Hello,

    I have the below snippet working to stop displaying the ‘request access’ button to the WP role ‘y_member’.

    How do I also make it so that those with the role ‘e_member’ also do not see the ‘request access’ button? I would also like it that if a user is already a member of the group that they can access the group – as this seems to stop users accessing the group.

    I have tried:
    if ( in_array( 'y_member' || 'e_member', (array) $current_user->roles )) {
    This did not work.

    // Remove Join/Leave Button
    function bp_remove_group_join_button( $button, $group ) {
        $current_user = wp_get_current_user();
        if ( in_array( 'y_member', (array) $current_user->roles )) {
            return '';
        }
        return $button;
    }
    add_filter( 'bp_get_group_join_button', 'bp_remove_group_join_button', 10, 2);

    Thanks for the help

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

  • clickallco
    Participant

    @clickallco

    Try this for an easier overview.

    function bp_remove_group_join_button( $button, $group ) {
    	$user = wp_get_current_user();
    	$banned_roles = array(
    		'y_member',
    		'e_member',
                    // add as many member types as you want
    	);
    	if (array_intersect($banned_roles, $user->roles)) {
            return '';
        }
        return $button;
    }
    add_filter( 'bp_get_group_join_button', 'bp_remove_group_join_button', 10, 2);

    welshlamb10
    Participant

    @welshlamb10

    Thank you that helped

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