Making WordPress.org


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

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

Fixes #2717.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.