Changeset 12517
- Timestamp:
- 03/30/2023 03:37:47 AM (2 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin
- Files:
-
- 3 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 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php
r12175 r12517 323 323 */ 324 324 public function save_close_reason( $post_id ) { 325 if ( ! isset( $_ POST['close_reason'] ) ) {325 if ( ! isset( $_REQUEST['close_reason'] ) ) { 326 326 return; 327 327 } … … 331 331 } 332 332 333 $close_reason = sanitize_key( $_ POST['close_reason'] );333 $close_reason = sanitize_key( $_REQUEST['close_reason'] ); 334 334 335 335 update_post_meta( $post_id, '_close_reason', $close_reason ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php
r12325 r12517 81 81 if ( current_user_can( 'plugin_reject' ) && ( empty( $_REQUEST['post_status'] ) || in_array( $_REQUEST['post_status'], array( 'new', 'pending' ) ) ) ) { 82 82 $actions['plugin_reject'] = __( 'Reject', 'wporg-plugins' ); 83 } 84 85 if ( current_user_can( 'plugin_approve' ) && ( empty( $_REQUEST['post_status'] ) || in_array( $_REQUEST['post_status'], array( 'closed', 'disabled' ) ) ) ) { 86 $actions['plugin_open'] = __( 'Open', 'wporg-plugins' ); 87 } 88 89 if ( current_user_can( 'plugin_close' ) && ( empty( $_REQUEST['post_status'] ) || in_array( $_REQUEST['post_status'], array( 'publish', 'approved', 'disabled' ) ) ) ) { 90 $actions['plugin_close'] = __( 'Close', 'wporg-plugins' ); 91 } 92 93 if ( current_user_can( 'plugin_close' ) && ( empty( $_REQUEST['post_status'] ) || in_array( $_REQUEST['post_status'], array( 'publish', 'approved', 'closed' ) ) ) ) { 94 $actions['plugin_disable'] = __( 'Disable', 'wporg-plugins' ); 83 95 } 84 96 … … 500 512 return $status_links; 501 513 } 514 515 /** 516 * Display the "actions" fields below the filters. 517 */ 518 public function extra_tablenav( $which ) { 519 parent::extra_tablenav( $which ); 520 521 // TODO: This shouldn't have inline CSS/JS. 522 523 if ( 'top' === $which ) { 524 ?> 525 <fieldset class="alignleft actions hide-if-js bulk-plugin_close bulk-plugin_disable" disabled="disabled"> 526 <select name="close_reason" id="close_reason"> 527 <option disabled="disabled" value='' selected="selected"><?php esc_html_e( 'Close/Disable Reason:', 'wporg-plugins' ); ?></option> 528 <?php foreach ( Template::get_close_reasons() as $key => $label ) : ?> 529 <option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $label ); ?></option> 530 <?php endforeach; ?> 531 </select> 532 </fieldset> 533 <style> 534 #posts-filter fieldset.bulk-plugin_close { 535 margin: 0; 536 } 537 </style> 538 <script> 539 jQuery( function( $ ) { 540 $( '.bulkactions' ).on( 'change', function() { 541 var $this = $( this ), 542 val = $this.find(':selected').val(), 543 $tablenav = $this.parents('form').find( '.tablenav.top' ); 544 545 $tablenav.find( '.actions.bulk-plugin_close, .actions.bulk-plugin_disable' ).prop( 'disabled', true ).hide(); 546 $tablenav.find( '.actions.bulk-' + val ).prop( 'disabled', false ).show(); 547 } ); 548 } ); 549 </script> 550 <?php 551 } 552 } 502 553 }
Note: See TracChangeset
for help on using the changeset viewer.