Making WordPress.org

Changeset 12594


Ignore:
Timestamp:
05/18/2023 03:26:43 AM (17 months ago)
Author:
dd32
Message:

Plugin Directory: Clear the assigned reviewer on the appropriate status transitions (->approved and ->publish).

See #6993.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin
Files:
3 edited

Legend:

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

    r12591 r12594  
    6969        add_action( 'save_post', array( __NAMESPACE__ . '\Metabox\Author_Notice', 'save_post' ) );
    7070        add_action( 'save_post', array( __NAMESPACE__ . '\Metabox\Reviewer', 'save_post' ) );
    71 
    72         // Audit logs
    73         add_action( 'updated_postmeta', array( $this, 'updated_postmeta' ), 10, 4 );
    7471    }
    7572
     
    858855        return $keys;
    859856    }
    860 
    861     /**
    862      * Watch for post_meta updates and log accordingly.
    863      */
    864     public function updated_postmeta( $meta_id, $post_id, $meta_key, $meta_value ) {
    865         if ( 'assigned_reviewer' === $meta_key && $meta_value ) {
    866             $reviewer = get_user_by( 'id', $meta_value );
    867             Tools::audit_log(
    868                 sprintf(
    869                     'Assigned to <a href="%s">%s</a>.',
    870                     esc_url( 'https://profiles.wordpress.org/' . $reviewer->user_nicename . '/' ),
    871                     $reviewer->display_name ?: $reviewer->user_login
    872                 ),
    873                 get_post( $post_id )
    874             );
    875         } elseif ( 'assigned_reviewer' === $meta_key && ! $meta_value ) {
    876             Tools::audit_log( 'Unassigned.', get_post( $post_id ) );
    877         }
    878     }
    879857}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php

    r12517 r12594  
    88use WordPressdotorg\Plugin_Directory\Email\Plugin_Approved as Plugin_Approved_Email;
    99use WordPressdotorg\Plugin_Directory\Email\Plugin_Rejected as Plugin_Rejected_Email;
     10use WordPressdotorg\Plugin_Directory\Admin\Metabox\Reviewer as Reviewer_Metabox;
    1011
    1112/**
     
    135136            case 'approved':
    136137                $this->approved( $post->ID, $post );
     138                $this->clear_reviewer( $post );
    137139                break;
    138140
    139141            case 'rejected':
    140142                $this->rejected( $post->ID, $post );
     143                $this->clear_reviewer( $post );
    141144                break;
    142145
     
    144147                $this->clean_closed_date( $post->ID );
    145148                $this->set_translation_status( $post, 'active' );
     149                $this->clear_reviewer( $post );
    146150                break;
    147151
     
    364368    }
    365369
     370    /**
     371     * Clear the assigned reviewer.
     372     *
     373     * @param \WP_Post $post Post object.
     374     */
     375    public function clear_reviewer( $post ) {
     376        // Unset the reviewer, but don't log it, as the triggering status changes should've been logged in some form.
     377        Reviewer_Metabox::set_reviewer( $post, false, false );
     378    }
    366379}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-reviewer.php

    r12591 r12594  
    103103        }
    104104
    105         update_post_meta( $post_id, 'assigned_reviewer', $reviewer_id );
    106         update_post_meta( $post_id, 'assigned_reviewer_time', time() );
     105        self::set_reviewer( $post_id, $reviewer_id );
    107106
    108107        $assigned_reviewer = get_post_meta( $post_id, 'assigned_reviewer', true );
     
    127126        $reviewer_id = absint( $_POST['assigned_reviewer'] ?? 0 );
    128127
    129         update_post_meta( $post_id, 'assigned_reviewer', $reviewer_id );
    130         update_post_meta( $post_id, 'assigned_reviewer_time', time() );
     128        self::set_reviewer( $post_id, $reviewer_id );
     129    }
     130
     131    /**
     132     * Set the reviewer for a post.
     133     *
     134     * @param int|WP_Post $post     Post object or ID.
     135     * @param int|WP_User $reviewer Reviewer User object or ID.
     136     * @param bool        $log_it   Whether to log the change. Optional.
     137     * @return bool
     138     */
     139    public static function set_reviewer( $post, $reviewer, $log_it = true ) {
     140        $post             = get_post( $post );
     141        $current_reviewer = get_post_meta( $post->ID, 'assigned_reviewer', true );
     142        $reviewer         = is_object( $reviewer ) ? $reviewer : get_user_by( 'id', $reviewer );
     143        $reviewer_id      = $reviewer->ID ?? 0;
     144
     145        if ( $current_reviewer == $reviewer_id || ! $post ) {
     146            return false;
     147        }
     148
     149        if ( ! $reviewer ) {
     150            delete_post_meta( $post->ID, 'assigned_reviewer' );
     151            delete_post_meta( $post->ID, 'assigned_reviewer_time' );
     152        } else {
     153            update_post_meta( $post->ID, 'assigned_reviewer', $reviewer_id );
     154            update_post_meta( $post->ID, 'assigned_reviewer_time', time() );
     155        }
     156
     157        // Audit logging.
     158        if ( $log_it ) {
     159            $message = 'Unassigned.';
     160            if ( $reviewer ) {
     161                $message = sprintf(
     162                    'Assigned to <a href="%s">%s</a>.',
     163                    esc_url( 'https://profiles.wordpress.org/' . $reviewer->user_nicename . '/' ),
     164                    $reviewer->display_name ?: $reviewer->user_login
     165                );
     166            }
     167
     168            Tools::audit_log( $message, $post );
     169        }
     170
     171        return true;
    131172    }
    132173}
Note: See TracChangeset for help on using the changeset viewer.