Skip to content

Instantly share code, notes, and snippets.

@imath
Created June 13, 2018 12:26
Show Gist options
  • Save imath/b7426f9108ad870bfee3afe7eb06b4ab to your computer and use it in GitHub Desktop.
Save imath/b7426f9108ad870bfee3afe7eb06b4ab to your computer and use it in GitHub Desktop.
Alternative BuddyPress members directory
<?php
/**
* BuddyPress custom functions to add an alternative Members directory using a Shortcode.
*
* Create a new WordPress Page, then write & save this shortcode [buddypress_members_sc] in it.
*/
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
function buddypress_return_members() {
return 'members';
}
function buddypress_handle_sc( $atts = array() ) {
add_filter( 'bp_current_component', 'buddypress_return_members' );
add_filter( 'bp_is_current_component', '__return_true' );
add_filter( 'bp_is_directory', '__return_true' );
if ( 'nouveau' === bp_get_theme_compat_id() ) {
$bp_nouveau = bp_nouveau();
// Set Up Nav.
$bp_nouveau->setup_directory_nav();
// Buffer the Members directory
$members = $bp_nouveau->theme_compat_wrapper( bp_buffer_template_part(
'members/index',
null,
false
) );
} else {
$members = bp_buffer_template_part(
'members/index',
null,
false
);
}
remove_filter( 'bp_current_component', 'buddypress_return_members' );
remove_filter( 'bp_is_current_component', '__return_true' );
remove_filter( 'bp_is_directory', '__return_true' );
return $members;
}
add_shortcode( 'buddypress_members_sc', 'buddypress_handle_sc' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment