Changeset 8873
- Timestamp:
- 09/12/2008 04:29:09 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/user.php
r8600 r8873 1 1 <?php 2 2 /** 3 * WordPress User API 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Authenticate user with remember capability. 10 * 11 * The credentials is an array that has 'user_login', 'user_password', and 12 * 'remember' indices. If the credentials is not given, then the log in form 13 * will be assumed and used if set. 14 * 15 * The various authentication cookies will be set by this function and will be 16 * set for a longer period depending on if the 'remember' credential is set to 17 * true. 18 * 19 * @since 2.5.0 20 * 21 * @param array $credentials Optional. User info in order to sign on. 22 * @param bool $secure_cookie Optional. Whether to use secure cookie. 23 * @return object Either WP_Error on failure, or WP_User on success. 24 */ 3 25 function wp_signon( $credentials = '', $secure_cookie = '' ) { 4 26 if ( empty($credentials) ) { … … 27 49 // If no credential info provided, check cookie. 28 50 if ( empty($credentials['user_login']) && empty($credentials['user_password']) ) { 29 30 31 32 33 34 35 36 37 38 39 40 41 42 51 $user = wp_validate_auth_cookie(); 52 if ( $user ) 53 return new WP_User($user); 54 55 if ( $secure_cookie ) 56 $auth_cookie = SECURE_AUTH_COOKIE; 57 else 58 $auth_cookie = AUTH_COOKIE; 59 60 if ( !empty($_COOKIE[$auth_cookie]) ) 61 return new WP_Error('expired_session', __('Please log in again.')); 62 63 // If the cookie is not set, be silent. 64 return new WP_Error(); 43 65 } 44 66 … … 62 84 } 63 85 86 /** 87 * Retrieve user data based on field. 88 * 89 * Use get_profile() will make a database query to get the value of the table 90 * column. The value might be cached using the query cache, but care should be 91 * taken when using the function to not make a lot of queries for retrieving 92 * user profile information. 93 * 94 * If the $user parameter is not used, then the user will be retrieved from a 95 * cookie of the user. Therefore, if the cookie does not exist, then no value 96 * might be returned. Sanity checking must be done to ensure that when using 97 * get_profile() that empty/null/false values are handled and that something is 98 * at least displayed. 99 * 100 * @since 1.5.0 101 * @uses $wpdb WordPress database object to create queries. 102 * 103 * @param string $field User field to retrieve. 104 * @param string $user Optional. User username. 105 * @return string The value in the field. 106 */ 64 107 function get_profile($field, $user = false) { 65 108 global $wpdb; … … 69 112 } 70 113 114 /** 115 * Number of posts user has written. 116 * 117 * @since 0.71 118 * @uses $wpdb WordPress database object for queries. 119 * 120 * @param int $userid User ID. 121 * @return int Amount of posts user has written. 122 */ 71 123 function get_usernumposts($userid) { 72 124 global $wpdb; … … 75 127 } 76 128 77 // TODO: xmlrpc only. Maybe move to xmlrpc.php. 78 function user_pass_ok($user_login,$user_pass) { 129 /** 130 * Check that the user login name and password is correct. 131 * 132 * @since 0.71 133 * @todo xmlrpc only. Maybe move to xmlrpc.php. 134 * 135 * @param string $user_login User name. 136 * @param string $user_pass User password. 137 * @return bool False if does not authenticate, true if username and password authenticates. 138 */ 139 function user_pass_ok($user_login, $user_pass) { 79 140 $user = wp_authenticate($user_login, $user_pass); 80 141 if ( is_wp_error($user) ) … … 88 149 // 89 150 151 /** 152 * Retrieve user option that can be either global, user, or blog. 153 * 154 * If the user ID is not given, then the current user will be used instead. If 155 * the user ID is given, then the user data will be retrieved. The filter for 156 * the result, will also pass the original option name and finally the user data 157 * object as the third parameter. 158 * 159 * The option will first check for the non-global name, then the global name, 160 * and if it still doesn't find it, it will try the blog option. The option can 161 * either be modified or set by a plugin. 162 * 163 * @since 2.0.0 164 * @uses $wpdb WordPress database object for queries. 165 * @uses apply_filters() Calls 'get_user_option_$option' hook with result, 166 * option parameter, and user data object. 167 * 168 * @param string $option User option name. 169 * @param int $user Optional. User ID. 170 * @return mixed 171 */ 90 172 function get_user_option( $option, $user = 0 ) { 91 173 global $wpdb; … … 107 189 } 108 190 191 /** 192 * Update user option with global blog capability. 193 * 194 * User options are just like user metadata except that they have support for 195 * global blog options. If the 'global' parameter is false, which it is by false 196 * it will prepend the WordPress table prefix to the option name. 197 * 198 * @since 2.0.0 199 * @uses $wpdb WordPress database object for queries 200 * 201 * @param int $user_id User ID 202 * @param string $option_name User option name. 203 * @param mixed $newvalue User option value. 204 * @param bool $global Optional. Whether option name is blog specific or not. 205 * @return unknown 206 */ 109 207 function update_user_option( $user_id, $option_name, $newvalue, $global = false ) { 110 208 global $wpdb; … … 114 212 } 115 213 116 // Get users with capabilities for the current blog. 117 // For setups that use the multi-blog feature. 214 /** 215 * Get users for the blog. 216 * 217 * For setups that use the multi-blog feature. Can be used outside of the 218 * multi-blog feature. 219 * 220 * @since 2.2.0 221 * @uses $wpdb WordPress database object for queries 222 * @uses $blog_id The Blog id of the blog for those that use more than one blog 223 * 224 * @param int $id Blog ID. 225 * @return array List of users that are part of that Blog ID 226 */ 118 227 function get_users_of_blog( $id = '' ) { 119 228 global $wpdb, $blog_id; … … 128 237 // 129 238 239 /** 240 * Remove user meta data. 241 * 242 * @since 2.0.0 243 * @uses $wpdb WordPress database object for queries. 244 * 245 * @param int $user_id User ID. 246 * @param string $meta_key Metadata key. 247 * @param mixed $meta_value Metadata value. 248 * @return bool True deletion completed and false if user_id is not a number. 249 */ 130 250 function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) { 131 251 global $wpdb; … … 148 268 } 149 269 270 /** 271 * Retrieve user metadata. 272 * 273 * If $user_id is not a number, then the function will fail over with a 'false' 274 * boolean return value. Other returned values depend on whether there is only 275 * one item to be returned, which be that single item type. If there is more 276 * than one metadata value, then it will be list of metadata values. 277 * 278 * @since 2.0.0 279 * @uses $wpdb WordPress database object for queries. 280 * 281 * @param int $user_id User ID 282 * @param string $meta_key Optional. Metadata key. 283 * @return mixed 284 */ 150 285 function get_usermeta( $user_id, $meta_key = '') { 151 286 global $wpdb; … … 182 317 } 183 318 319 /** 320 * Update metadata of user. 321 * 322 * There is no need to serialize values, they will be serialized if it is 323 * needed. The metadata key can only be a string with underscores. All else will 324 * be removed. 325 * 326 * Will remove the metadata, if the meta value is empty. 327 * 328 * @since 2.0.0 329 * @uses $wpdb WordPress database object for queries 330 * 331 * @param int $user_id User ID 332 * @param string $meta_key Metadata key. 333 * @param mixed $meta_value Metadata value. 334 * @return bool True on successful update, false on failure. 335 */ 184 336 function update_usermeta( $user_id, $meta_key, $meta_value ) { 185 337 global $wpdb; … … 188 340 $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key); 189 341 190 / / FIXME: usermeta data is assumed to be already escaped342 /** @todo Might need fix because usermeta data is assumed to be already escaped */ 191 343 if ( is_string($meta_value) ) 192 344 $meta_value = stripslashes($meta_value); … … 217 369 // 218 370 219 // Setup global user vars. Used by set_current_user() for back compat. 371 /** 372 * Setup global user vars. 373 * 374 * Used by set_current_user() for back compat. Might be deprecated in the 375 * future. 376 * 377 * @since 2.0.4 378 * @global string $userdata User description. 379 * @global string $user_login The user username for logging in 380 * @global int $user_level The level of the user 381 * @global int $user_ID The ID of the user 382 * @global string $user_email The email address of the user 383 * @global string $user_url The url in the user's profile 384 * @global string $user_pass_md5 MD5 of the user's password 385 * @global string $user_identity The display name of the user 386 * 387 * @param int $user_id Optional. User ID to setup global data. 388 */ 220 389 function setup_userdata($user_id = '') { 221 390 global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity; … … 239 408 } 240 409 410 /** 411 * Create dropdown HTML content of users. 412 * 413 * The content can either be displayed, which it is by default or retrieved by 414 * setting the 'echo' argument. The 'include' and 'exclude' arguments do not 415 * need to be used; all users will be displayed in that case. Only one can be 416 * used, either 'include' or 'exclude', but not both. 417 * 418 * The available arguments are as follows: 419 * <ol> 420 * <li>show_option_all - Text to show all and whether HTML option exists.</li> 421 * <li>show_option_none - Text for show none and whether HTML option exists. 422 * </li> 423 * <li>orderby - SQL order by clause for what order the users appear. Default is 424 * 'display_name'.</li> 425 * <li>order - Default is 'ASC'. Can also be 'DESC'.</li> 426 * <li>include - User IDs to include.</li> 427 * <li>exclude - User IDs to exclude.</li> 428 * <li>show - Default is 'display_name'. User table column to display.</li> 429 * <li>echo - Default is '1'. Whether to display or retrieve content.</li> 430 * <li>selected - Which User ID is selected.</li> 431 * <li>name - Default is 'user'. Name attribute of select element.</li> 432 * <li>class - Class attribute of select element.</li> 433 * </ol> 434 * 435 * @since 2.3.0 436 * @uses $wpdb WordPress database object for queries 437 * 438 * @param string|array $args Optional. Override defaults. 439 * @return string|null Null on display. String of HTML content on retrieve. 440 */ 241 441 function wp_dropdown_users( $args = '' ) { 242 442 global $wpdb; … … 304 504 } 305 505 506 /** 507 * Add user meta data as properties to given user object. 508 * 509 * The finished user data is cached, but the cache is not used to fill in the 510 * user data for the given object. Once the function has been used, the cache 511 * should be used to retrieve user data. The purpose seems then to be to ensure 512 * that the data in the object is always fresh. 513 * 514 * @access private 515 * @since 2.5.0 516 * @uses $wpdb WordPress database object for queries 517 * 518 * @param object $user The user data object. 519 */ 306 520 function _fill_user( &$user ) { 307 521 global $wpdb;
Note: See TracChangeset
for help on using the changeset viewer.