Make WordPress Core

Changeset 26901


Ignore:
Timestamp:
01/04/2014 06:17:18 AM (13 years ago)
Author:
DrewAPicture
Message:

Inline documentation for hooks in wp-includes/user.php.

Props stephenharris, kpdesign.
Fixes #25533.

File:
1 edited

Legend:

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

    r26493 r26901  
    3939
    4040        // TODO do we deprecate the wp_authentication action?
    41         do_action_ref_array('wp_authenticate', array(&$credentials['user_login'], &$credentials['user_password']));
     41        /**
     42         * Fires before the user is authenticated.
     43         *
     44         * The variables passed to the callbacks are passed by reference,
     45         * and can be modified by callback functions.
     46         *
     47         * @since 1.5.1
     48         *
     49         * @param string $user_login    Username, passed by reference.
     50         * @param string $user_password User password, passed by reference.
     51         */
     52        do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) );
    4253
    4354        if ( '' === $secure_cookie )
    4455                $secure_cookie = is_ssl();
    4556
    46         $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, $credentials);
     57        /**
     58         * Filter whether to use a secure sign-on cookie.
     59         *
     60         * @since 3.1.0
     61         *
     62         * @param bool  $secure_cookie Whether to use a secure sign-on cookie.
     63         * @param array $credentials {
     64         *     Array of entered sign-on data.
     65         *
     66         *     @type string $user_login    Username.
     67         *     @type string $user_password Password entered.
     68         *     @type bool   $remember      Whether to 'remember' the user. Increases the time
     69         *                                 that the cookie will be kept. Default false.
     70         * }
     71         */
     72        $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials );
    4773
    4874        global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
     
    6288
    6389        wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie);
    64         do_action('wp_login', $user->user_login, $user);
     90        /**
     91         * Fires after the user has successfully logged in.
     92         *
     93         * @since 1.5.0
     94         *
     95         * @param string  $user_login Username.
     96         * @param WP_User $user       WP_User object of the logged-in user.
     97         */
     98        do_action( 'wp_login', $user->user_login, $user );
    6599        return $user;
    66100}
     
    93127                return new WP_Error( 'invalid_username', sprintf( __( '<strong>ERROR</strong>: Invalid username. <a href="%s" title="Password Lost and Found">Lost your password</a>?' ), wp_lostpassword_url() ) );
    94128
    95         $user = apply_filters('wp_authenticate_user', $user, $password);
     129        /**
     130         * Filter whether the given user can be authenticated with the provided $password.
     131         *
     132         * @since 2.5.0
     133         *
     134         * @param WP_User|WP_Error $user     WP_User or WP_Error object if a previous
     135         *                                   callback failed authentication.
     136         * @param string           $password Password to check against the user.
     137         */
     138        $user = apply_filters( 'wp_authenticate_user', $user, $password );
    96139        if ( is_wp_error($user) )
    97140                return $user;
     
    139182function wp_authenticate_spam_check( $user ) {
    140183        if ( $user && is_a( $user, 'WP_User' ) && is_multisite() ) {
     184                /**
     185                 * Filter whether the user has been marked as a spammer.
     186                 *
     187                 * @since 3.7.0
     188                 *
     189                 * @param bool    $spammed Whether the user is considered a spammer.
     190                 * @param WP_User $user    User to check against.
     191                 */
    141192                $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user );
    142193
     
    163214        $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    164215
    165         return apply_filters('get_usernumposts', $count, $userid);
     216        /**
     217         * Filter the number of posts a user has written.
     218         *
     219         * @since 2.7.0
     220         *
     221         * @param int $count  The user's post count.
     222         * @param int $userid User ID.
     223         */
     224        return apply_filters( 'get_usernumposts', $count, $userid );
    166225}
    167226
     
    259318                $result = false;
    260319
    261         return apply_filters("get_user_option_{$option}", $result, $option, $user);
     320        /**
     321         * Filter a specific user option value.
     322         *
     323         * The dynamic portion of the hook name, $option, refers to the user option name.
     324         *
     325         * @since 2.5.0
     326         *
     327         * @param mixed   $result Value for the user's option.
     328         * @param string  $option Name of the option being retrieved.
     329         * @param WP_User $user   WP_User object of the user whose option is being retrieved.
     330         */
     331        return apply_filters( "get_user_option_{$option}", $result, $option, $user );
    262332}
    263333
     
    497567                        }
    498568
     569                        /**
     570                         * Filter the columns to search in a WP_User_Query search.
     571                         *
     572                         * The default columns depend on the search term, and include 'user_email',
     573                         * 'user_login', 'ID', 'user_url', and 'user_nicename'.
     574                         *
     575                         * @since 3.6.0
     576                         *
     577                         * @param array         $search_columns Array of column names to be searched.
     578                         * @param string        $search         Text being searched.
     579                         * @param WP_User_Query $this           The current WP_User_Query instance.
     580                         */
    499581                        $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this );
    500582
     
    549631                }
    550632
     633                /**
     634                 * Fires after the WP_User_Query has been parsed, and before
     635                 * the query is executed.
     636                 *
     637                 * The passed WP_User_Query object contains SQL parts formed
     638                 * from parsing the given query.
     639                 *
     640                 * @since 3.1.0
     641                 *
     642                 * @param WP_User_Query $this The current WP_User_Query instance,
     643                 *                            passed by reference.
     644                 */
    551645                do_action_ref_array( 'pre_user_query', array( &$this ) );
    552646        }
     
    569663                }
    570664
     665                /**
     666                 * Filter SELECT_FOUND_ROWS value for the current WP_User_Query instance.
     667                 *
     668                 * @since 3.2.0
     669                 *
     670                 * @global wpdb $wpdb WordPress database object.
     671                 *
     672                 * @param string $sql The SELECT_FOUND_ROWS() value for the current WP_User_Query.
     673                 */
    571674                if ( isset( $qv['count_total'] ) && $qv['count_total'] )
    572675                        $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
     
    777880        }
    778881
     882        /**
     883         * Filter the list of blogs a user belongs to.
     884         *
     885         * @since MU
     886         *
     887         * @param array $blogs   An array of blog objects belonging to the user.
     888         * @param int   $user_id User ID.
     889         * @param bool  $all     Whether the returned blogs array should contain all blogs, including
     890         *                       those marked 'deleted', 'archived', or 'spam'. Default false.
     891         */
    779892        return apply_filters( 'get_blogs_of_user', $blogs, $user_id, $all );
    780893}
     
    10961209        }
    10971210
    1098         $output = apply_filters('wp_dropdown_users', $output);
     1211        /**
     1212         * Filter the wp_dropdown_users() HTML output.
     1213         *
     1214         * @since 2.3.0
     1215         *
     1216         * @param string $output HTML output generated by wp_dropdown_users().
     1217         */
     1218        $output = apply_filters( 'wp_dropdown_users', $output );
    10991219
    11001220        if ( $echo )
     
    11411261        if ( 'edit' == $context ) {
    11421262                if ( $prefixed ) {
    1143                         $value = apply_filters("edit_{$field}", $value, $user_id);
     1263                        /** This filter is documented in wp-includes/post.php */
     1264                        $value = apply_filters( "edit_{$field}", $value, $user_id );
    11441265                } else {
    1145                         $value = apply_filters("edit_user_{$field}", $value, $user_id);
     1266                        /**
     1267                         * Filter a user field value in the 'edit' context.
     1268                         *
     1269                         * The dynamic portion of the hook name, $field, refers to the prefixed user
     1270                         * field being filtered, such as 'user_login', 'user_email', 'first_name', etc.
     1271                         *
     1272                         * @since 2.9.0
     1273                         *
     1274                         * @param mixed $value   Value of the prefixed user field.
     1275                         * @param int   $user_id User ID.
     1276                         */
     1277                        $value = apply_filters( "edit_user_{$field}", $value, $user_id );
    11461278                }
    11471279
     
    11521284        } else if ( 'db' == $context ) {
    11531285                if ( $prefixed ) {
    1154                         $value = apply_filters("pre_{$field}", $value);
     1286                        /** This filter is documented in wp-includes/post.php */
     1287                        $value = apply_filters( "pre_{$field}", $value );
    11551288                } else {
    1156                         $value = apply_filters("pre_user_{$field}", $value);
     1289                        /**
     1290                         * Filter the value of a user field in the 'db' context.
     1291                         *
     1292                         * The dynamic portion of the hook name, $field, refers to the prefixed user
     1293                         * field being filtered, such as 'user_login', 'user_email', 'first_name', etc.
     1294                         *
     1295                         * @since 2.9.0
     1296                         *
     1297                         * @param mixed $value Value of the prefixed user field.
     1298                         */
     1299                        $value = apply_filters( "pre_user_{$field}", $value );
    11571300                }
    11581301        } else {
    11591302                // Use display filters by default.
    1160                 if ( $prefixed )
    1161                         $value = apply_filters($field, $value, $user_id, $context);
    1162                 else
    1163                         $value = apply_filters("user_{$field}", $value, $user_id, $context);
     1303                if ( $prefixed ){
     1304                        /** This filter is documented in wp-includes/post.php */
     1305                        $value = apply_filters( $field, $value, $user_id, $context );
     1306                }else{
     1307                        /**
     1308                         * Filter the value of a user field in a standard context.
     1309                         *
     1310                         * The dynamic portion of the hook name, $field, refers to the prefixed user
     1311                         * field being filtered, such as 'user_login', 'user_email', 'first_name', etc.
     1312                         *
     1313                         * @since 2.9.0
     1314                         *
     1315                         * @param mixed  $value   The user object value to sanitize.
     1316                         * @param int    $user_id User ID.
     1317                         * @param string $context The context to filter within.
     1318                         */
     1319                        $value = apply_filters( "user_{$field}", $value, $user_id, $context );
     1320                }
    11641321        }
    11651322
     
    12531410        $sanitized = sanitize_user( $username, true );
    12541411        $valid = ( $sanitized == $username );
     1412        /**
     1413         * Filter whether the provided username is valid or not.
     1414         *
     1415         * @since 2.0.1
     1416         *
     1417         * @param bool   $valid    Whether given username is valid.
     1418         * @param string $username Username to check.
     1419         */
    12551420        return apply_filters( 'validate_username', $valid, $username );
    12561421}
     
    13181483
    13191484        $user_login = sanitize_user($user_login, true);
    1320         $user_login = apply_filters('pre_user_login', $user_login);
     1485        /**
     1486         * Filter a username after it has been sanitized.
     1487         *
     1488         * This filter is called before the user is created or updated.
     1489         *
     1490         * @since 2.0.3
     1491         *
     1492         * @param string $user_login Username after it has been sanitized.
     1493         */
     1494        $user_login = apply_filters( 'pre_user_login', $user_login );
    13211495
    13221496        //Remove any non-printable chars from the login string to see if we have ended up with an empty username
     
    13311505        if ( empty($user_nicename) )
    13321506                $user_nicename = sanitize_title( $user_login );
    1333         $user_nicename = apply_filters('pre_user_nicename', $user_nicename);
     1507        /**
     1508         * Filter a user's nicename before the user is created or updated.
     1509         *
     1510         * @since 2.0.3
     1511         *
     1512         * @param string $user_nicename The user's nicename.
     1513         */
     1514        $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
    13341515
    13351516        if ( empty($user_url) )
    13361517                $user_url = '';
    1337         $user_url = apply_filters('pre_user_url', $user_url);
     1518        /**
     1519         * Filter a user's URL before the user is created or updated.
     1520         *
     1521         * @since 2.0.3
     1522         *
     1523         * @param string $user_url The user's URL.
     1524         */
     1525        $user_url = apply_filters( 'pre_user_url', $user_url );
    13381526
    13391527        if ( empty($user_email) )
    13401528                $user_email = '';
    1341         $user_email = apply_filters('pre_user_email', $user_email);
     1529        /**
     1530         * Filter a user's email before the user is created or updated.
     1531         *
     1532         * @since 2.0.3
     1533         *
     1534         * @param string $user_email The user's email.
     1535         */
     1536        $user_email = apply_filters( 'pre_user_email', $user_email );
    13421537
    13431538        if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
     
    13461541        if ( empty($nickname) )
    13471542                $nickname = $user_login;
    1348         $nickname = apply_filters('pre_user_nickname', $nickname);
     1543        /**
     1544         * Filter a user's nickname before the user is created or updated.
     1545         *
     1546         * @since 2.0.3
     1547         *
     1548         * @param string $nickname The user's nickname.
     1549         */
     1550        $nickname = apply_filters( 'pre_user_nickname', $nickname );
    13491551
    13501552        if ( empty($first_name) )
    13511553                $first_name = '';
    1352         $first_name = apply_filters('pre_user_first_name', $first_name);
     1554        /**
     1555         * Filter a user's first name before the user is created or updated.
     1556         *
     1557         * @since 2.0.3
     1558         *
     1559         * @param string $first_name The user's first name.
     1560         */
     1561        $first_name = apply_filters( 'pre_user_first_name', $first_name );
    13531562
    13541563        if ( empty($last_name) )
    13551564                $last_name = '';
    1356         $last_name = apply_filters('pre_user_last_name', $last_name);
     1565        /**
     1566         * Filter a user's last name before the user is created or updated.
     1567         *
     1568         * @since 2.0.3
     1569         *
     1570         * @param string $last_name The user's last name.
     1571         */
     1572        $last_name = apply_filters( 'pre_user_last_name', $last_name );
    13571573
    13581574        if ( empty( $display_name ) ) {
     
    13691585                        $display_name = $user_login;
    13701586        }
     1587        /**
     1588         * Filter a user's display name before the user is created or updated.
     1589         *
     1590         * @since 2.0.3
     1591         *
     1592         * @param string $display_name The user's display name.
     1593         */
    13711594        $display_name = apply_filters( 'pre_user_display_name', $display_name );
    13721595
    13731596        if ( empty($description) )
    13741597                $description = '';
    1375         $description = apply_filters('pre_user_description', $description);
     1598        /**
     1599         * Filter a user's description before the user is created or updated.
     1600         *
     1601         * @since 2.0.3
     1602         *
     1603         * @param string $description The user's description.
     1604         */
     1605        $description = apply_filters( 'pre_user_description', $description );
    13761606
    13771607        if ( empty($rich_editing) )
     
    14321662        wp_cache_delete($user_login, 'userlogins');
    14331663
    1434         if ( $update )
    1435                 do_action('profile_update', $user_id, $old_user_data);
    1436         else
    1437                 do_action('user_register', $user_id);
     1664        if ( $update ) {
     1665                /**
     1666                 * Fires immediately after an existing user is updated.
     1667                 *
     1668                 * @since 2.0.0
     1669                 *
     1670                 * @param int    $user_id       User ID.
     1671                 * @param object $old_user_data Object containing user's data prior to update.
     1672                 */
     1673                do_action( 'profile_update', $user_id, $old_user_data );
     1674        } else {
     1675                /**
     1676                 * Fires immediately after a new user is registered.
     1677                 *
     1678                 * @since 1.5.0
     1679                 *
     1680                 * @param int $user_id User ID.
     1681                 */
     1682                do_action( 'user_register', $user_id );
     1683        }
    14381684
    14391685        return $user_id;
     
    16441890 */
    16451891function reset_password( $user, $new_pass ) {
     1892        /**
     1893         * Fires before the user's password is reset.
     1894         *
     1895         * @since 1.5.0
     1896         *
     1897         * @param object $user     The user.
     1898         * @param string $new_pass New user password.
     1899         */
    16461900        do_action( 'password_reset', $user, $new_pass );
    16471901
     
    16631917
    16641918        $sanitized_user_login = sanitize_user( $user_login );
     1919        /**
     1920         * Filter the email address of a user being registered.
     1921         *
     1922         * @since 2.1.0
     1923         *
     1924         * @param string $user_email The email address of the new user.
     1925         */
    16651926        $user_email = apply_filters( 'user_registration_email', $user_email );
    16661927
     
    16851946        }
    16861947
     1948        /**
     1949         * Fires when submitting registration form data, before the user is created.
     1950         *
     1951         * @since 2.1.0
     1952         *
     1953         * @param string   $sanitized_user_login The submitted username after being sanitized.
     1954         * @param string   $user_email           The submitted email.
     1955         * @param WP_Error $errors               Contains any errors with submitted username and email,
     1956         *                                       e.g., an empty field, an invalid username or email,
     1957         *                                       or an existing username or email.
     1958         */
    16871959        do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
    16881960
     1961        /**
     1962         * Filter the errors encountered when a new user is being registered.
     1963         *
     1964         * The filtered WP_Error object may, for example, contain errors for an invalid
     1965         * or existing username or email address. A WP_Error object should always returned,
     1966         * but may or may not contain errors.
     1967         *
     1968         * If any errors are present in $errors, this will abort the user's registration.
     1969         *
     1970         * @since 2.1.0
     1971         *
     1972         * @param WP_Error $errors               A WP_Error object containing any errors encountered
     1973         *                                       during registration.
     1974         * @param string   $sanitized_user_login User's username after it has been sanitized.
     1975         * @param string   $user_email           User's email.
     1976         */
    16891977        $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
    16901978
Note: See TracChangeset for help on using the changeset viewer.