Make WordPress Core

Ticket #25533: 25533.diff

File 25533.diff, 15.2 KB (added by stephenharris, 13 years ago)

Adds in-line documentation

  • wp-includes/user.php

    diff --git wp-includes/user.php wp-includes/user.php
    index 9a60cd2..1bab48f 100644
    function wp_signon( $credentials = '', $secure_cookie = '' ) {  
    3838                $credentials['remember'] = false;
    3939
    4040        // TODO do we deprecate the wp_authentication action?
     41        /**
     42         * Triggered before the user is logged in.
     43         *
     44         * The variables passed to the callbacks are passed by reference and can be modified by callback functions.
     45         * @since 1.5.2
     46         *
     47         * @param string $user_login
     48         * @param string $user_password
     49         */
    4150        do_action_ref_array('wp_authenticate', array(&$credentials['user_login'], &$credentials['user_password']));
    4251
    4352        if ( '' === $secure_cookie )
    4453                $secure_cookie = is_ssl();
    4554
     55        /**
     56         * Filters whether the sign-on cookie should only be transmitted over a secure HTTPS
     57         * connection from the client.
     58         *
     59         * @since 3.1.0
     60         *
     61         * @param bool $secure_cookie When set to true, the cookie will only be set if a secure connection exists.
     62         * @param array $args {
     63         *     User credentials,
     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 that the cookie will be kept.
     68         * }
     69         */
    4670        $secure_cookie = apply_filters('secure_signon_cookie', $secure_cookie, $credentials);
    4771
    4872        global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
    function wp_signon( $credentials = '', $secure_cookie = '' ) {  
    6185        }
    6286
    6387        wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie);
     88       
     89        /**
     90         * Triggered after the user has successfully logged in.
     91         *
     92         * @since 1.5.2
     93         *
     94         * @param string $user_login The user's usersname
     95         * @param WP_User $user The logged-in user
     96         */
    6497        do_action('wp_login', $user->user_login, $user);
    6598        return $user;
    6699}
    function wp_authenticate_username_password($user, $username, $password) {  
    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
     128        /**
     129         * Returns either a WP_User or WP_Error object depending on whether the given user can be authenticated with the provided $password.
     130         *
     131         * This allows plug-ins to add additional authentication conditions. Please note that the filtered value is originally a WP_User,
     132         * but hooked callbacks may recieve a WP_Error if authentication has failed in an earlier callback.
     133         *
     134         * @since 2.5.0
     135         *
     136         * @param WP_User|WP_Error The user to authenticate as a WP_User object or a WP_Error object if a previous callback as 'failed' the authentication.
     137         * @param string $password The password to check against the user.
     138         */
    95139        $user = apply_filters('wp_authenticate_user', $user, $password);
    96140        if ( is_wp_error($user) )
    97141                return $user;
    function wp_authenticate_cookie($user, $username, $password) {  
    138182 */
    139183function wp_authenticate_spam_check( $user ) {
    140184        if ( $user && is_a( $user, 'WP_User' ) && is_multisite() ) {
     185                /**
     186                 * Filters whether the user has been marked as a spammer.
     187                 *
     188                 * @since 3.7.0
     189                 *
     190                 * @param bool $spammed True if the user is considered a spammer.
     191                 * @param WP_User $user The user to check against.
     192                 */
    141193                $spammed = apply_filters( 'check_is_user_spammed', is_user_spammy(), $user );
    142194
    143195                if ( $spammed )
    function count_user_posts($userid) {  
    162214
    163215        $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    164216
     217        /**
     218         * Filters the number of posts a user has written.
     219         *
     220         * @since 2.7.0
     221         *
     222         * @param int $count The number of posts the user has posted.
     223         * @param int $userid The ID of the user.
     224         */
    165225        return apply_filters('get_usernumposts', $count, $userid);
    166226}
    167227
    function get_user_option( $option, $user = 0, $deprecated = '' ) {  
    256316        else
    257317                $result = false;
    258318
     319        /**
     320         * Filter a specific option value for a user.
     321         *
     322         * @since 2.5.0
     323         *
     324         * @param mixed The value for the user's option.
     325         * @param string $option The name of the option being retrieved.
     326         * @param WP_User $user User object of the user whose option is being retrieved.
     327         */
    259328        return apply_filters("get_user_option_{$option}", $result, $option, $user);
    260329}
    261330
    class WP_User_Query {  
    494563                                        $search_columns = array('user_login', 'user_nicename');
    495564                        }
    496565
     566                        /**
     567                         * Filters the columns which are searched in a WP_User_Query search.
     568                         *
     569                         * @since 3.6.0
     570                         *
     571                         * @param array $search_columns Array of column names to be searched.
     572                         * @param string $search The term being searched.
     573                         * @param WP_User_Query $this The user query.
     574                         */
    497575                        $search_columns = apply_filters( 'user_search_columns', $search_columns, $search, $this );
    498576
    499577                        $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
    class WP_User_Query {  
    546624                        $this->query_where .= " AND $wpdb->users.ID NOT IN ($ids)";
    547625                }
    548626
     627                /**
     628                 * Triggered after the WP_User_Query has been parsed and before the query is executed.
     629                 *
     630                 * The WP_User_Query is passed by reference and can be modified. It contains SQL
     631                 * parts formed from parsing WP_User_Query.
     632                 *
     633                 * @since 1.5.2
     634                 *
     635                 * @param WP_User_Query $this The user query.
     636                 */
    549637                do_action_ref_array( 'pre_user_query', array( &$this ) );
    550638        }
    551639
    class WP_User_Query {  
    566654                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
    567655                }
    568656
     657                /**
     658                 * Filters the SQL command for number of users matching the WP_User_Query
     659                 *
     660                 * @since 3.2.0
     661                 *
     662                 * @param string $sql
     663                 */
    569664                if ( isset( $qv['count_total'] ) && $qv['count_total'] )
    570665                        $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) );
    571666
    function get_blogs_of_user( $user_id, $all = false ) {  
    774869                }
    775870        }
    776871
     872        /**
     873         * Filters the blogs belonging to the specified user.
     874         *
     875         * @since 3.1.0
     876         *
     877         * @param array An array of blog objects belonging to the user.
     878         * @param int $user_id The ID of the user.
     879         * @param bool $all True if $blogs should conain all blogs, false if it should only contain blogs that are not marked as deleted, archived, or spam.
     880         */
    777881        return apply_filters( 'get_blogs_of_user', $blogs, $user_id, $all );
    778882}
    779883
    function wp_dropdown_users( $args = '' ) {  
    10921196
    10931197                $output .= "</select>";
    10941198        }
    1095 
     1199       
     1200        /**
     1201         * Filters the HTML of a dropdown of users.
     1202         *
     1203         * @since 2.3.0
     1204         *
     1205         * @param string HTML generated by `wp_dropdown_users()`.
     1206         */
    10961207        $output = apply_filters('wp_dropdown_users', $output);
    10971208
    10981209        if ( $echo )
    function sanitize_user_field($field, $value, $user_id, $context) {  
    11381249
    11391250        if ( 'edit' == $context ) {
    11401251                if ( $prefixed ) {
     1252                        /**
     1253                         * Filter and sanitize the value of the prefixed field (for editing).
     1254                         *
     1255                         * @since 2.3.0
     1256                         *
     1257                         * @param mixed $value The user object value to sanitize.
     1258                         * @param int $user_id The user ID.
     1259                         */
    11411260                        $value = apply_filters("edit_{$field}", $value, $user_id);
    11421261                } else {
     1262                        /**
     1263                         * Non prefixed version...
     1264                         * @since 2.9.0
     1265                         * @see edit_user_{$field} filter above
     1266                         */
    11431267                        $value = apply_filters("edit_user_{$field}", $value, $user_id);
    11441268                }
    11451269
    function sanitize_user_field($field, $value, $user_id, $context) {  
    11491273                        $value = esc_attr($value);
    11501274        } else if ( 'db' == $context ) {
    11511275                if ( $prefixed ) {
     1276                        /**
     1277                         * Filter and sanitize the value of the prefixed field (for database use).
     1278                         *
     1279                         * @since 2.3.0
     1280                         *
     1281                         * @param mixed $value The user object value to sanitize.
     1282                         */
    11521283                        $value = apply_filters("pre_{$field}", $value);
    11531284                } else {
     1285                        /**
     1286                         * Non prefixed version...
     1287                         * @see pre_user_{$field} filter above
     1288                         * @since 2.9.0
     1289                         */
    11541290                        $value = apply_filters("pre_user_{$field}", $value);
    11551291                }
    11561292        } else {
    11571293                // Use display filters by default.
    1158                 if ( $prefixed )
     1294                if ( $prefixed ){
     1295                        /**
     1296                         * Filter and sanitize the value of the prefixed field (for other contexts).
     1297                         *
     1298                         * @since 2.3.0
     1299                         *
     1300                         * @param mixed $value The user object value to sanitize.
     1301                         * @param int $user_id The User ID.
     1302                         * @param string $context The context to filter for.
     1303                         */
    11591304                        $value = apply_filters($field, $value, $user_id, $context);
    1160                 else
     1305                }else{
     1306                        /**
     1307                         * Non prefixed version...
     1308                         * @see user_{$field} filter above
     1309                         * @since 2.9.0
     1310                         */
    11611311                        $value = apply_filters("user_{$field}", $value, $user_id, $context);
     1312                }
    11621313        }
    11631314
    11641315        if ( 'user_url' == $field )
    function email_exists( $email ) {  
    12501401function validate_username( $username ) {
    12511402        $sanitized = sanitize_user( $username, true );
    12521403        $valid = ( $sanitized == $username );
     1404        /**
     1405         * Filters whether the provided username is valid or not.
     1406         *
     1407         * @since 2.0.11
     1408         *
     1409         * @param bool Whether username given is valid.
     1410         * @param string The username to check.
     1411         */
    12531412        return apply_filters( 'validate_username', $valid, $username );
    12541413}
    12551414
    function wp_insert_user( $userdata ) {  
    13211480        }
    13221481
    13231482        $user_login = sanitize_user($user_login, true);
     1483        /**
     1484         * Filters the username after it has been sanitized, but before the user is created or updated.
     1485         *
     1486         * This hook is called before the user is created or updated.
     1487         *
     1488         * @since 2.0.11
     1489         *
     1490         * @param string $user_login The username after it has been sanitized.
     1491         */
    13241492        $user_login = apply_filters('pre_user_login', $user_login);
    13251493
    13261494        //Remove any non-printable chars from the login string to see if we have ended up with an empty username
    function wp_insert_user( $userdata ) {  
    13341502
    13351503        if ( empty($user_nicename) )
    13361504                $user_nicename = sanitize_title( $user_login );
     1505       
     1506        /**
     1507         * Filters the user's nicename before the user is created or updated.
     1508         *
     1509         * This hook is called before the user is created or updated.
     1510         *
     1511         * @since 2.0.11
     1512         *
     1513         * @param string $user_nicename
     1514         */
    13371515        $user_nicename = apply_filters('pre_user_nicename', $user_nicename);
    13381516
    13391517        if ( empty($user_url) )
    13401518                $user_url = '';
     1519       
     1520        /**
     1521         * Filters the user's url before the user is created or updated.
     1522         *
     1523         * @since 2.0.11
     1524         *
     1525         * @param string $user_url
     1526         */
    13411527        $user_url = apply_filters('pre_user_url', $user_url);
    13421528
    13431529        if ( empty($user_email) )
    13441530                $user_email = '';
     1531       
     1532        /**
     1533         * Filters the user's email before the user is created or updated.
     1534         *
     1535         * @since 2.0.11
     1536         *
     1537         * @param string $user_email
     1538         */
    13451539        $user_email = apply_filters('pre_user_email', $user_email);
    13461540
    13471541        if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
    function wp_insert_user( $userdata ) {  
    13491543
    13501544        if ( empty($nickname) )
    13511545                $nickname = $user_login;
     1546       
     1547        /**
     1548         * Filters the user's nickname before the user is created or updated.
     1549         *
     1550         * @since 2.0.11
     1551         *
     1552         * @param string $nickname The user's nickname.
     1553         */
    13521554        $nickname = apply_filters('pre_user_nickname', $nickname);
    13531555
    13541556        if ( empty($first_name) )
    13551557                $first_name = '';
     1558       
     1559        /**
     1560         * Filters the user's first name before the user is created or updated.
     1561         *
     1562         * @since 2.0.11
     1563         *
     1564         * @param string $first_name
     1565         */
    13561566        $first_name = apply_filters('pre_user_first_name', $first_name);
    13571567
    13581568        if ( empty($last_name) )
    13591569                $last_name = '';
     1570       
     1571        /**
     1572         * Filters the user's last name before the user is created or updated.
     1573         *
     1574         * @since 2.0.11
     1575         *
     1576         * @param string $last_name
     1577         */
    13601578        $last_name = apply_filters('pre_user_last_name', $last_name);
    13611579
    13621580        if ( empty( $display_name ) ) {
    function wp_insert_user( $userdata ) {  
    13721590                else
    13731591                        $display_name = $user_login;
    13741592        }
     1593       
     1594        /**
     1595         * Filters the user's display name before the user is created or updated.
     1596         *
     1597         * @since 2.0.11
     1598         *
     1599         * @param string $display_name
     1600         */
    13751601        $display_name = apply_filters( 'pre_user_display_name', $display_name );
    13761602
    13771603        if ( empty($description) )
    13781604                $description = '';
     1605       
     1606        /**
     1607         * Filters the user's description before the user is created or updated.
     1608         *
     1609         * @since 2.0.11
     1610         *
     1611         * @param string $description
     1612         */
    13791613        $description = apply_filters('pre_user_description', $description);
    13801614
    13811615        if ( empty($rich_editing) )
    function wp_insert_user( $userdata ) {  
    14351669        wp_cache_delete($user_id, 'users');
    14361670        wp_cache_delete($user_login, 'userlogins');
    14371671
    1438         if ( $update )
     1672        if ( $update ){
     1673                /**
     1674                 * Triggered after the user is updated.
     1675                 *
     1676                 * @since 2.0.0
     1677                 *
     1678                 * @param int $user_id The user ID
     1679                 * @param object $old_user_data User's data prior to update as a raw object
     1680                 */
    14391681                do_action('profile_update', $user_id, $old_user_data);
    1440         else
     1682        }else{
     1683                /**
     1684                 * Triggered after the user is created.
     1685                 *
     1686                 * @since 1.5.2
     1687                 *
     1688                 * @param int $user_id The user ID
     1689                 */
    14411690                do_action('user_register', $user_id);
     1691        }
    14421692
    14431693        return $user_id;
    14441694}
    function check_password_reset_key($key, $login) {  
    16481898 * @param string $new_pass New password for the user in plaintext
    16491899 */
    16501900function reset_password( $user, $new_pass ) {
     1901       
     1902        /**
     1903         * Triggered before the user's password is reset to $new_pass
     1904         *
     1905         * @since Unknown
     1906         *
     1907         * @param int $user_id The user ID
     1908         * @param object $old_user_data User's data prior to update as a raw object
     1909         */
    16511910        do_action( 'password_reset', $user, $new_pass );
    1652 
     1911        //@since is uknown but exists before 1.5
    16531912        wp_set_password( $new_pass, $user->ID );
    16541913        update_user_option( $user->ID, 'default_password_nag', false, true );
    16551914
    function register_new_user( $user_login, $user_email ) {  
    16671926        $errors = new WP_Error();
    16681927
    16691928        $sanitized_user_login = sanitize_user( $user_login );
     1929        /**
     1930         * Filters the email address of a user being registered.
     1931         *
     1932         * This hooks is triggered before the user is created.
     1933         *
     1934         * @since 2.1.0
     1935         *
     1936         * @param string $user_email The email of the new user.
     1937         */
    16701938        $user_email = apply_filters( 'user_registration_email', $user_email );
    16711939
    16721940        // Check the username
    function register_new_user( $user_login, $user_email ) {  
    16891957                $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );
    16901958        }
    16911959
     1960        /**
     1961         * Triggered when registration form data is submitted, and before the user has been created.
     1962         *
     1963         * @since 2.1.0
     1964         *
     1965         * @param string $sanitized_user_login The submitted username after sanitization.
     1966         * @param string $user_email The submitted email.
     1967         * @param WP_Error $errors Contains any errors with the submitted username and email (e.g. invalid, already exists).
     1968         */
    16921969        do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
    16931970
     1971        /**
     1972         * Filters the errors encountered when a new user is beng registerered.
     1973         *
     1974         * The filtered WP_Error object may, for example, contain errors for an invalid or existing username or email.
     1975         * A WP_Error object should always returned, but may or may not contain errors.
     1976         *
     1977         * If any errors are present in $errors, this will abort the user's registration.
     1978         *
     1979         * @since 2.1.0
     1980         *
     1981         * @param WP_Error $errors A WP_Error object which contains any errors encountered during registration.
     1982         * @param string $sanitized_user_login The user's username after it has been sanitized.
     1983         * @param string $user_email The user's email.
     1984         */
    16941985        $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
    16951986
    16961987        if ( $errors->get_error_code() )