Making WordPress.org

Changeset 5573


Ignore:
Timestamp:
06/15/2017 02:05:54 PM (6 years ago)
Author:
Otto42
Message:

Plugin Directory: Change edit actions dropdown to buttons with specific states. props @SergeyBiryukov. Fixes #2796

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php

    r5335 r5573  
    3333        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
    3434        add_filter( 'admin_head-edit.php', array( $this, 'plugin_posts_list_table' ) );
     35        add_filter( 'post_row_actions', array( $this, 'plugin_row_actions' ) );
    3536        add_action( 'edit_form_top', array( $this, 'show_permalink' ) );
    3637        add_action( 'admin_notices', array( $this, 'add_post_status_notice' ) );
     
    112113                    wp_enqueue_script( 'plugin-admin-post-js', plugins_url( 'js/edit-form.js', Plugin_Directory\PLUGIN_FILE ), array( 'wp-util', 'wp-lists' ), 3 );
    113114                    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' ),
    114117                        'removeCommitterAYS' => __( 'Are you sure you want to remove this committer?', 'wporg-plugins' ),
    115118                    ) );
     
    160163            $wp_list_table->prepare_items();
    161164        }
     165    }
     166
     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;
    162181    }
    163182
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php

    r5460 r5573  
    3232
    3333    /**
     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    /**
    3473     * Checks permissions before allowing a post_status change for plugins.
    3574     *
     
    5291
    5392        // ...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 ) ) ) {
    5594            return $data;
    5695        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/list-table/class-plugin-posts.php

    r5318 r5573  
    7575            if ( $this->is_trash ) {
    7676                $actions['untrash'] = __( 'Restore', 'wporg-plugins' );
    77             } else {
    78                 $actions['edit'] = __( 'Edit', 'wporg-plugins' );
    7977            }
    8078        }
     
    290288
    291289    /**
     290     * Remove the Quick/Bulk Edit hidden row.
     291     */
     292    public function inline_edit() {
     293    }
     294
     295    /**
    292296     * Prepares list view links, including plugins that the current user has commit access to.
    293297     *
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-controls.php

    r5318 r5573  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
     3use WordPressdotorg\Plugin_Directory\Admin\Status_Transitions;
    34
    45/**
     
    3132
    3233    /**
     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    /**
    3368     * Displays the Plugin Status control in the Publish metabox.
    3469     */
     
    4277
    4378        $statuses = array( 'new', 'pending' );
     79
    4480        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 );
    5082        }
    5183        ?>
     
    5385            <label for="post_status"><?php _e( 'Status:', 'wporg-plugins' ); ?></label>
    5486            <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>
    5987
    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>
    8095        </div><!-- .misc-pub-section --><?php
    8196    }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/edit-form.js

    r5335 r5573  
    66    var PluginEdit = {
    77        $testedWith: {},
    8         $pluginStatus: {},
    98
    109        ready: function() {
    1110            PluginEdit.$testedWith   = $( '#tested-with-select' );
    12             PluginEdit.$pluginStatus = $( '#plugin-status-select' );
    1311
    1412            $( '#submitdiv' )
    1513                .on( 'click', '.edit-tested-with',     PluginEdit.editTestedWith )
    16                 .on( 'click', '.edit-plugin-status',   PluginEdit.editPluginStatus )
    1714                .on( 'click', '.save-tested-with',     PluginEdit.updateTestedWith )
    18                 .on( 'click', '.save-plugin-status',   PluginEdit.updatePluginStatus )
    1915                .on( 'click', '.cancel-tested-with',   PluginEdit.cancelTestedWith )
    20                 .on( 'click', '.cancel-plugin-status', PluginEdit.cancelPluginStatus );
     16                .on( 'click', '.set-plugin-status',    PluginEdit.setPluginStatus );
    2117
    2218            _.each( $( '#post-body' ).find( '.comments-box' ), PluginEdit.loadComments );
     
    5349        },
    5450
    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 
    6451        updateTestedWith: function() {
    6552            PluginEdit.$testedWith.slideUp( 'fast' ).siblings( 'button.edit-tested-with' ).show().focus();
    6653            $( '#tested-with-display' ).text( $( 'option:selected', PluginEdit.$testedWith ).text() );
    67         },
    68 
    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() );
    7254        },
    7355
     
    7759        },
    7860
    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            }
    8269        },
    8370
Note: See TracChangeset for help on using the changeset viewer.