BuddyDev

Search

hide mediapress for simple users

  • Participant
    Level: Initiated
    Posts: 4
    Luigi on #21060

    hi,
    i want to hide mediapress from profile only for simple users

    how can i do?

  • Keymaster
    (BuddyDev Team)
    Posts: 21796
    Brajesh Singh on #21087

    Hi Luigi,
    Welcome to BuddyDev.

    Please define simple users. Is it users with ‘subscriber’ role?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 4
    Luigi on #21090

    yeah, like customers.

    i got multiple custom users role but i need to hide the media gallery only for simple users, the lowest level, the customer or the subscriber.

    thank you!

  • Keymaster
    (BuddyDev Team)
    Posts: 21796
    Brajesh Singh on #21106

    Please use the following

    
    
    /**
     * Check if a user has given WordPress role(or any of the roles).
     *
     * @param int           $user_id user.
     * @param string|array  $role role(s).
     *
     * @return bool|array
     */
    function buddydev_user_has_role( $user_id, $role ) {
    	$user   = get_user_by( 'id', $user_id );
    
    	if ( empty( $user ) ) {
    		return false;
    	}
    
    	$user_roles = $user->roles;
    
    	if ( empty( $user_roles ) ) {
    		return false;
    	}
    	// if an array o roles was given.
    	return is_array( $role) ? array_intersect( $role, $user_roles ) : in_array( $role, $user_roles, true );
    }
    
    /**
     * Only allow galleries for a certain role.
     *
     * @param bool   $is_active Can create gallery or not.
     * @param string $component Component name.
     * @param int    $component_id Component id.
     *
     * @return bool
     */
    function buddydev_disable_gallery_for_roles( $is_active, $component, $component_id ) {
    
    	if ( 'members' !== $component ) {
    		return $is_active;
    	}
    
    	$restricted_roles = array( 'subscriber', 'contributor' );// 'editor', 'contributor', 'subscriber'
    
    	if ( buddydev_user_has_role( $component_id, $restricted_roles ) ) {
    		$is_active = false;
    	}
    
    	return $is_active;
    }
    add_filter( 'mpp_is_enabled', 'buddydev_disable_gallery_for_roles', 10, 3 );
    
    

    Please feel free to modify the roles list.

    Let me know if it works for you or not?

    PS:- The code should go to wp-content/plugins/bp-custom.php

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 4
    Luigi on #21130

    there’s not that file in the folder

    eidt. IT WORKED!!! I put it on wp-content/plugins/buddypress/class-buddypress.php

    is it good?

    • This reply was modified 3 years, 7 months ago by Luigi.
  • Keymaster
    (BuddyDev Team)
    Posts: 21796
    Brajesh Singh on #21134

    Hi Luigi,
    Thank you.
    If it is not there, Please create a php file. You can use the following(start with php tag)
    https://gist.github.com/sbrajesh/55639df69806b564a9765562a4f40e37

    as the starting template. Also, Please make sure to remove the code from class-buddypress.php, It should not be modified as the next update of BuddyPress will overwrite it.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved