Changeset 3511 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-tools.php
- Timestamp:
- 06/20/2016 05:34:18 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
r3510 r3511 12 12 /** 13 13 * Retrieve the average color of a specified image. 14 * 14 15 * This currently relies upon the Jetpack libraries. 15 16 * 16 * @param $file_location string URL or filepath of image 17 * @return string|bool Average color as a hex value, False on failure 18 */ 19 static function get_image_average_color( $file_location ) { 17 * @static 18 * 19 * @param $file_location string URL or filepath of image. 20 * @return string|bool Average color as a hex value, False on failure. 21 */ 22 public static function get_image_average_color( $file_location ) { 20 23 if ( ! class_exists( 'Tonesque' ) && function_exists( 'jetpack_require_lib' ) ) { 21 24 jetpack_require_lib( 'tonesque' ); 22 25 } 26 23 27 if ( ! class_exists( 'Tonesque' ) ) { 24 28 return false; … … 33 37 * Returns the two latest reviews of a specific plugin. 34 38 * 39 * @static 35 40 * @global \wpdb $wpdb WordPress database abstraction object. 36 41 * … … 54 59 posts.post_position = 1 55 60 ORDER BY ratings.review_id DESC LIMIT 2", $plugin_slug ) ); 61 56 62 wp_cache_set( "{$plugin_slug}_reviews", $reviews, 'wporg-plugins', HOUR_IN_SECONDS ); 57 63 } … … 62 68 /** 63 69 * Retrieve a list of users who have commit to a specific plugin. 70 * 71 * @static 72 * @global \wpdb $wpdb WordPress database abstraction object. 64 73 * 65 74 * @param string $plugin_slug The plugin slug. … … 67 76 */ 68 77 public static function get_plugin_committers( $plugin_slug ) { 69 global $wpdb;70 71 78 if ( false === ( $committers = wp_cache_get( "{$plugin_slug}_committer", 'wporg-plugins' ) ) ) { 79 global $wpdb; 80 72 81 $committers = $wpdb->get_col( $wpdb->prepare( 'SELECT user FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE path = %s', "/{$plugin_slug}" ) ); 73 82 … … 80 89 /** 81 90 * Retrieve a list of plugins a specific user has commit to. 91 * 92 * @static 93 * @global \wpdb $wpdb WordPress database abstraction object. 82 94 * 83 95 * @param int|\WP_User $user The user. … … 85 97 */ 86 98 public static function get_users_write_access_plugins( $user ) { 87 global $wpdb;88 99 if ( ! $user instanceof \WP_User ) { 89 100 $user = new \WP_User( $user ); 90 101 } 102 91 103 if ( ! $user->exists() ) { 92 104 return false; … … 94 106 95 107 if ( false === ( $plugins = wp_cache_get( "{$user->user_login}_committer", 'wporg-plugins' ) ) ) { 108 global $wpdb; 109 96 110 $plugins = $wpdb->get_col( $wpdb->prepare( 'SELECT path FROM `' . PLUGINS_TABLE_PREFIX . 'svn_access' . '` WHERE user = %s', $user->user_login ) ); 97 $plugins = array_map( function( $plugin ) { return trim( $plugin, '/' ); }, $plugins ); 111 $plugins = array_map( function ( $plugin ) { 112 return trim( $plugin, '/' ); 113 }, $plugins ); 98 114 99 115 wp_cache_set( "{$user->user_login}_committer", $plugins, 'wporg-plugins' ); … … 101 117 102 118 return $plugins; 103 104 119 } 105 120 106 121 /** 107 122 * Grant a user RW access to a plugin. 123 * 124 * @static 125 * @global \wpdb $wpdb WordPress database abstraction object. 108 126 * 109 127 * @param string $plugin_slug The plugin slug. … … 124 142 $existing_committers = self::get_plugin_committers( $plugin_slug ); 125 143 if ( in_array( $user->user_login, $existing_committers, true ) ) { 144 126 145 // User already has write access. 127 146 return true; … … 131 150 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 132 151 133 return (bool) $wpdb->insert( 134 PLUGINS_TABLE_PREFIX . 'svn_access', 135 array( 136 'path' => "/{$plugin_slug}", 137 'user' => $user->user_login, 138 'access' => 'rw', 139 ) 140 ); 152 return (bool) $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array( 153 'path' => "/{$plugin_slug}", 154 'user' => $user->user_login, 155 'access' => 'rw', 156 ) ); 141 157 } 142 158 143 159 /** 144 160 * Revoke a users RW access to a plugin. 161 * 162 * @static 163 * @global \wpdb $wpdb WordPress database abstraction object. 145 164 * 146 165 * @param string $plugin_slug The plugin slug. … … 162 181 wp_cache_delete( "{$user->user_login}_committer", 'wporg-plugins' ); 163 182 164 return $wpdb->delete( 165 PLUGINS_TABLE_PREFIX . 'svn_access', 166 array( 167 'path' => "/{$plugin_slug}", 168 'user' => $user->user_login, 169 ) 170 ); 183 return $wpdb->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array( 184 'path' => "/{$plugin_slug}", 185 'user' => $user->user_login, 186 ) ); 171 187 } 172 188 … … 177 193 * emails and cannot unsubscribe. 178 194 * 195 * @static 196 * 179 197 * @param string $plugin_slug The plugin to subscribe to. 180 * @param int|WP_User $user The user to subscribe. Default current user.181 * @param bool $subscribe Whether to subscribe (true) or unsubscribe (false).182 * 198 * @param int|WP_User $user Optional. The user to subscribe. Default current user. 199 * @param bool $subscribe Optional. Whether to subscribe (true) or unsubscribe (false). 200 * Default: true. 183 201 * @return bool Whether the user is subscribed. 184 202 */ … … 216 234 * function does not respect that status. 217 235 * 236 * @static 237 * 218 238 * @param string $plugin_slug The plugin to subscribe to. 219 * @param int|WP_User $user The user to check. Default current user. 220 * 239 * @param int|WP_User $user Optional. The user to check. Default current user. 221 240 * @return bool Whether the specified user is subscribed to commits. 222 241 */
Note: See TracChangeset
for help on using the changeset viewer.