Ticket #2796: 2796.3.patch
File 2796.3.patch, 11.5 KB (added by , 7 years ago) |
---|
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php
32 32 add_action( 'load-edit.php', array( $this, 'bulk_reject_plugins' ) ); 33 33 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); 34 34 add_filter( 'admin_head-edit.php', array( $this, 'plugin_posts_list_table' ) ); 35 add_filter( 'post_row_actions', array( $this, 'plugin_row_actions' ) ); 35 36 add_action( 'edit_form_top', array( $this, 'show_permalink' ) ); 36 37 add_action( 'admin_notices', array( $this, 'add_post_status_notice' ) ); 37 38 add_action( 'all_admin_notices', array( $this, 'admin_notices' ) ); … … 111 112 wp_enqueue_style( 'plugin-admin-post-css', plugins_url( 'css/edit-form.css', Plugin_Directory\PLUGIN_FILE ), array( 'edit' ), 4 ); 112 113 wp_enqueue_script( 'plugin-admin-post-js', plugins_url( 'js/edit-form.js', Plugin_Directory\PLUGIN_FILE ), array( 'wp-util', 'wp-lists' ), 3 ); 113 114 wp_localize_script( 'plugin-admin-post-js', 'pluginDirectory', array( 115 'approvePluginAYS' => __( 'Are you sure you want to approve this plugin?', 'wporg-plugins' ), 116 'rejectPluginAYS' => __( 'Are you sure you want to reject this plugin?', 'wporg-plugins' ), 114 117 'removeCommitterAYS' => __( 'Are you sure you want to remove this committer?', 'wporg-plugins' ), 115 118 ) ); 116 119 break; … … 162 165 } 163 166 164 167 /** 168 * Disables Quick Edit for plugins. 169 * 170 * @param array $actions An array of row action links. 171 * @return array Filtered array of row action links. 172 */ 173 public function plugin_row_actions( $actions ) { 174 global $post_type; 175 176 if ( 'plugin' === $post_type ) { 177 unset( $actions['inline hide-if-no-js'] ); 178 } 179 180 return $actions; 181 } 182 183 /** 165 184 * Rejects plugins in bulk. 166 185 */ 167 186 public function bulk_reject_plugins() { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php
31 31 } 32 32 33 33 /** 34 * Get the list of allowed status transitions for a given plugin. 35 * 36 * @param string $post_status Plugin post status. 37 * @return array An array of allowed post status transitions. 38 */ 39 public static function get_allowed_transitions( $post_status ) { 40 switch ( $post_status ) { 41 case 'new': 42 $transitions = array( 'pending', 'approved', 'rejected' ); 43 break; 44 case 'pending': 45 $transitions = array( 'approved', 'rejected' ); 46 break; 47 case 'approved': 48 // Plugins move from 'approved' to 'publish' on first commit, but cannot be published manually. 49 $transitions = array( 'disabled', 'closed' ); 50 break; 51 case 'rejected': 52 // Rejections cannot be recovered. 53 $transitions = array(); 54 break; 55 case 'publish': 56 $transitions = array( 'disabled', 'closed' ); 57 break; 58 case 'disabled': 59 $transitions = array( 'publish', 'closed' ); 60 break; 61 case 'closed': 62 $transitions = array( 'publish', 'disabled' ); 63 break; 64 default: 65 $transitions = array( 'new', 'pending' ); 66 break; 67 } 68 69 return $transitions; 70 } 71 72 /** 34 73 * Checks permissions before allowing a post_status change for plugins. 35 74 * 36 75 * @param array $data An array of slashed post data. … … 51 90 } 52 91 53 92 // ...or it's a plugin admin... 54 if ( current_user_can( 'plugin_approve', $postarr['ID'] ) ) {93 if ( current_user_can( 'plugin_approve', $postarr['ID'] ) && in_array( $postarr['post_status'], self::get_allowed_transitions( $old_status ) ) ) { 55 94 return $data; 56 95 } 57 96 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php
74 74 if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { 75 75 if ( $this->is_trash ) { 76 76 $actions['untrash'] = __( 'Restore', 'wporg-plugins' ); 77 } else {78 $actions['edit'] = __( 'Edit', 'wporg-plugins' );79 77 } 80 78 } 81 79 … … 289 287 } 290 288 291 289 /** 290 * Remove the Quick/Bulk Edit hidden row. 291 */ 292 public function inline_edit() { 293 } 294 295 /** 292 296 * Prepares list view links, including plugins that the current user has commit access to. 293 297 * 294 298 * @global array $locked_post_status This seems to be deprecated. -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-controls.php
1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Admin\Metabox; 3 use WordPressdotorg\Plugin_Directory\Admin\Status_Transitions; 3 4 4 5 /** 5 6 * The Plugin Controls / Publish metabox. … … 30 31 } 31 32 32 33 /** 34 * Get button label for setting the plugin status. 35 * 36 * @param string $post_status Plugin post status. 37 * @return string Status button label. 38 */ 39 public static function get_status_button_label( $post_status ) { 40 switch ( $post_status ) { 41 case 'approved': 42 $label = __( 'Approve' ); 43 break; 44 case 'rejected': 45 $label = __( 'Reject' ); 46 break; 47 case 'pending': 48 $label = __( 'Mark as Pending' ); 49 break; 50 case 'publish': 51 $label = __( 'Open' ); 52 break; 53 case 'disabled': 54 $label = __( 'Disable' ); 55 break; 56 case 'closed': 57 $label = __( 'Close' ); 58 break; 59 default: 60 $label = __( 'Mark as Pending' ); 61 break; 62 } 63 64 return $label; 65 } 66 67 /** 33 68 * Displays the Plugin Status control in the Publish metabox. 34 69 */ 35 70 protected static function display_post_status() { … … 41 76 } 42 77 43 78 $statuses = array( 'new', 'pending' ); 79 44 80 if ( current_user_can( 'plugin_approve', $post ) ) { 45 if ( in_array( $post->post_status, array( 'new', 'draft', 'pending', 'rejected', 'approved' ) ) ) { 46 $statuses = array_merge( $statuses, array( 'approved', 'rejected' ) ); 47 } else { 48 $statuses = array( 'publish', 'disabled', 'closed', 'pending' ); 49 } 81 $statuses = Status_Transitions::get_allowed_transitions( $post->post_status ); 50 82 } 51 83 ?> 52 84 <div class="misc-pub-section misc-pub-plugin-status"> 53 85 <label for="post_status"><?php _e( 'Status:', 'wporg-plugins' ); ?></label> 54 86 <strong id="plugin-status-display"><?php echo esc_html( get_post_status_object( $post->post_status )->label ); ?></strong> 55 <button type="button" class="button-link edit-plugin-status hide-if-no-js">56 <span aria-hidden="true"><?php _e( 'Edit', 'wporg-plugins' ); ?></span>57 <span class="screen-reader-text"><?php _e( 'Edit plugin status', 'wporg-plugins' ); ?></span>58 </button>59 87 60 <div id="plugin-status-select" class="plugin-control-select hide-if-js"> 61 <input type="hidden" name="hidden_post_status" id="hidden-post-status" value="<?php echo esc_attr( $post->post_status ); ?>"> 62 <label class="screen-reader-text" for="plugin-status"><?php _e( 'Plugin status', 'wporg-plugins' ); ?></label> 63 <select name="post_status" id="plugin-status"> 64 <?php 65 foreach ( $statuses as $statii ) { 66 $status_object = get_post_status_object( $statii ); 67 printf( 68 '<option value="%s" %s>%s</option>', 69 esc_attr( $statii ), 70 selected( $post->post_status, $statii, false ), 71 esc_html( $status_object->label ) 72 ); 73 } 74 ?> 75 </select> 76 <button type="button" class="save-plugin-status hide-if-no-js button"><?php _e( 'OK', 'wporg-plugins' ); ?></button> 77 <button type="button" class="cancel-plugin-status hide-if-no-js button-link"><?php _e( 'Cancel', 'wporg-plugins' ); ?></button> 78 </div> 79 88 <p> 89 <?php foreach ( $statuses as $status ) : ?> 90 <button type="submit" name="post_status" value="<?php echo esc_attr( $status ); ?>" class="button set-plugin-status"> 91 <?php echo self::get_status_button_label( $status ); ?> 92 </button> 93 <?php endforeach; ?> 94 </p> 80 95 </div><!-- .misc-pub-section --><?php 81 96 } 82 97 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/edit-form.js
5 5 ( function( $, wp, pluginDirectory ) { 6 6 var PluginEdit = { 7 7 $testedWith: {}, 8 $pluginStatus: {},9 8 10 9 ready: function() { 11 10 PluginEdit.$testedWith = $( '#tested-with-select' ); 12 PluginEdit.$pluginStatus = $( '#plugin-status-select' );13 11 14 12 $( '#submitdiv' ) 15 13 .on( 'click', '.edit-tested-with', PluginEdit.editTestedWith ) 16 .on( 'click', '.edit-plugin-status', PluginEdit.editPluginStatus )17 14 .on( 'click', '.save-tested-with', PluginEdit.updateTestedWith ) 18 .on( 'click', '.save-plugin-status', PluginEdit.updatePluginStatus )19 15 .on( 'click', '.cancel-tested-with', PluginEdit.cancelTestedWith ) 20 .on( 'click', '. cancel-plugin-status', PluginEdit.cancelPluginStatus );16 .on( 'click', '.set-plugin-status', PluginEdit.setPluginStatus ); 21 17 22 18 _.each( $( '#post-body' ).find( '.comments-box' ), PluginEdit.loadComments ); 23 19 … … 52 48 } 53 49 }, 54 50 55 editPluginStatus: function() {56 if ( PluginEdit.$pluginStatus.is( ':hidden' ) ) {57 PluginEdit.$pluginStatus.slideDown( 'fast', function() {58 $( 'select', PluginEdit.$pluginStatus ).focus();59 } );60 $( this ).hide();61 }62 },63 64 51 updateTestedWith: function() { 65 52 PluginEdit.$testedWith.slideUp( 'fast' ).siblings( 'button.edit-tested-with' ).show().focus(); 66 53 $( '#tested-with-display' ).text( $( 'option:selected', PluginEdit.$testedWith ).text() ); 67 54 }, 68 55 69 updatePluginStatus: function() {70 PluginEdit.$pluginStatus.slideUp( 'fast' ).siblings( 'button.edit-plugin-status' ).show().focus();71 $( '#plugin-status-display' ).text( $( 'option:selected', PluginEdit.$pluginStatus ).text() );72 },73 74 56 cancelTestedWith: function() { 75 57 $( '#tested-with' ).val( $( '#hidden-tested-with' ).val() ); 76 58 PluginEdit.updateTestedWith(); 77 59 }, 78 60 79 cancelPluginStatus: function() { 80 $( '#post-status' ).val( $( '#hidden-post-status' ).val() ); 81 PluginEdit.updatePluginStatus( event ); 61 setPluginStatus: function() { 62 if ( 'approved' === $(this).val() ) { 63 return confirm( pluginDirectory.approvePluginAYS ); 64 } else if ( 'rejected' === $(this).val() ) { 65 return confirm( pluginDirectory.rejectPluginAYS ); 66 } else { 67 return true; 68 } 82 69 }, 83 70 84 71 loadComments: function ( element ) {