Making WordPress.org

Changeset 9094


Ignore:
Timestamp:
08/07/2019 10:45:11 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Plugin Directory: Track plugin ownership change in audit log.

Props Ipstenu, SergeyBiryukov.
Fixes #4663.

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

Legend:

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

    r8900 r9094  
    2727        private function __construct() {
    2828                add_action( 'transition_post_status', array( $this, 'transition_post_status' ), 11, 3 );
     29                add_action( 'post_updated', array( $this, 'record_owner_change' ), 11, 3 );
    2930        }
    3031
    … …  
    384385                update_post_meta( $post_id, 'plugin_closed_date', current_time( 'mysql' ) );
    385386
    386                 $this->audit_log( sprintf( 'Plugin closed for: %s', $close_reason ), $post_id );
     387                $this->audit_log( sprintf( 'Plugin closed. Reason: %s', $close_reason ), $post_id );
     388        }
     389
     390        /**
     391         * Records a plugin owner change.
     392         *
     393         * @param integer $post_id     Post ID.
     394         * @param WP_Post $post_after  Post object following the update.
     395         * @param WP_Post $post_before Post object before the update.
     396         */
     397        public function record_owner_change( $post_id, $post_after, $post_before ) {
     398                if ( 'plugin' !== $post_after->post_type ) {
     399                        return;
     400                }
     401
     402                if ( $post_after->post_author === $post_before->post_author ) {
     403                        return;
     404                }
     405
     406                $new_owner = get_userdata( $post_after->post_author );
     407
     408                $this->audit_log( sprintf(
     409                        'Ownership transferred to <a href="%s">%s</a>.',
     410                        esc_url( '//profiles.wordpress.org/' . $new_owner->user_nicename ),
     411                        $new_owner->user_login
     412                ), $post_id );
    387413        }
    388414
    … …  
    393419         * @param integer $post_id The Post ID.
    394420         */
    395         private function audit_log( $message, $post_id ) {
     421        public function audit_log( $message, $post_id ) {
    396422                $user = wp_get_current_user();
    397423
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r9042 r9094  
    15191519                        wp_cache_set( $result, $slug, 'plugin-slugs' );
    15201520                        $result = get_post( $result );
     1521
     1522                        $owner = get_userdata( $result->post_author );
     1523
     1524                        Admin\Status_Transitions::instance()->audit_log( sprintf(
     1525                                'Submitted by <a href="%s">%s</a>.',
     1526                                esc_url( '//profiles.wordpress.org/' . $owner->user_nicename ),
     1527                                $owner->user_login
     1528                        ), $result->ID );
    15211529                }
    15221530
Note: See TracChangeset for help on using the changeset viewer.