Changeset 13507 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php
- Timestamp:
- 04/12/2024 03:58:20 AM (10 months ago)
- 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 36 36 37 37 /** 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. 41 42 * 42 43 * @return array An array of allowed post status transitions. 43 44 */ 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. 45 47 switch ( $post_status ) { 46 48 case 'new': … … 48 50 break; 49 51 case 'pending': 50 $transitions = array( 'approved', 'rejected' );52 $transitions = array( 'approved', 'rejected', 'new' ); 51 53 break; 52 54 case 'approved': … … 55 57 break; 56 58 case 'rejected': 57 // Rejections cannot be recovered.58 59 $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 } 59 65 break; 60 66 case 'publish': … … 97 103 98 104 // ...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'] ) ) ) ) { 100 106 return $data; 101 107 } … … 158 164 $this->set_translation_status( $post, 'inactive' ); 159 165 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 } 160 177 } 161 178 … … 298 315 299 316 /** 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 /** 300 336 * Returns the path to a plugins root directory. 301 337 *
Note: See TracChangeset
for help on using the changeset viewer.