Make WordPress Core

Changeset 8873


Ignore:
Timestamp:
09/12/2008 04:29:09 AM (16 years ago)
Author:
azaozz
Message:

Inline Documentation for user.php, props jacobsantos, fixes #5512

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r8600 r8873  
    11<?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 */
    325function wp_signon( $credentials = '', $secure_cookie = '' ) {
    426    if ( empty($credentials) ) {
     
    2749    // If no credential info provided, check cookie.
    2850    if ( empty($credentials['user_login']) && empty($credentials['user_password']) ) {
    29             $user = wp_validate_auth_cookie();
    30             if ( $user )
    31                 return new WP_User($user);
    32 
    33             if ( $secure_cookie )
    34                 $auth_cookie = SECURE_AUTH_COOKIE;
    35             else
    36                 $auth_cookie = AUTH_COOKIE;
    37 
    38             if ( !empty($_COOKIE[$auth_cookie]) )
    39                 return new WP_Error('expired_session', __('Please log in again.'));
    40 
    41             // If the cookie is not set, be silent.
    42             return new WP_Error();
     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();
    4365    }
    4466
     
    6284}
    6385
     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 */
    64107function get_profile($field, $user = false) {
    65108    global $wpdb;
     
    69112}
    70113
     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 */
    71123function get_usernumposts($userid) {
    72124    global $wpdb;
     
    75127}
    76128
    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 */
     139function user_pass_ok($user_login, $user_pass) {
    79140    $user = wp_authenticate($user_login, $user_pass);
    80141    if ( is_wp_error($user) )
     
    88149//
    89150
     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 */
    90172function get_user_option( $option, $user = 0 ) {
    91173    global $wpdb;
     
    107189}
    108190
     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 */
    109207function update_user_option( $user_id, $option_name, $newvalue, $global = false ) {
    110208    global $wpdb;
     
    114212}
    115213
    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 */
    118227function get_users_of_blog( $id = '' ) {
    119228    global $wpdb, $blog_id;
     
    128237//
    129238
     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 */
    130250function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) {
    131251    global $wpdb;
     
    148268}
    149269
     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 */
    150285function get_usermeta( $user_id, $meta_key = '') {
    151286    global $wpdb;
     
    182317}
    183318
     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 */
    184336function update_usermeta( $user_id, $meta_key, $meta_value ) {
    185337    global $wpdb;
     
    188340    $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
    189341
    190     // FIXME: usermeta data is assumed to be already escaped
     342    /** @todo Might need fix because usermeta data is assumed to be already escaped */
    191343    if ( is_string($meta_value) )
    192344        $meta_value = stripslashes($meta_value);
     
    217369//
    218370
    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 */
    220389function setup_userdata($user_id = '') {
    221390    global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity;
     
    239408}
    240409
     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 */
    241441function wp_dropdown_users( $args = '' ) {
    242442    global $wpdb;
     
    304504}
    305505
     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 */
    306520function _fill_user( &$user ) {
    307521    global $wpdb;
Note: See TracChangeset for help on using the changeset viewer.