Changeset 12765 for trunk/src/bp-members/classes/class-bp-members-admin.php
- Timestamp:
- 10/24/2020 12:20:39 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-members/classes/class-bp-members-admin.php
r12725 r12765 1287 1287 } 1288 1288 1289 $types = bp_get_member_types( array(), 'objects' );1290 $current_type = bp_get_member_type( $user->ID );1289 $types = bp_get_member_types( array(), 'objects' ); 1290 $current_type = bp_get_member_type( $user->ID, false ); 1291 1291 ?> 1292 1292 1293 <label for="bp-members-profile-member-type" class="screen-reader-text"><?php 1293 <label for="bp-members-profile-member-type" class="screen-reader-text"> 1294 <?php 1294 1295 /* translators: accessibility text */ 1295 1296 esc_html_e( 'Select member type', 'buddypress' ); 1296 ?></label> 1297 <select name="bp-members-profile-member-type" id="bp-members-profile-member-type"> 1298 <option value="" <?php selected( '', $current_type ); ?>><?php 1299 /* translators: no option picked in select box */ 1300 esc_attr_e( '----', 'buddypress' ); 1301 ?></option> 1297 ?> 1298 </label> 1299 <select name="bp-members-profile-member-type[]" id="bp-members-profile-member-type" multiple="multiple"> 1300 <option value="" <?php selected( ! $current_type ); ?>> 1301 <?php 1302 /* translators: no option picked in select box */ 1303 esc_attr_e( '----', 'buddypress' ); 1304 ?> 1305 </option> 1302 1306 <?php foreach ( $types as $type ) : ?> 1303 <option value="<?php echo esc_attr( $type->name ) ?>" <?php selected( $type->name, $current_type) ?>><?php echo esc_html( $type->labels['singular_name'] ) ?></option>1307 <option value="<?php echo esc_attr( $type->name ) ?>" <?php selected( in_array( $type->name, (array) $current_type, true ) ) ?>><?php echo esc_html( $type->labels['singular_name'] ) ?></option> 1304 1308 <?php endforeach; ?> 1305 1309 </select> 1306 1310 1307 1311 <?php 1308 1309 1312 wp_nonce_field( 'bp-member-type-change-' . $user->ID, 'bp-member-type-nonce' ); 1310 1313 } … … 1329 1332 } 1330 1333 1331 // Member type string must either reference a valid member type, or be empty. 1332 $member_type = stripslashes( $_POST['bp-members-profile-member-type'] ); 1333 if ( ! empty( $member_type ) && ! bp_get_member_type_object( $member_type ) ) { 1334 return; 1335 } 1334 // Member type [string] must either reference a valid member type, or be empty. 1335 $member_type = wp_parse_slug_list( wp_unslash( $_POST['bp-members-profile-member-type'] ) ); 1336 $member_type = array_filter( $member_type ); 1336 1337 1337 1338 /* … … 2388 2389 $user_id = (int) $user_id; 2389 2390 2390 // Get the old member type to check against. 2391 $member_type = bp_get_member_type( $user_id ); 2392 2393 if ( 'remove_member_type' === $new_type ) { 2394 // Remove the current member type, if there's one to remove. 2395 if ( $member_type ) { 2396 $removed = bp_remove_member_type( $user_id, $member_type ); 2397 if ( false === $removed || is_wp_error( $removed ) ) { 2398 $error = true; 2399 } 2391 // Get the old member types to check against. 2392 $current_types = bp_get_member_type( $user_id, false ); 2393 2394 if ( $current_types && 'remove_member_type' === $new_type ) { 2395 $member_types = array(); 2396 } elseif ( ! $current_types || 1 !== count( $current_types ) || $new_type !== $current_types[0] ) { 2397 // Set the new member type. 2398 $member_types = array( $new_type ); 2399 } 2400 2401 if ( isset( $member_types ) ) { 2402 $set = bp_set_member_type( $user_id, $member_types ); 2403 if ( false === $set || is_wp_error( $set ) ) { 2404 $error = true; 2400 2405 } 2401 } else { 2402 // Set the new member type. 2403 if ( $new_type !== $member_type ) { 2404 $set = bp_set_member_type( $user_id, $new_type ); 2405 if ( false === $set || is_wp_error( $set ) ) { 2406 $error = true; 2407 } 2408 } 2406 unset( $member_types ); 2409 2407 } 2410 2408 } … … 2478 2476 2479 2477 // Get the member type. 2480 $type = bp_get_member_type( $user_id ); 2481 2482 // Output the 2483 if ( $type_obj = bp_get_member_type_object( $type ) ) { 2484 $url = add_query_arg( array( 'bp-member-type' => urlencode( $type ) ) ); 2485 $retval = '<a href="' . esc_url( $url ) . '">' . esc_html( $type_obj->labels['singular_name'] ) . '</a>'; 2478 $member_type = bp_get_member_type( $user_id, false ); 2479 2480 // Build the Output. 2481 if ( $member_type ) { 2482 $member_types = array_filter( array_map( 'bp_get_member_type_object', $member_type ) ); 2483 if ( ! $member_types ) { 2484 return $retval; 2485 } 2486 2487 $type_links = array(); 2488 foreach ( $member_types as $type ) { 2489 $url = add_query_arg( array( 'bp-member-type' => urlencode( $type->name ) ) ); 2490 $type_links[] = sprintf( 2491 '<a href="%1$s">%2$s</a>', 2492 esc_url( $url ), 2493 esc_html( $type->labels['singular_name'] ) 2494 ); 2495 } 2496 2497 $retval = implode( ', ', $type_links ); 2486 2498 } 2487 2499
Note: See TracChangeset
for help on using the changeset viewer.