Making WordPress.org


Ignore:
Timestamp:
10/04/2017 02:45:22 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Make sure that Status_Transitions::approved() and ::rejected() only run on status change, not on subsequent edits.

See #3180.

File:
1 edited

Legend:

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

    r5918 r5996  
    2525     */
    2626    private function __construct() {
    27         add_action( 'transition_post_status', array( $this, 'record_status_change' ), 11, 3 );
    28 
    29         add_action( 'approved_plugin', array( $this, 'approved' ), 10, 2 );
    30         add_action( 'rejected_plugin', array( $this, 'rejected' ), 10, 2 );
     27        add_action( 'transition_post_status', array( $this, 'transition_post_status' ), 11, 3 );
    3128    }
    3229
     
    107104
    108105    /**
    109      * Records the time a plugin was transitioned into a specific status.
     106     * Calls the methods that should fire when a plugin is transitioned
     107     * to a specific status.
    110108     *
    111109     * @param string   $new_status New post status.
     
    113111     * @param \WP_Post $post       Post object.
    114112     */
    115     public function record_status_change( $new_status, $old_status, $post ) {
    116         if ( 'plugin' === $post->post_type ) {
    117             update_post_meta( $post->ID, "_{$new_status}", strtotime( $post->post_modified_gmt ) );
    118         }
     113    public function transition_post_status( $new_status, $old_status, $post ) {
     114        if ( 'plugin' !== $post->post_type ) {
     115            return;
     116        }
     117
     118        // Bail if no status change.
     119        if ( $old_status === $new_status ) {
     120            return;
     121        }
     122
     123        switch ( $new_status ) {
     124            case 'approved':
     125                $this->approved( $post->ID, $post );
     126                break;
     127            case 'rejected':
     128                $this->rejected( $post->ID, $post );
     129                break;
     130        }
     131
     132        // Record the time a plugin was transitioned into a specific status.
     133        update_post_meta( $post->ID, "_{$new_status}", strtotime( $post->post_modified_gmt ) );
    119134    }
    120135
     
    216231        }
    217232
    218         // Prevent recursive calling via wp_update_post().
    219         remove_action( 'rejected_plugin', array( $this, 'rejected' ), 10 );
    220 
    221233        // Change slug to 'rejected-plugin-name-rejected' to free up 'plugin-name'.
    222234        wp_update_post( array(
     
    224236            'post_name' => sprintf( 'rejected-%s-rejected', $post->post_name )
    225237        ) );
    226 
    227         // Re-add action.
    228         add_action( 'rejected_plugin', array( $this, 'rejected' ), 10, 2 );
    229238
    230239        // Send email.
Note: See TracChangeset for help on using the changeset viewer.