BuddyPress Members Directory – Member Types by User Role Error
-
I’m adding a tab in member types list on BuddyPress members directory. I want it to filter by user roles. I already tried but there are two big issues. 1. Not working via AJAX. It’s showing 400 error. 2. ‘members-order-by’ filter not working either. It’s loading all user instead of specific roles.
Generated User IDs specific to
subscriber
only:function getSubscriberIds() { $user_ids = get_transient( 'bp_only_subscriber_ids' ); if ( false === $user_ids ) { $args = array( 'role__in' => 'subscriber', 'fields' => 'ID' ); $user_ids = get_users( $args ); set_transient( 'bp_only_subscriber_ids', $user_ids, 12 * HOUR_IN_SECONDS ); } return $user_ids; }
Generated
member_types
tab:function onlySubscribersTab() { $button_args = array( 'id' => 'subscribers', 'component' => 'members', 'link_text' => sprintf( __( 'Subscribers %s', 'buddypress' ), '<span>' . count( getSubscriberIds() ) . '</span>' ), 'link_title' => __( 'Subscribers', 'buddypress' ), 'link_class' => 'subscribers no-ajax', 'link_href' => bp_get_members_directory_permalink() . '?show=subscribers', 'wrapper' => false, 'block_self' => false, 'must_be_logged_in' => false ); ?> <li id="subscribers" <?php if ( isset( $_GET['show'] ) && $_GET['show'] == 'subscribers' ) { ?> class="current" <?php } ?>><?php echo bp_get_button( $button_args ); ?></li> <?php } add_action( 'bp_members_directory_member_types', 'onlySubscribersTab' );
And then filtered only
subscribers
:function filterSubscribers( $r ) { if( isset( $_GET['show'] ) && $_GET['show'] == 'subscribers' ) { $user_ids = $this->getUsersIds(); if( $user_ids ) { $r['include'] = $user_ids; } } return $r; } add_filter( 'bp_after_core_get_users_parse_args', 'filterSubscribers' );
Now, it’s working but not as I expected. I want to to work through AJAX. I removed
no-ajax
from button class but not working. It’s showing 400 error. Andmembers-order-by
filters not working either. When I change the filter, it’s showing all user instead of subscribers.Can you help me?
Thanks in advance 🙂
- You must be logged in to reply to this topic.