Changeset 11139 for trunk/src/bp-groups/bp-groups-admin.php
- Timestamp:
- 09/21/2016 04:57:45 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-admin.php
r11091 r11139 1225 1225 } 1226 1226 add_action( 'wp_ajax_bp_group_admin_member_autocomplete', 'bp_groups_admin_autocomplete_handler' ); 1227 1228 /** 1229 * Process input from the Group Type bulk change select. 1230 * 1231 * @since 2.7.0 1232 * 1233 * @param string $doaction Current $_GET action being performed in admin screen. 1234 */ 1235 function bp_groups_admin_process_group_type_bulk_changes( $doaction ) { 1236 // Bail if no groups are specified or if this isn't a relevant action. 1237 if ( empty( $_REQUEST['gid'] ) 1238 || ( empty( $_REQUEST['bp_change_type'] ) && empty( $_REQUEST['bp_change_type2'] ) ) 1239 || empty( $_REQUEST['bp_change_group_type'] ) 1240 ) { 1241 return; 1242 } 1243 1244 // Bail if nonce check fails. 1245 check_admin_referer( 'bp-bulk-groups-change-type-' . bp_loggedin_user_id(), 'bp-bulk-groups-change-type-nonce' ); 1246 1247 if ( ! bp_current_user_can( 'bp_moderate' ) ) { 1248 return; 1249 } 1250 1251 $new_type = ''; 1252 if ( ! empty( $_REQUEST['bp_change_type2'] ) ) { 1253 $new_type = sanitize_text_field( $_REQUEST['bp_change_type2'] ); 1254 } elseif ( ! empty( $_REQUEST['bp_change_type'] ) ) { 1255 $new_type = sanitize_text_field( $_REQUEST['bp_change_type'] ); 1256 } 1257 1258 // Check that the selected type actually exists. 1259 if ( 'remove_group_type' !== $new_type && null === bp_groups_get_group_type_object( $new_type ) ) { 1260 $error = true; 1261 } else { 1262 // Run through group ids. 1263 $error = false; 1264 foreach ( (array) $_REQUEST['gid'] as $group_id ) { 1265 $group_id = (int) $group_id; 1266 1267 // Get the old group type to check against. 1268 $group_type = bp_groups_get_group_type( $group_id ); 1269 1270 if ( 'remove_group_type' === $new_type ) { 1271 // Remove the current group type, if there's one to remove. 1272 if ( $group_type ) { 1273 $removed = bp_groups_remove_group_type( $group_id, $group_type ); 1274 if ( false === $removed || is_wp_error( $removed ) ) { 1275 $error = true; 1276 } 1277 } 1278 } else { 1279 // Set the new group type. 1280 if ( $new_type !== $group_type ) { 1281 $set = bp_groups_set_group_type( $group_id, $new_type ); 1282 if ( false === $set || is_wp_error( $set ) ) { 1283 $error = true; 1284 } 1285 } 1286 } 1287 } 1288 } 1289 1290 // If there were any errors, show the error message. 1291 if ( $error ) { 1292 $redirect = add_query_arg( array( 'updated' => 'group-type-change-error' ), wp_get_referer() ); 1293 } else { 1294 $redirect = add_query_arg( array( 'updated' => 'group-type-change-success' ), wp_get_referer() ); 1295 } 1296 1297 wp_redirect( $redirect ); 1298 exit(); 1299 } 1300 add_action( 'bp_groups_admin_load', 'bp_groups_admin_process_group_type_bulk_changes' ); 1301 1302 /** 1303 * Display an admin notice upon group type bulk update. 1304 * 1305 * @since 2.7.0 1306 */ 1307 function bp_groups_admin_groups_type_change_notice() { 1308 $updated = isset( $_REQUEST['updated'] ) ? $_REQUEST['updated'] : false; 1309 1310 // Display feedback. 1311 if ( $updated && in_array( $updated, array( 'group-type-change-error', 'group-type-change-success' ), true ) ) { 1312 1313 if ( 'group-type-change-error' === $updated ) { 1314 $notice = __( 'There was an error while changing group type. Please try again.', 'buddypress' ); 1315 $type = 'error'; 1316 } else { 1317 $notice = __( 'Group type was changed successfully.', 'buddypress' ); 1318 $type = 'updated'; 1319 } 1320 1321 bp_core_add_admin_notice( $notice, $type ); 1322 } 1323 } 1324 add_action( bp_core_admin_hook(), 'bp_groups_admin_groups_type_change_notice' );
Note: See TracChangeset
for help on using the changeset viewer.