Make WordPress Core

Ticket #25533: 25533.4.diff

File 25533.4.diff, 16.7 KB (added by kpdesign, 13 years ago)

Fourth pass

  • src/wp-includes/user.php

     
    3838                $credentials['remember'] = false;
    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, and can be modified by callback functions.
     45         *
     46         * @since 1.5.1
     47         *
     48         * @param string $user_login    Username, passed by reference.
     49         * @param string $user_password User password, passed by reference.
     50         */
     51        do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) );
    4252
    4353        if ( '' === $secure_cookie )
    4454                $secure_cookie = is_ssl();
    4555
    46         $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, $credentials);
     56        /**
     57         * Filter whether to use a secure sign-on cookie.
     58         *
     59         * @since 3.1.0
     60         *
     61         * @param bool  $secure_cookie Whether to use a secure sign-on cookie.
     62         * @param array $credentials {
     63         *     Array of entered sign-on data.
     64         *
     65         *     @type string $user_login    Username.
     66         *     @type string $user_password Password entered.
     67         *     @type bool   $remember      Whether to 'remember' the user. Increases the time
     68         *                                 that the cookie will be kept. Default false.
     69         * }
     70         */
     71        $secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials );
    4772
    4873        global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
    4974        $auth_secure_cookie = $secure_cookie;
     
    6186        }
    6287
    6388        wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie);
    64         do_action('wp_login', $user->user_login, $user);
     89        /**
     90         * Fires after the user has successfully logged in.
     91         *
     92         * @since 1.5.0
     93         *
     94         * @param string  $user_login Username.
     95         * @param WP_User $user       WP_User object of the logged-in user.
     96         */
     97        do_action( 'wp_login', $user->user_login, $user );
    6598        return $user;
    6699}
    67100
     
    92125        if ( !$user )
    93126                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() ) );
    94127
    95         $user = apply_filters('wp_authenticate_user', $user, $password);
     128        /**
     129         * Filter whether the given user can be authenticated with the provided $password.
     130         *
     131         * @since 2.5.0
     132         *
     133         * @param WP_User|WP_Error $user     WP_User object or WP_Error object if a previous
     134         *                                   callback failed authentication.
     135         * @param string           $password The password to check against the user.
     136         */
     137        $user = apply_filters( 'wp_authenticate_user', $user, $password );
    96138        if ( is_wp_error($user) )
    97139                return $user;
    98140
     
    138180 */
    139181function wp_authenticate_spam_check( $user ) {
    140182        if ( $user && is_a( $user, 'WP_User' ) && is_multisite() ) {
     183                /**
     184                 * Filter whether the user has been marked as a spammer.
     185                 *
     186                 * @since 3.7.0
     187                 *
     188                 * @param bool    $spammed Whether the user is considered spam.
     189                 * @param WP_User $user    The user to check against.
     190                 */
    141191                $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user );
    142192
    143193                if ( $spammed )
     
    162212
    163213        $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    164214
    165         return apply_filters('get_usernumposts', $count, $userid);
     215        /**
     216         * Filter the number of posts a user has written.
     217         *
     218         * @since 2.7.0
     219         *
     220         * @param int $count  The user's post count.
     221         * @param int $userid User ID.
     222         */
     223        return apply_filters( 'get_usernumposts', $count, $userid );
    166224}
    167225
    168226/**
     
    258316        else
    259317                $result = false;
    260318
    261         return apply_filters("get_user_option_{$option}", $result, $option, $user);
     319        /**
     320         * Filter a specific user option value.
     321         *
     322         * The dynamic portion of the hook name, $option, refers to the user option name.
     323         *
     324         * @since 2.5.0
     325         *
     326         * @param mixed   $result Value for the user's option.
     327         * @param string  $option Name of the option being retrieved.
     328         * @param WP_User $user   WP_User object of the user whose option is being retrieved.
     329         */
     330        return apply_filters( "get_user_option_{$option}", $result, $option, $user );
    262331}
    263332
    264333/**
     
    496565                                        $search_columns = array('user_login', 'user_nicename');
    497566                        }
    498567
     568                        /**
     569                         * Filter the columns to search in a WP_User_Query search.
     570                         *
     571                         * The default columns depend on the search term, and include 'user_email',
     572                         * 'user_login', 'ID', 'user_url', and 'user_nicename'.
     573                         *
     574                         * @since 3.6.0
     575                         *
     576                         * @param array         $search_columns Array of column names to be searched.
     577                         * @param string        $search         The text being searched.
     578                         * @param WP_User_Query $this           The current WP_User_Query instance.
     579                         */
    499580                        $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this );
    500581
    501582                        $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
     
    548629                        $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";
    549630                }
    550631
     632                /**
     633                 * Fires after the WP_User_Query has been parsed, and before
     634                 * the query is executed.
     635                 *
     636                 * The passed WP_User_Query object contains SQL parts formed
     637                 * from parsing the given query.
     638                 *
     639                 * @since 3.1.0
     640                 *
     641                 * @param WP_User_Query $this The current WP_User_Query instance,
     642                 *                            passed by reference.
     643                 */
    551644                do_action_ref_array( 'pre_user_query', array( &$this ) );
    552645        }
    553646
     
    568661                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
    569662                }
    570663
     664                /**
     665                 * Filter SELECT_FOUND_ROWS value for the current WP_User_Query instance.
     666                 *
     667                 * @since 3.2.0
     668                 *
     669                 * @global wpdb $wpdb WordPress database object.
     670                 *
     671                 * @param string $sql The SELECT_FOUND_ROWS() value for the current WP_User_Query.
     672                 */
    571673                if ( isset( $qv['count_total'] ) && $qv['count_total'] )
    572674                        $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
    573675
     
    776878                }
    777879        }
    778880
     881        /**
     882         * Filter the list of blogs a user belongs to.
     883         *
     884         * @since MU
     885         *
     886         * @param array $blogs   An array of blog objects belonging to the user.
     887         * @param int   $user_id User ID.
     888         * @param bool  $all     Whether the returned blogs array should contain all blogs, including
     889         *                       those marked 'deleted', 'archived', or 'spam'. Default false.
     890         */
    779891        return apply_filters( 'get_blogs_of_user', $blogs, $user_id, $all );
    780892}
    781893
     
    10951207                $output .= "</select>";
    10961208        }
    10971209
    1098         $output = apply_filters('wp_dropdown_users', $output);
     1210        /**
     1211         * Filter the wp_dropdown_users() HTML output.
     1212         *
     1213         * @since 2.3.0
     1214         *
     1215         * @param string $output HTML output generated by wp_dropdown_users().
     1216         */
     1217        $output = apply_filters( 'wp_dropdown_users', $output );
    10991218
    11001219        if ( $echo )
    11011220                echo $output;
     
    11401259
    11411260        if ( 'edit' == $context ) {
    11421261                if ( $prefixed ) {
    1143                         $value = apply_filters("edit_{$field}", $value, $user_id);
     1262                        /** This filter is documented in wp-includes/post.php */
     1263                        $value = apply_filters( "edit_{$field}", $value, $user_id );
    11441264                } else {
    1145                         $value = apply_filters("edit_user_{$field}", $value, $user_id);
     1265                        /**
     1266                         * Filter a user field value in the 'edit' context.
     1267                         *
     1268                         * The dynamic portion of the hook name, $field, refers to the prefixed user
     1269                         * field being filtered, such as 'user_login', 'user_email', 'first_name', etc.
     1270                         *
     1271                         * @since 2.9.0
     1272                         *
     1273                         * @param mixed $value   Value of the prefixed user field.
     1274                         * @param int   $user_id User ID.
     1275                         */
     1276                        $value = apply_filters( "edit_user_{$field}", $value, $user_id );
    11461277                }
    11471278
    11481279                if ( 'description' == $field )
     
    11511282                        $value = esc_attr($value);
    11521283        } else if ( 'db' == $context ) {
    11531284                if ( $prefixed ) {
    1154                         $value = apply_filters("pre_{$field}", $value);
     1285                        /** This filter is documented in wp-includes/post.php */
     1286                        $value = apply_filters( "pre_{$field}", $value );
    11551287                } else {
    1156                         $value = apply_filters("pre_user_{$field}", $value);
     1288                        /**
     1289                         * Filter the value of a user field in the 'db' context.
     1290                         *
     1291                         * The dynamic portion of the hook name, $field, refers to the prefixed user
     1292                         * field being filtered, such as 'user_login', 'user_email', 'first_name', etc.
     1293                         *
     1294                         * @since 2.9.0
     1295                         *
     1296                         * @param mixed $value Value of the prefixed user field.
     1297                         */
     1298                        $value = apply_filters( "pre_user_{$field}", $value );
    11571299                }
    11581300        } else {
    11591301                // 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);
     1302                if ( $prefixed ){
     1303                        /** This filter is documented in wp-includes/post.php */
     1304                        $value = apply_filters( $field, $value, $user_id, $context );
     1305                }else{
     1306                        /**
     1307                         * Filter the value of a user field in a standard context.
     1308                         *
     1309                         * The dynamic portion of the hook name, $field, refers to the prefixed user
     1310                         * field being filtered, such as 'user_login', 'user_email', 'first_name', etc.
     1311                         *
     1312                         * @since 2.9.0
     1313                         *
     1314                         * @param mixed  $value   The user object value to sanitize.
     1315                         * @param int    $user_id User ID.
     1316                         * @param string $context The context to filter within.
     1317                         */
     1318                        $value = apply_filters( "user_{$field}", $value, $user_id, $context );
     1319                }
    11641320        }
    11651321
    11661322        if ( 'user_url' == $field )
     
    12521408function validate_username( $username ) {
    12531409        $sanitized = sanitize_user( $username, true );
    12541410        $valid = ( $sanitized == $username );
     1411        /**
     1412         * Filter whether the provided username is valid or not.
     1413         *
     1414         * @since 2.0.1
     1415         *
     1416         * @param bool   $valid    Whether username given is valid. Default true.
     1417         * @param string $username The username to check.
     1418         */
    12551419        return apply_filters( 'validate_username', $valid, $username );
    12561420}
    12571421
     
    13171481        }
    13181482
    13191483        $user_login = sanitize_user($user_login, true);
    1320         $user_login = apply_filters('pre_user_login', $user_login);
     1484        /**
     1485         * Filter a username after it has been sanitized.
     1486         *
     1487         * This filter is called before the user is created or updated.
     1488         *
     1489         * @since 2.0.3
     1490         *
     1491         * @param string $user_login The username after it has been sanitized.
     1492         */
     1493        $user_login = apply_filters( 'pre_user_login', $user_login );
    13211494
    13221495        //Remove any non-printable chars from the login string to see if we have ended up with an empty username
    13231496        $user_login = trim($user_login);
     
    13301503
    13311504        if ( empty($user_nicename) )
    13321505                $user_nicename = sanitize_title( $user_login );
    1333         $user_nicename = apply_filters('pre_user_nicename', $user_nicename);
     1506        /**
     1507         * Filter a user's nicename before the user is created or updated.
     1508         *
     1509         * @since 2.0.3
     1510         *
     1511         * @param string $user_nicename The user's nicename.
     1512         */
     1513        $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
    13341514
    13351515        if ( empty($user_url) )
    13361516                $user_url = '';
    1337         $user_url = apply_filters('pre_user_url', $user_url);
     1517        /**
     1518         * Filter a user's URL before the user is created or updated.
     1519         *
     1520         * @since 2.0.3
     1521         *
     1522         * @param string $user_url The user's URL.
     1523         */
     1524        $user_url = apply_filters( 'pre_user_url', $user_url );
    13381525
    13391526        if ( empty($user_email) )
    13401527                $user_email = '';
    1341         $user_email = apply_filters('pre_user_email', $user_email);
     1528        /**
     1529         * Filter a user's email before the user is created or updated.
     1530         *
     1531         * @since 2.0.3
     1532         *
     1533         * @param string $user_email The user's email.
     1534         */
     1535        $user_email = apply_filters( 'pre_user_email', $user_email );
    13421536
    13431537        if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
    13441538                return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) );
     
    13451539
    13461540        if ( empty($nickname) )
    13471541                $nickname = $user_login;
    1348         $nickname = apply_filters('pre_user_nickname', $nickname);
     1542        /**
     1543         * Filter a user's nickname before the user is created or updated.
     1544         *
     1545         * @since 2.0.3
     1546         *
     1547         * @param string $nickname The user's nickname.
     1548         */
     1549        $nickname = apply_filters( 'pre_user_nickname', $nickname );
    13491550
    13501551        if ( empty($first_name) )
    13511552                $first_name = '';
    1352         $first_name = apply_filters('pre_user_first_name', $first_name);
     1553        /**
     1554         * Filter a user's first name before the user is created or updated.
     1555         *
     1556         * @since 2.0.3
     1557         *
     1558         * @param string $first_name The user's first name.
     1559         */
     1560        $first_name = apply_filters( 'pre_user_first_name', $first_name );
    13531561
    13541562        if ( empty($last_name) )
    13551563                $last_name = '';
    1356         $last_name = apply_filters('pre_user_last_name', $last_name);
     1564        /**
     1565         * Filter a user's last name before the user is created or updated.
     1566         *
     1567         * @since 2.0.3
     1568         *
     1569         * @param string $last_name The user's last name.
     1570         */
     1571        $last_name = apply_filters( 'pre_user_last_name', $last_name );
    13571572
    13581573        if ( empty( $display_name ) ) {
    13591574                if ( $update )
     
    13681583                else
    13691584                        $display_name = $user_login;
    13701585        }
     1586        /**
     1587         * Filter a user's display name before the user is created or updated.
     1588         *
     1589         * @since 2.0.3
     1590         *
     1591         * @param string $display_name The user's display name.
     1592         */
    13711593        $display_name = apply_filters( 'pre_user_display_name', $display_name );
    13721594
    13731595        if ( empty($description) )
    13741596                $description = '';
    1375         $description = apply_filters('pre_user_description', $description);
     1597        /**
     1598         * Filter a user's description before the user is created or updated.
     1599         *
     1600         * @since 2.0.3
     1601         *
     1602         * @param string $description The user's description.
     1603         */
     1604        $description = apply_filters( 'pre_user_description', $description );
    13761605
    13771606        if ( empty($rich_editing) )
    13781607                $rich_editing = 'true';
     
    14311660        wp_cache_delete($user_id, 'users');
    14321661        wp_cache_delete($user_login, 'userlogins');
    14331662
    1434         if ( $update )
    1435                 do_action('profile_update', $user_id, $old_user_data);
    1436         else
    1437                 do_action('user_register', $user_id);
     1663        if ( $update ) {
     1664                /**
     1665                 * Fires immediately after an existing user is updated.
     1666                 *
     1667                 * @since 2.0.0
     1668                 *
     1669                 * @param int    $user_id       User ID.
     1670                 * @param object $old_user_data Object containing user's data prior to update.
     1671                 */
     1672                do_action( 'profile_update', $user_id, $old_user_data );
     1673        } else {
     1674                /**
     1675                 * Fires immediately after a new user is registered.
     1676                 *
     1677                 * @since 1.5.0
     1678                 *
     1679                 * @param int $user_id User ID.
     1680                 */
     1681                do_action( 'user_register', $user_id );
     1682        }
    14381683
    14391684        return $user_id;
    14401685}
     
    16431888 * @param string $new_pass New password for the user in plaintext
    16441889 */
    16451890function reset_password( $user, $new_pass ) {
     1891        /**
     1892         * Fires before the user's password is reset.
     1893         *
     1894         * @since 1.5.0
     1895         *
     1896         * @param object $user     The user.
     1897         * @param string $new_pass New user password.
     1898         */
    16461899        do_action( 'password_reset', $user, $new_pass );
    16471900
    16481901        wp_set_password( $new_pass, $user->ID );
     
    16621915        $errors = new WP_Error();
    16631916
    16641917        $sanitized_user_login = sanitize_user( $user_login );
     1918        /**
     1919         * Filter the email address of a user being registered.
     1920         *
     1921         * @since 2.1.0
     1922         *
     1923         * @param string $user_email The email address of the new user.
     1924         */
    16651925        $user_email = apply_filters( 'user_registration_email', $user_email );
    16661926
    16671927        // Check the username
     
    16841944                $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );
    16851945        }
    16861946
     1947        /**
     1948         * Fires when submitting registration form data, before the user is created.
     1949         *
     1950         * @since 2.1.0
     1951         *
     1952         * @param string   $sanitized_user_login The submitted username after being sanitized.
     1953         * @param string   $user_email           The submitted email.
     1954         * @param WP_Error $errors               Contains any errors with submitted username and email,
     1955         *                                       e.g., an empty field, an invalid username or email,
     1956         *                                       or an existing username or email.
     1957         */
    16871958        do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
    16881959
     1960        /**
     1961         * Filter the errors encountered when a new user is being registered.
     1962         *
     1963         * The filtered WP_Error object may, for example, contain errors for an invalid
     1964         * or existing username or email address. A WP_Error object should always returned,
     1965         * but may or may not contain errors.
     1966         *
     1967         * If any errors are present in $errors, this will abort the user's registration.
     1968         *
     1969         * @since 2.1.0
     1970         *
     1971         * @param WP_Error $errors               A WP_Error object containing any errors encountered
     1972         *                                       during registration.
     1973         * @param string   $sanitized_user_login User's username after it has been sanitized.
     1974         * @param string   $user_email           User's email.
     1975         */
    16891976        $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
    16901977
    16911978        if ( $errors->get_error_code() )