Changeset 12594
- Timestamp:
- 05/18/2023 03:26:43 AM (17 months ago)
- 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 69 69 add_action( 'save_post', array( __NAMESPACE__ . '\Metabox\Author_Notice', 'save_post' ) ); 70 70 add_action( 'save_post', array( __NAMESPACE__ . '\Metabox\Reviewer', 'save_post' ) ); 71 72 // Audit logs73 add_action( 'updated_postmeta', array( $this, 'updated_postmeta' ), 10, 4 );74 71 } 75 72 … … 858 855 return $keys; 859 856 } 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_login872 ),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 }879 857 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-status-transitions.php
r12517 r12594 8 8 use WordPressdotorg\Plugin_Directory\Email\Plugin_Approved as Plugin_Approved_Email; 9 9 use WordPressdotorg\Plugin_Directory\Email\Plugin_Rejected as Plugin_Rejected_Email; 10 use WordPressdotorg\Plugin_Directory\Admin\Metabox\Reviewer as Reviewer_Metabox; 10 11 11 12 /** … … 135 136 case 'approved': 136 137 $this->approved( $post->ID, $post ); 138 $this->clear_reviewer( $post ); 137 139 break; 138 140 139 141 case 'rejected': 140 142 $this->rejected( $post->ID, $post ); 143 $this->clear_reviewer( $post ); 141 144 break; 142 145 … … 144 147 $this->clean_closed_date( $post->ID ); 145 148 $this->set_translation_status( $post, 'active' ); 149 $this->clear_reviewer( $post ); 146 150 break; 147 151 … … 364 368 } 365 369 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 } 366 379 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-reviewer.php
r12591 r12594 103 103 } 104 104 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 ); 107 106 108 107 $assigned_reviewer = get_post_meta( $post_id, 'assigned_reviewer', true ); … … 127 126 $reviewer_id = absint( $_POST['assigned_reviewer'] ?? 0 ); 128 127 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; 131 172 } 132 173 }
Note: See TracChangeset
for help on using the changeset viewer.