Skip to:
Content

BuddyPress.org

Ticket #6125: 6125.02.patch

File 6125.02.patch, 5.3 KB (added by johnjamesjacoby, 10 years ago)
  • src/bp-members/bp-members-admin.php

     
    760760                        );
    761761
    762762                        // Member Type metabox. Only added if member types have been registered.
    763                         $member_types = bp_get_member_types();
    764                         if ( ! empty( $member_types ) ) {
     763                        if ( bp_get_member_types() ) {
    765764                                add_meta_box(
    766765                                        'bp_members_admin_member_type',
    767766                                        _x( 'Member Type', 'members user-admin edit screen', 'buddypress' ),
     
    10901089                        return;
    10911090                }
    10921091
    1093                 $types = bp_get_member_types( array(), 'objects' );
    1094                 $current_type = bp_get_member_type( $user->ID );
    1095                 ?>
     1092                $types        = bp_get_member_types();
     1093                $current_type = bp_get_member_type( $user->ID ); ?>
    10961094
    10971095                <select name="bp-members-profile-member-type">
    10981096                        <option value="" <?php selected( '', $current_type ); ?>><?php /* translators: no option picked in select box */ esc_attr_e( '----', 'buddypress' ) ?></option>
  • src/bp-members/bp-members-functions.php

     
    24792479                'labels' => array(),
    24802480        ), 'register_member_type' );
    24812481
    2482         $type = (object) $r;
    2483 
    24842482        // Store the post type name as data in the object (not just as the array key).
    2485         $type->name = $member_type;
     2483        $r['name'] = $member_type;
    24862484
    24872485        // Make sure the relevant labels have been filled in.
    2488         $default_name = isset( $r['labels']['name'] ) ? $r['labels']['name'] : ucfirst( $type->name );
    2489         $r['labels'] = array_merge( array(
     2486        $default_name = isset( $r['labels']['name'] )
     2487                ? $r['labels']['name']
     2488                : ucfirst( $r['name'] );
     2489
     2490        $r['labels']  = array_merge( array(
    24902491                'name'          => $default_name,
    24912492                'singular_name' => $default_name,
    24922493        ), $r['labels'] );
    24932494
    2494         $bp->members->types[ $member_type ] = $type;
     2495        // Add the member type
     2496        $bp->members->types[ $member_type ] = $type = (object) $r;
    24952497
    24962498        /**
    24972499         * Fires after a member type is registered.
     
    25112513 *
    25122514 * @since BuddyPress (2.2.0)
    25132515 *
    2514  * @param  string $post_type The name of the member type.
     2516 * @param  string $member_type The name of the member type.
    25152517 * @return object A member type object.
    25162518 */
    25172519function bp_get_member_type_object( $member_type ) {
    2518         $types = bp_get_member_types( array(), 'objects' );
     2520        $types = bp_get_member_types();
    25192521
    2520         if ( empty( $types[ $member_type ] ) ) {
     2522        if ( ! isset( $types[ $member_type ] ) ) {
    25212523                return null;
    25222524        }
    25232525
     
    25302532 * @since BuddyPress (2.2.0)
    25312533 *
    25322534 * @see bp_register_member_type() for accepted arguments.
    2533  *
    2534  * @param array|string $args     Optional. An array of key => value arguments to match against
    2535  *                               the member type objects. Default empty array.
    2536  * @param string       $output   Optional. The type of output to return. Accepts 'names'
    2537  *                               or 'objects'. Default 'names'.
    2538  * @param string       $operator Optional. The logical operation to perform. 'or' means only one
    2539  *                               element from the array needs to match; 'and' means all elements
    2540  *                               must match. Accepts 'or' or 'and'. Default 'and'.
    25412535 * @return array A list of member type names or objects.
    25422536 */
    2543 function bp_get_member_types( $args = array(), $output = 'names', $operator = 'and' ) {
     2537function bp_get_member_types() {
     2538
     2539        // Get member types objects
    25442540        $types = buddypress()->members->types;
    25452541
    2546         $field = 'names' == $output ? 'name' : false;
    2547 
    2548         $types = wp_filter_object_list( $types, $args, $operator );
    2549 
    25502542        /**
    25512543         * Filters the array of member type objects.
    25522544         *
    2553          * This filter is run before the $output filter has been applied, so that
    2554          * filtering functions have access to the entire member type objects.
    2555          *
    25562545         * @since BuddyPress (2.2.0)
    25572546         *
    2558          * @param array  $types     Member type objects, keyed by name.
    2559          * @param array  $args      Array of key=>value arguments for filtering.
    2560          * @param string $operator  'or' to match any of $args, 'and' to require all.
     2547         * @param array $types Member type objects, keyed by name.
    25612548         */
    2562         $types = apply_filters( 'bp_get_member_types', $types, $args, $operator );
     2549        return apply_filters( 'bp_get_member_types', $types );
     2550}
    25632551
    2564         if ( 'names' === $output ) {
    2565                 $types = wp_list_pluck( $types, 'name' );
    2566         }
     2552/**
     2553 * Get a filtered list of all registered member type objects.
     2554 *
     2555 * @since BuddyPress (2.2.0)
     2556 *
     2557 * @see bp_register_member_type() for accepted arguments.
     2558 *
     2559 * @param array|string $args     Optional. An array of key => value arguments to match against
     2560 *                               the member type objects. Default empty array.
     2561 * @param string       $operator Optional. The logical operation to perform. 'or' means only one
     2562 *                               element from the array needs to match; 'and' means all elements
     2563 *                               must match. Accepts 'or' or 'and'. Default 'and'.
     2564 * @param string       $field    Optional. The type of output to return. Accepts 'names'
     2565 *                               or 'objects'. Default 'names'.
     2566 * @return array A list of member type names or objects.
     2567 */
     2568function bp_filter_member_types( $args = array(), $operator = 'and', $field = false ) {
     2569        $types = bp_get_member_types();
    25672570
    2568         return $types;
     2571        // Filter type objects based on passed parameters
     2572        return wp_filter_object_list( $types, $args, $operator, $field );       
    25692573}
    25702574
    25712575/**