Making WordPress.org

Ticket #2796: 2796.patch

File 2796.patch, 5.9 KB (added by SergeyBiryukov, 8 years ago)
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php

     
    3131        }
    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();
     50                                break;
     51                        case 'rejected':
     52                                $transitions = array( 'pending' );
     53                                break;
     54                        case 'publish':
     55                                $transitions = array( 'disabled', 'closed' );
     56                                break;
     57                        case 'disabled':
     58                                $transitions = array( 'publish', 'closed' );
     59                                break;
     60                        case 'closed':
     61                                $transitions = array( 'publish', 'disabled' );
     62                                break;
     63                        default:
     64                                $transitions = array( 'new', 'pending' );
     65                                break;
     66                }
     67
     68                return $transitions;
     69        }
     70
     71        /**
    3472         * Checks permissions before allowing a post_status change for plugins.
    3573         *
    3674         * @param array $data    An array of slashed post data.
     
    5189                }
    5290
    5391                // ...or it's a plugin admin...
    54                 if ( current_user_can( 'plugin_approve', $postarr['ID'] ) ) {
     92                if ( current_user_can( 'plugin_approve', $postarr['ID'] ) && in_array( $postarr['post_status'], self::get_allowed_transitions( $postarr['post_status'] ) ) ) {
    5593                        return $data;
    5694                }
    5795
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-controls.php

     
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
     3use WordPressdotorg\Plugin_Directory\Admin\Status_Transitions;
    34
    45/**
    56 * The Plugin Controls / Publish metabox.
     
    4142                }
    4243
    4344                $statuses = array( 'new', 'pending' );
     45
    4446                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                         }
     47                        $statuses = Status_Transitions::get_allowed_transitions( $post->post_status );
    5048                }
    5149                ?>
    5250                <div class="misc-pub-section misc-pub-plugin-status">
    5351                        <label for="post_status"><?php _e( 'Status:', 'wporg-plugins' ); ?></label>
    5452                        <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>
    5953
    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>
     54                        <?php if ( $statuses ) : ?>
     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>
    7959
     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                        <?php endif; ?>
     80
    8081                </div><!-- .misc-pub-section --><?php
    8182        }
    8283