Making WordPress.org

Changeset 2562


Ignore:
Timestamp:
02/24/2016 08:02:18 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Add the starts of a Plugin Committers metabox & the methods required to alter the database records.
See #1571

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

Legend:

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

    r2555 r2562  
    5454
    5555        $tonesque = new Tonesque( $file_location );
    56         if ( $tonesque ) {
    57             return $tonesque->color();
     56        return $tonesque->color();
     57    }
     58
     59    /**
     60     * Retrieve a list of users who have commit to a specific plugin.
     61     *
     62     * @param string $plugin_slug The plugin slug.
     63     * @return array The list of user_login's which have commit.
     64     */
     65    public static function get_plugin_committers( $plugin_slug ) {
     66        global $wpdb;
     67
     68        return $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) );
     69    }
     70
     71    /**
     72     * Grant a user RW access to a plugin.
     73     *
     74     * @param string         $plugin_slug The plugin slug.
     75     * @param string|WP_User $user        The user to grant access to.
     76     */
     77    public static function grant_plugin_committer( $plugin_slug, $user ) {
     78        global $wpdb, $wporg_plugin_directory;
     79        if ( ! $user instanceof WP_User ) {
     80            $user = new WP_User( $user );
    5881        }
    5982
    60         return false;
     83        if ( ! $user->exists() || ! $wporg_plugin_directory->get_plugin_post( $plugin_slug ) ) {
     84            return false;
     85        }
     86
     87        $existing_committers = wp_list_pluck( self::get_plugin_committers( $plugin_slug ), 'user_login' );
     88        if ( in_array( $user->user_login, $existing_committers, true ) ) {
     89            // User already has write access
     90            return true;
     91        }
     92
     93        return (bool)$wpdb->insert(
     94            PLUGINS_TABLE_PREFIX . 'svn_access',
     95            array(
     96                'path'   => "/{$plugin_slug}",
     97                'user'   => $user->user_login,
     98                'access' => 'rw'
     99            )
     100        );
    61101    }
     102
     103    /**
     104     * Revoke a users RW access to a plugin.
     105     *
     106     * @param string         $plugin_slug The plugin slug.
     107     * @param string|WP_User $user        The user to revoke access of.
     108     */
     109    public static function revoke_plugin_committer( $plugin_slug, $user ) {
     110        global $wpdb, $wporg_plugin_directory;
     111        if ( ! $user instanceof WP_User ) {
     112            $user = new WP_User( $user );
     113        }
     114
     115        if ( ! $user->exists() || ! $wporg_plugin_directory->get_plugin_post( $plugin_slug ) ) {
     116            return false;
     117        }
     118
     119        return $wpdb->delete(
     120            PLUGINS_TABLE_PREFIX . 'svn_access',
     121            array(
     122                'path'   => "/{$plugin_slug}",
     123                'user'   => $user->user_login
     124            )
     125        );
     126    }
     127
     128
    62129}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/wporg-plugin-directory.php

    r2560 r2562  
    2020include __DIR__ . '/shortcodes/screenshots.php';
    2121
     22if ( is_admin() ) {
     23    include __DIR__ . '/admin/class-wporg-plugin-directory-admin-metabox-committers.php';
     24}
     25
    2226$wporg_plugin_directory = new WPorg_Plugin_Directory();
    2327register_activation_hook( __FILE__, array( $wporg_plugin_directory, 'activate' ) );
Note: See TracChangeset for help on using the changeset viewer.