Making WordPress.org


Ignore:
Timestamp:
04/12/2024 03:58:20 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Allow reviewers to move a plugin from pending (Pending developer feedback) back to new (Pending initial review), and from rejected back to pending (Pending developer feedback)

Fixes #7386.

File:
1 edited

Legend:

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

    r13440 r13507  
    3636
    3737        /**
    38          * Get the list of allowed status transitions for a given plugin.
    39          *
    40          * @param string $post_status Plugin post status.
     38         * Get the list of allowed status transitions for a given plugin status & post.
     39         *
     40         * @param string   $post_status Plugin post status.
     41         * @param \WP_Post $post        Plugin post object.
    4142         *
    4243         * @return array An array of allowed post status transitions.
    4344         */
    44         public static function get_allowed_transitions( $post_status ) {
     45        public static function get_allowed_transitions( $post_status, $post ) {
     46                // NOTE: $post_status and $post->post_status will differ, as it's used during a pre-update hook.
    4547                switch ( $post_status ) {
    4648                        case 'new':
     
    4850                                break;
    4951                        case 'pending':
    50                                 $transitions = array( 'approved', 'rejected' );
     52                                $transitions = array( 'approved', 'rejected', 'new' );
    5153                                break;
    5254                        case 'approved':
     
    5557                                break;
    5658                        case 'rejected':
    57                                 // Rejections cannot be recovered.
    5859                                $transitions = array();
     60                                // If it was rejected less than a week ago, allow it to be recovered.
     61                                $rejected_date = get_post_meta( $post->ID, '_rejected', true );
     62                                if ( $rejected_date >= strtotime( '-1 week' ) ) {
     63                                        $transitions[] = 'pending';
     64                                }
    5965                                break;
    6066                        case 'publish':
     
    97103
    98104                // ...or it's a plugin admin...
    99                 if ( current_user_can( 'plugin_approve', $postarr['ID'] ) && in_array( $postarr['post_status'], self::get_allowed_transitions( $old_status ) ) ) {
     105                if ( current_user_can( 'plugin_approve', $postarr['ID'] ) && in_array( $postarr['post_status'], self::get_allowed_transitions( $old_status, get_post( $postarr['ID'] ) ) ) ) {
    100106                        return $data;
    101107                }
     
    158164                                $this->set_translation_status( $post, 'inactive' );
    159165                                break;
     166
     167                        case 'pending':
     168                                if ( 'rejected' === $old_status ) {
     169                                        $this->restore_rejected_plugin( $post );
     170                                }
     171
     172                        case 'new':
     173                                // If it's moved from Pending to new, unasign.
     174                                if ( 'pending' === $old_status ) {
     175                                        $this->clear_reviewer( $post );
     176                                }
    160177                }
    161178
     
    298315
    299316        /**
     317         * Restores a rejected plugin.
     318         *
     319         * @param \WP_Post $post Post object.
     320         */
     321        public function restore_rejected_plugin( $post ) {
     322                $slug = $post->post_name;
     323                $slug = preg_replace( '!^rejected-(.+)-rejected$!i', '$1', $slug );
     324
     325                // Change slug back to 'plugin-name'.
     326                wp_update_post( array(
     327                        'ID'        => $post->ID,
     328                        'post_name' => $slug,
     329                ) );
     330
     331                delete_post_meta( $post_id, '_rejection_reason' );
     332                delete_post_meta( $post_id, 'plugin_rejected_date' );
     333        }
     334
     335        /**
    300336         * Returns the path to a plugins root directory.
    301337         *
Note: See TracChangeset for help on using the changeset viewer.