Find Answers and Get Support › Forums › Gwangi – PRO Multi-Purpose Membership, Social Network & BuddyPress Community Theme › Theme Customizer › Pages › Extend code snippet to exclude role
- This topic has 4 replies, 2 voices, and was last updated 6 years, 4 months ago by
Themosaurus.
-
AuthorPosts
-
alexParticipant@abourne
- 81 Topics
- 259 Posts
Require extending this code to exclude the role ‘trainee’ in addition to admin.
add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' ); function buddydev_exclude_users_by_role( $args ) { //do not exclude in admin if( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $args; } $excluded = isset( $args['exclude'] )? $args['exclude'] : array(); if( !is_array( $excluded ) ) { $excluded = explode(',', $excluded ); } $role = 'administrator';//change to the role to be excluded $user_ids = get_users( array( 'role' => $role ,'fields'=>'ID') ); $excluded = array_merge( $excluded, $user_ids ); $args['exclude'] = $excluded; return $args; }
Tried extending this part to ‘trainee’ but only broke the site…
Must be doing something wrong. Please help to make proper snippet to exclude ‘trainee’.
$role = ‘administrator’;//change to the role to be excluded
$user_ids = get_users( array( ‘role’ => $role ,’fields’=>’ID’) );November 1, 2018 at 15:49 #3188@themosaurus- 1 Topics
- 1675 Posts
Hi @abourne,
It should work fine if you replace the
'administrator'
value by'author'
or'subscriber'
. The value ‘trainee’ doesn’t exist by default and we’re not sure that it has been properly created or recognized by BuddyPress. Moreover, it seems that your snippet does not work anymore once the AJAX filter values are changed (for instance, from Last Active to Alphabetical). So, it seems this snippet won’t work across the board…Please note that this issue is related with the customization of BuddyPress, not with the use of your theme. As theme authors, the installation, setting or debugging of third party plugins isn’t part of the support we will provide.
To go further, we invite you to ask for more help from the plugin authors and post your request on their support forums:
https://buddypress.org/support/We remain available for all support requests related with the use of your theme.
Regards,
November 1, 2018 at 17:33 #3196alexParticipant@abourne- 81 Topics
- 259 Posts
Thanks for the comment.
“pro” and “trainee” are roles I created.
WP successfully recognises the roles.
I did a test of the snippet using just “pro” and just “administrator”
Both work fine.
Just need to do in conjunction, as I cannot redeclare the function.
Please share thoughts on snippet to extend for ‘two’ role exclusions.
Thanks
November 1, 2018 at 20:14 #3207alexParticipant@abourne- 81 Topics
- 259 Posts
Nevermind, I just figured it out. For you forums reference:
add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users_by_role' ); function buddydev_exclude_users_by_role( $args ) { //do not exclude in admin if( is_admin() && ! defined( 'DOING_AJAX' ) ) { return $args; } $excluded = isset( $args['exclude'] )? $args['exclude'] : array(); if( !is_array( $excluded ) ) { $excluded = explode(',', $excluded ); } //change 'role' to the role to be excluded $user_ids_customer = get_users( array( 'role' => 'administrator' ,'fields'=>'ID') ); $user_ids_admin = get_users( array( 'role' => 'trainee' ,'fields'=>'ID') ); $excluded = array_merge( $excluded, $user_ids_customer, $user_ids_admin ); $args['exclude'] = $excluded; return $args; }
November 1, 2018 at 20:20 #3208 -
AuthorPosts
The topic ‘Extend code snippet to exclude role’ is closed to new replies.