Ticket #8292: 8292-3.patch
File 8292-3.patch, 7.8 KB (added by , 4 years ago) |
---|
-
src/bp-members/bp-members-functions.php
diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php index c55e942c6..7ea06d83b 100644
function bp_set_member_type( $user_id, $member_type, $append = false ) { 3027 3027 return $retval; 3028 3028 } 3029 3029 3030 /** 3031 * Set types for a member. 3032 * 3033 * @since 2.2.0 3034 * 3035 * @param int $user_id ID of the user. 3036 * @param array $member_types Member type. 3037 * @param bool $append Optional. True to append this to existing types for user, 3038 * false to replace. Default: false. 3039 * @return false|array $retval See {@see bp_set_object_terms()}. 3040 */ 3041 function bp_set_member_types( $user_id, $member_types, $append = false ) { 3042 // Pass an empty $member_type to remove a user's type. 3043 if ( ! empty( $member_type ) && ! is_array( $member_types ) ) { 3044 return false; 3045 } 3046 3047 $retval = bp_set_object_terms( $user_id, $member_types, bp_get_member_type_tax_name(), $append ); 3048 3049 // Bust the cache if the type has been updated. 3050 if ( ! is_wp_error( $retval ) ) { 3051 wp_cache_delete( $user_id, 'bp_member_member_types' ); 3052 3053 /** 3054 * Fires just after a user's member type has been changed. 3055 * 3056 * @since 2.2.0 3057 * 3058 * @param int $user_id ID of the user whose member type has been updated. 3059 * @param string $member_type Member type. 3060 * @param bool $append Whether the type is being appended to existing types. 3061 */ 3062 do_action( 'bp_set_member_types', $user_id, $member_types, $append ); 3063 } 3064 3065 return $retval; 3066 } 3067 3030 3068 /** 3031 3069 * Remove type for a member. 3032 3070 * -
src/bp-members/classes/class-bp-members-admin.php
diff --git src/bp-members/classes/class-bp-members-admin.php src/bp-members/classes/class-bp-members-admin.php index d344b5d7c..0503c0c41 100644
class BP_Members_Admin { 1286 1286 return; 1287 1287 } 1288 1288 1289 $types = bp_get_member_types( array(), 'objects' ); 1290 $current_type = bp_get_member_type( $user->ID ); 1291 ?> 1292 1293 <label for="bp-members-profile-member-type" class="screen-reader-text"><?php 1289 $types = bp_get_member_types( array(), 'object' ); 1290 $current_types = bp_get_member_type( $user->ID, false ); 1291 $selected = ''; 1292 ?> 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 1300 <select name="bp-members-profile-member-type[]" id="bp-members-profile-member-type" multiple="multiple"> 1301 <option value=""><?php 1302 1303 /* translators: no option picked in select box */ 1304 esc_attr_e( '----', 'buddypress' ); 1305 ?> 1306 </option> 1302 1307 <?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> 1308 <?php 1309 if ( ! empty( $current_types ) && in_array( $type->name, $current_types ) ) { 1310 $selected = 'selected'; 1311 } else { 1312 $selected = ''; 1313 } 1314 ?> 1315 <option value="<?php echo esc_attr( $type->name ); ?> "<?php echo esc_attr( $selected ); ?>><?php echo esc_html( $type->labels['singular_name'] ); ?></option> 1304 1316 <?php endforeach; ?> 1305 1317 </select> 1306 1307 <?php 1308 1309 wp_nonce_field( 'bp-member-type-change-' . $user->ID, 'bp-member-type-nonce' ); 1310 } 1311 1312 /** 1313 * Process changes from the Member Type metabox. 1314 * 1315 * @since 2.2.0 1316 */ 1317 public function process_member_type_update() { 1318 if ( ! isset( $_POST['bp-member-type-nonce'] ) || ! isset( $_POST['bp-members-profile-member-type'] ) ) { 1319 return; 1318 <?php 1319 wp_nonce_field( 'bp-member-type-change-' . $user->ID, 'bp-member-type-nonce' ); 1320 1320 } 1321 1321 1322 $user_id = $this->get_user_id(); 1322 /** 1323 * Process changes from the Member Type metabox. 1324 * 1325 * @since 2.2.0 1326 */ 1327 public function process_member_type_update() { 1328 if ( ! isset( $_POST['bp-member-type-nonce'] ) || ! isset( $_POST['bp-members-profile-member-type'] ) ) { 1329 return; 1330 } 1323 1331 1324 check_admin_referer( 'bp-member-type-change-' . $user_id, 'bp-member-type-nonce' ); 1332 $user_id = $this->get_user_id(); 1333 $member_types = array(); 1325 1334 1326 // Permission check. 1327 if ( ! bp_current_user_can( 'bp_moderate' ) && $user_id != bp_loggedin_user_id() ) { 1328 return; 1329 } 1335 check_admin_referer( 'bp-member-type-change-' . $user_id, 'bp-member-type-nonce' ); 1330 1336 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 } 1337 // Permission check. 1338 if ( ! bp_current_user_can( 'bp_moderate' ) && $user_id != bp_loggedin_user_id() ) { 1339 return; 1340 } 1341 $member_types = wp_unslash( $_POST['bp-members-profile-member-type'] ); 1342 foreach ( $member_types as $key => $types ) { 1343 // Member type string must either reference a valid member type, or be empty. 1344 $member_type = stripslashes( $types ); 1345 if ( ! empty( $member_type ) && ! bp_get_member_type_object( $member_type ) ) { 1346 return; 1347 } 1336 1348 1337 /* 1338 * If an invalid member type is passed, someone's doing something 1339 * fishy with the POST request, so we can fail silently. 1340 */ 1341 if ( bp_set_member_type( $user_id, $member_type ) ) { 1342 // @todo Success messages can't be posted because other stuff happens on the page load. 1349 $member_types[ $key ] = $member_type; 1350 } 1351 1352 /* 1353 * If an invalid member type is passed, someone's doing something 1354 * fishy with the POST request, so we can fail silently. 1355 */ 1356 if ( bp_set_member_types( $user_id, $member_types ) ) { 1357 // @todo Success messages can't be posted because other stuff happens on the page load. 1358 } 1343 1359 } 1344 }1345 1360 1346 1361 /** 1347 1362 * Add a link to Profile in Users listing row actions. … … class BP_Members_Admin { 2470 2485 * 2471 2486 * @return string Member type as a link to filter all users. 2472 2487 */ 2473 public function users_table_populate_type_cell( $retval = '', $column_name = '', $user_id = 0 ) {2474 // Only looking for member type column.2475 if ( bp_get_member_type_tax_name() !== $column_name ) {2476 return $retval;2477 }2488 public function users_table_populate_type_cell( $retval = '', $column_name = '', $user_id = 0 ) { 2489 // Only looking for member type column. 2490 if ( bp_get_member_type_tax_name() !== $column_name ) { 2491 return $retval; 2492 } 2478 2493 2479 // Get the member type.2480 $type = bp_get_member_type( $user_id);2494 // Get the member type. 2495 $types = bp_get_member_type( $user_id, false ); 2481 2496 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>'; 2486 } 2497 if ( ! empty( $types ) ) { 2487 2498 2488 return $retval; 2489 } 2499 $member_types = ''; 2500 2501 foreach ( $types as $key => $type ) { 2502 if ( $type_obj = bp_get_member_type_object( $type ) ) { 2503 2504 if ( ! empty( $member_types ) ) { 2505 $member_types .= ', '; 2506 } 2507 2508 $url = add_query_arg( array( 'bp-member-type' => urlencode( $type ) ) ); 2509 $member_types .= '<a href="' . esc_url( $url ) . '">' . esc_html( $type_obj->labels['name'] ) . '</a>'; 2510 } 2511 } 2512 2513 if ( ! empty( $member_types ) ) { 2514 $retval .= '<br />' . $member_types; 2515 } 2516 return $retval; 2517 } 2518 } 2490 2519 2491 2520 /** 2492 2521 * Filter WP Admin users list table to include users of the specified type.