Changeset 12517 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php
- Timestamp:
- 03/30/2023 03:37:47 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php
r12507 r12517 31 31 add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) ); 32 32 33 add_action( 'load-edit.php', array( $this, 'bulk_ reject_plugins' ) );33 add_action( 'load-edit.php', array( $this, 'bulk_action_plugins' ) ); 34 34 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); 35 35 add_filter( 'admin_head-edit.php', array( $this, 'plugin_posts_list_table' ) ); … … 229 229 230 230 /** 231 * Rejects plugins in bulk. 232 */ 233 public function bulk_reject_plugins() { 234 if ( empty( $_REQUEST['action'] ) || empty( $_REQUEST['action2'] ) || ! in_array( 'plugin_reject', array( $_REQUEST['action'], $_REQUEST['action2'] ) ) || 'plugin' !== $_REQUEST['post_type'] ) { 231 * Performs plugin status changes in bulk. 232 */ 233 public function bulk_action_plugins() { 234 if ( 235 empty( $_REQUEST['action'] ) || 236 empty( $_REQUEST['action2'] ) || 237 'plugin' !== $_REQUEST['post_type'] 238 ) { 235 239 return; 236 240 } … … 238 242 check_admin_referer( 'bulk-posts' ); 239 243 240 $rejected = 0; 244 $action = array_intersect( 245 [ 'plugin_open', 'plugin_close', 'plugin_disable', 'plugin_reject' ], 246 [ $_REQUEST['action'], $_REQUEST['action2'] ] 247 ); 248 $action = array_shift( $action ); 249 if ( ! $action ) { 250 return; 251 } 252 253 switch( $action ) { 254 case 'plugin_open': 255 $capability = 'plugin_approve'; 256 $new_status = 'publish'; 257 $message = _n_noop( '%s plugin opened.', '%s plugins opened.', 'wporg-plugins' ); 258 $from_state = [ 'closed', 'disabled' ]; 259 break; 260 case 'plugin_close': 261 $capability = 'plugin_close'; 262 $new_status = 'closed'; 263 $message = _n_noop( '%s plugin closed.', '%s plugins closed.', 'wporg-plugins' ); 264 $from_state = [ 'closed', 'disabled', 'publish', 'approved' ]; 265 break; 266 case 'plugin_disable': 267 $capability = 'plugin_close'; 268 $new_status = 'disabled'; 269 $message = _n_noop( '%s plugin disabled.', '%s plugins disabled.', 'wporg-plugins' ); 270 $from_state = [ 'closed', 'disabled', 'publish', 'approved' ]; 271 break; 272 case 'plugin_reject': 273 $capability = 'plugin_reject'; 274 $new_status = 'rejected'; 275 $message = _n_noop( '%s plugin rejected.', '%s plugins rejected.', 'wporg-plugins' ); 276 $from_state = [ 'new', 'pending' ]; 277 break; 278 default: 279 return; 280 } 281 282 $closed = 0; 241 283 $plugins = get_posts( array( 242 284 'post_type' => 'plugin', 243 285 'post__in' => array_map( 'absint', $_REQUEST['post'] ), 244 'post_status' => array( 'new', 'pending' ),286 'post_status' => $from_state, 245 287 'posts_per_page' => count( $_REQUEST['post'] ), 246 288 ) ); 247 289 248 290 foreach ( $plugins as $plugin ) { 249 if ( ! current_user_can( 'plugin_reject', $plugin ) ) {250 wp_die( __( 'You are not allowed to reject this plugin.', 'wporg-plugins' ), '', array( 'back_link' => true ) );291 if ( ! current_user_can( $capability, $plugin ) ) { 292 continue; 251 293 } 252 294 253 295 $updated = wp_update_post( array( 254 296 'ID' => $plugin->ID, 255 'post_status' => 'rejected',297 'post_status' => $new_status, 256 298 ) ); 257 299 258 300 if ( $updated && ! is_wp_error( $updated ) ) { 259 $rejected++; 260 } 261 } 262 263 if ( $rejected ) { 264 set_transient( 'settings_errors', array( 265 array( 266 'setting' => 'wporg-plugins', 267 'code' => 'plugins-bulk-rejected', 268 'message' => sprintf( _n( '%d plugin rejected.', '%d plugins rejected.', $rejected, 'wporg-plugins' ), $rejected ), 269 'type' => 'updated', 270 ), 271 ) ); 272 } 301 $closed++; 302 } 303 304 } 305 306 set_transient( 'settings_errors', array( 307 array( 308 'setting' => 'wporg-plugins', 309 'code' => 'plugins-bulk-actioned', 310 'message' => sprintf( translate_nooped_plural( $message, $closed, 'wporg-plugins' ), number_format_i18n( $closed ) ), 311 'type' => 'updated', 312 ), 313 ) ); 273 314 274 315 $send_back = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'locked', 'ids', 'action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view' ), wp_get_referer() ); 275 wp_ redirect( add_query_arg( array( 'settings-updated' => true ), $send_back ) );316 wp_safe_redirect( add_query_arg( array( 'settings-updated' => true ), $send_back ) ); 276 317 exit; 277 318 }
Note: See TracChangeset
for help on using the changeset viewer.