Making WordPress.org


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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                }
Note: See TracChangeset for help on using the changeset viewer.