Making WordPress.org

Changeset 9682


Ignore:
Timestamp:
04/02/2020 02:23:28 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: Add audit log entries for plugin committer/support reps addition/removal.

Fixes #2717.

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

Legend:

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

    r9094 r9682  
    280280        );
    281281
    282         $this->audit_log( 'Plugin approved.', $post_id );
     282        Tools::audit_log( 'Plugin approved.', $post_id );
    283283        wp_mail( $plugin_author->user_email, $subject, $content, 'From: plugins@wordpress.org' );
    284284    }
     
    322322        );
    323323
    324         $this->audit_log( 'Plugin rejected.', $post_id );
     324        Tools::audit_log( 'Plugin rejected.', $post_id );
    325325        wp_mail( $email, $subject, $content, 'From: plugins@wordpress.org' );
    326326    }
     
    362362        $post = get_post( $post_id );
    363363        if ( $post && 'approved' != $post->post_status ) {
    364             $this->audit_log( 'Plugin reopened.', $post_id );
     364            Tools::audit_log( 'Plugin reopened.', $post_id );
    365365        }
    366366    }
     
    385385        update_post_meta( $post_id, 'plugin_closed_date', current_time( 'mysql' ) );
    386386
    387         $this->audit_log( sprintf( 'Plugin closed. Reason: %s', $close_reason ), $post_id );
     387        Tools::audit_log( sprintf( 'Plugin closed. Reason: %s', $close_reason ), $post_id );
    388388    }
    389389
     
    406406        $new_owner = get_userdata( $post_after->post_author );
    407407
    408         $this->audit_log( sprintf(
     408        Tools::audit_log( sprintf(
    409409            'Ownership transferred to <a href="%s">%s</a>.',
    410             esc_url( '//profiles.wordpress.org/' . $new_owner->user_nicename ),
     410            esc_url( 'https://profiles.wordpress.org/' . $new_owner->user_nicename .'/' ),
    411411            $new_owner->user_login
    412412        ), $post_id );
    413413    }
    414414
    415     /**
    416      * Saves an audit_log comment for the plugin.
    417      *
    418      * @param string  $message The message for the audit log.
    419      * @param integer $post_id The Post ID.
    420      */
    421     public function audit_log( $message, $post_id ) {
    422         $user = wp_get_current_user();
    423 
    424         $comment = array(
    425             'comment_author'       => $user->display_name,
    426             'comment_author_email' => $user->user_email,
    427             'comment_author_url'   => $user->user_url,
    428             'comment_type'         => 'internal-note',
    429             'comment_post_ID'      => $post_id,
    430             'user_id'              => get_current_user_id(),
    431             'comment_content'      => $message,
    432         );
    433         wp_insert_comment( $comment );
    434     }
    435415}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-internal-notes.php

    r6403 r9682  
    4747     * @param string $action Action to perform.
    4848     */
    49     function get_notes( $action ) {
     49    public static function get_notes( $action ) {
    5050        global $post_id;
    5151        if ( empty( $action ) ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-self-close.php

    r9674 r9682  
    7474
    7575        // Add an audit-log entry as to why this has happened.
    76         $user = wp_get_current_user();
    77         wp_insert_comment( [
    78             'comment_author'       => $user->display_name,
    79             'comment_author_email' => $user->user_email,
    80             'comment_author_url'   => $user->user_url,
    81             'comment_type'         => 'internal-note',
    82             'comment_post_ID'      => $plugin->ID,
    83             'user_id'              => get_current_user_id(),
    84             'comment_content'      => sprintf( 'Plugin closed. Reason: Author Self-close Request from %s', $_SERVER['REMOTE_ADDR'] ),
    85         ] );
     76        Tools::audit_log(
     77            $plugin,
     78            sprintf( 'Plugin closed. Reason: Author Self-close Request from %s', $_SERVER['REMOTE_ADDR'] )
     79        );
    8680
    8781        // Email all Plugin Committers.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php

    r9650 r9682  
    197197        Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
    198198
     199        Tools::audit_log(
     200            sprintf(
     201                'Added <a href="%s">%s</a> as a committer.',
     202                esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ),
     203                $user->user_login
     204            ),
     205            $plugin_slug
     206        );
     207
    199208        return $result;
    200209    }
     
    229238        wp_cache_delete( $user->user_login, 'committer-plugins' );
    230239        Tools::sync_plugin_committers_with_taxonomy( $plugin_slug );
     240
     241        Tools::audit_log(
     242            sprintf(
     243                'Removed <a href="%s">%s</a> as a committer.',
     244                esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ),
     245                $user->user_login
     246            ),
     247            $plugin_slug
     248        );
    231249
    232250        return $result;
     
    326344        wp_cache_delete( $user->user_nicename, 'support-rep-plugins' );
    327345
     346        Tools::audit_log(
     347            sprintf(
     348                'Added <a href="%s">%s</a> as a support rep.',
     349                esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ),
     350                $user->user_login
     351            ),
     352            $plugin_slug
     353        );
     354
    328355        return $result;
    329356    }
     
    357384        wp_cache_delete( $plugin_slug, 'plugin-support-reps' );
    358385        wp_cache_delete( $user->user_nicename, 'support-rep-plugins' );
     386
     387        Tools::audit_log(
     388            sprintf(
     389                'Removed <a href="%s">%s</a> as a support rep.',
     390                esc_url( 'https://profiles.wordpress.org/' . $user->user_nicename . '/' ),
     391                $user->user_login
     392            ),
     393            $plugin_slug
     394        );
    359395
    360396        return $result;
     
    557593        }
    558594    }
     595
     596    /**
     597     * Add an Audit Internal Note for a plugin.
     598     *
     599     * @param int|string|WP_Post $plugin A Post ID, Plugin Slug or, WP_Post object.
     600     * @param string $note The note to audit log entry to add.
     601     * @param WP_User $user The user which performed the action. Optional.
     602     */
     603    public static function audit_log( $note, $plugin = null, $user = false ) {
     604        if ( is_string( $plugin ) && ! is_numeric( $plugin ) ) {
     605            $plugin = Plugin_Directory::get_plugin_post( $plugin );
     606        } else {
     607            $plugin = get_post( $plugin );
     608        }
     609
     610        if ( ! $note || ! $plugin ) {
     611            return false;
     612        }
     613        if ( ! $user || ! ( $user instanceof \WP_User ) ) {
     614            $user = wp_get_current_user();
     615        }
     616
     617        return wp_insert_comment( [
     618            'comment_author'       => $user->display_name,
     619            'comment_author_email' => $user->user_email,
     620            'comment_author_url'   => $user->user_url,
     621            'comment_author_IP'    => $_SERVER['REMOTE_ADDR'],
     622            'comment_type'         => 'internal-note',
     623            'comment_post_ID'      => $plugin->ID,
     624            'user_id'              => $user->ID,
     625            'comment_content'      => $note,
     626        ] );
     627    }
    559628}
Note: See TracChangeset for help on using the changeset viewer.