Created
August 8, 2023 09:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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