Skip to content

Instantly share code, notes, and snippets.

@sbrajesh
Created August 8, 2023 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbrajesh/3026e51bd9ee09a547c7bbe53c2f5925 to your computer and use it in GitHub Desktop.
Save sbrajesh/3026e51bd9ee09a547c7bbe53c2f5925 to your computer and use it in GitHub Desktop.
custom sorting BuddyPress member types in the member type field by their creation order in member types pro
// custom sorting of member types on registration page
// by the creation order in member types pro plugin.
add_filter( 'bp_xprofile_member_type_field_allowed_types', function ( $member_types, $registered_types ) {
if ( empty( $member_types ) || ! function_exists( 'bpmtp_get_active_member_type_entries' ) ) {
return $member_types;
}
// find all our active types(Member Types Pro plugin)
$active_type_objects = bpmtp_get_active_member_type_entries();
// sort by post_id(it is similar to creation order)
$active_type_objects = wp_list_sort( $active_type_objects, 'post_id', 'ASC', true );
$active_keys = array_keys( $active_type_objects );
return array_replace( array_flip( $active_keys ), $member_types );
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment