Changeset 2836 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php
- Timestamp:
- 03/28/2016 09:01:37 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php
r2777 r2836 38 38 global $wpdb; 39 39 40 return $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) ); 40 if ( false === ( $committers = wp_cache_get( "{$plugin_slug}_committer", 'wporg-plugins' ) ) ) { 41 $committers = $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) ); 42 43 wp_cache_set( "{$plugin_slug}_committer", $committers, 'wporg-plugins' ); 44 } 45 46 return $committers; 41 47 } 42 48 49 /** 50 * Retrieve a list of plugins a specific user has commit to. 51 * 52 * @param int|\WP_User $user The user. 53 * @return array The list of plugins the user has commit to. 54 */ 43 55 public static function get_users_write_access_plugins( $user ) { 44 56 global $wpdb; … … 50 62 } 51 63 52 $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) ); 53 $plugins = array_map( function( $plugin ) { return trim( $plugin, '/' ); }, $plugins ); 64 if ( false === ( $plugins = wp_cache_get( "{$user->user_login}_committer", 'wporg-plugins' ) ) ) { 65 $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) ); 66 $plugins = array_map( function( $plugin ) { return trim( $plugin, '/' ); }, $plugins ); 67 68 wp_cache_set( "{$user->user_login}_committer", $plugins, 'wporg-plugins' ); 69 } 54 70 55 71 return $plugins; … … 77 93 $existing_committers = self::get_plugin_committers( $plugin_slug ); 78 94 if ( in_array( $user->user_login, $existing_committers, true ) ) { 79 // User already has write access 95 // User already has write access. 80 96 return true; 81 97 } 98 99 wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' ); 100 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 82 101 83 102 return (bool) $wpdb->insert( … … 86 105 'path' => "/{$plugin_slug}", 87 106 'user' => $user->user_login, 88 'access' => 'rw' 107 'access' => 'rw', 89 108 ) 90 109 ); … … 109 128 } 110 129 130 wp_cache_delete( "{$plugin_slug}_committer", 'wporg-plugins' ); 131 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 132 111 133 return $wpdb->delete( 112 134 PLUGINS_TABLE_PREFIX . 'svn_access',
Note: See TracChangeset
for help on using the changeset viewer.