Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

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

    r47114 r47122  
    169169     */
    170170    function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
    171         // Compact the input, apply the filters, and extract them back out
     171        // Compact the input, apply the filters, and extract them back out.
    172172
    173173        /**
     
    210210        global $phpmailer;
    211211
    212         // (Re)create it, if it's gone missing
     212        // (Re)create it, if it's gone missing.
    213213        if ( ! ( $phpmailer instanceof PHPMailer ) ) {
    214214            require_once ABSPATH . WPINC . '/class-phpmailer.php';
     
    217217        }
    218218
    219         // Headers
     219        // Headers.
    220220        $cc       = array();
    221221        $bcc      = array();
     
    226226        } else {
    227227            if ( ! is_array( $headers ) ) {
    228                 // Explode the headers out, so this function can take both
    229                 // string headers and an array of headers.
     228                // Explode the headers out, so this function can take
     229                // both string headers and an array of headers.
    230230                $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
    231231            } else {
     
    234234            $headers = array();
    235235
    236             // If it's actually got contents
     236            // If it's actually got contents.
    237237            if ( ! empty( $tempheaders ) ) {
    238                 // Iterate through the raw headers
     238                // Iterate through the raw headers.
    239239                foreach ( (array) $tempheaders as $header ) {
    240240                    if ( strpos( $header, ':' ) === false ) {
     
    245245                        continue;
    246246                    }
    247                     // Explode them out
     247                    // Explode them out.
    248248                    list( $name, $content ) = explode( ':', trim( $header ), 2 );
    249249
    250                     // Cleanup crew
     250                    // Cleanup crew.
    251251                    $name    = trim( $name );
    252252                    $content = trim( $content );
    253253
    254254                    switch ( strtolower( $name ) ) {
    255                         // Mainly for legacy -- process a From: header if it's there
     255                        // Mainly for legacy -- process a "From:" header if it's there.
    256256                        case 'from':
    257257                            $bracket_pos = strpos( $content, '<' );
     
    299299                            break;
    300300                        default:
    301                             // Add it to our grand headers array
     301                            // Add it to our grand headers array.
    302302                            $headers[ trim( $name ) ] = trim( $content );
    303303                            break;
     
    307307        }
    308308
    309         // Empty out the values that may be set
     309        // Empty out the values that may be set.
    310310        $phpmailer->clearAllRecipients();
    311311        $phpmailer->clearAttachments();
     
    313313        $phpmailer->clearReplyTos();
    314314
    315         // From email and name
    316         // If we don't have a name from the input headers
     315        // Set "From" name and email.
     316
     317        // If we don't have a name from the input headers.
    317318        if ( ! isset( $from_name ) ) {
    318319            $from_name = 'WordPress';
    319320        }
    320321
    321         /* If we don't have an email from the input headers default to wordpress@$sitename
    322          * Some hosts will block outgoing mail from this address if it doesn't exist but
    323          * there's no easy alternative. Defaulting to admin_email might appear to be another
    324          * option but some hosts may refuse to relay mail from an unknown domain. See
    325          * https://core.trac.wordpress.org/ticket/5007.
    326          */
    327 
     322        /*
     323         * If we don't have an email from the input headers, default to wordpress@$sitename
     324         * Some hosts will block outgoing mail from this address if it doesn't exist,
     325         * but there's no easy alternative. Defaulting to admin_email might appear to be
     326         * another option, but some hosts may refuse to relay mail from an unknown domain.
     327         * See https://core.trac.wordpress.org/ticket/5007.
     328         */
    328329        if ( ! isset( $from_email ) ) {
    329330            // Get the site domain and get rid of www.
     
    366367        }
    367368
    368         // Set mail's subject and body
     369        // Set mail's subject and body.
    369370        $phpmailer->Subject = $subject;
    370371        $phpmailer->Body    = $message;
    371372
    372         // Set destination addresses, using appropriate methods for handling addresses
     373        // Set destination addresses, using appropriate methods for handling addresses.
    373374        $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
    374375
     
    380381            foreach ( (array) $addresses as $address ) {
    381382                try {
    382                     // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>"
     383                    // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>".
    383384                    $recipient_name = '';
    384385
     
    410411        }
    411412
    412         // Set to use PHP's mail()
     413        // Set to use PHP's mail().
    413414        $phpmailer->isMail();
    414415
    415         // Set Content-Type and charset
    416         // If we don't have a content-type from the input headers
     416        // Set Content-Type and charset.
     417
     418        // If we don't have a content-type from the input headers.
    417419        if ( ! isset( $content_type ) ) {
    418420            $content_type = 'text/plain';
     
    430432        $phpmailer->ContentType = $content_type;
    431433
    432         // Set whether it's plaintext, depending on $content_type
     434        // Set whether it's plaintext, depending on $content_type.
    433435        if ( 'text/html' == $content_type ) {
    434436            $phpmailer->isHTML( true );
    435437        }
    436438
    437         // If we don't have a charset from the input headers
     439        // If we don't have a charset from the input headers.
    438440        if ( ! isset( $charset ) ) {
    439441            $charset = get_bloginfo( 'charset' );
     
    538540
    539541        if ( $user == null ) {
    540             // TODO what should the error message be? (Or would these even happen?)
     542            // TODO: What should the error message be? (Or would these even happen?)
    541543            // Only needed if all authentication handlers fail to return anything.
    542544            $user = new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: Invalid username, email address or incorrect password.' ) );
     
    626628        $expiration = $cookie_elements['expiration'];
    627629
    628         // Allow a grace period for POST and Ajax requests
     630        // Allow a grace period for POST and Ajax requests.
    629631        if ( wp_doing_ajax() || 'POST' == $_SERVER['REQUEST_METHOD'] ) {
    630632            $expired += HOUR_IN_SECONDS;
    631633        }
    632634
    633         // Quick check to see if an honest cookie has expired
     635        // Quick check to see if an honest cookie has expired.
    634636        if ( $expired < time() ) {
    635637            /**
     
    690692        }
    691693
    692         // Ajax/POST grace period set above
     694        // Ajax/POST grace period set above.
    693695        if ( $expiration < time() ) {
    694696            $GLOBALS['login_grace_period'] = 1;
     
    967969        }
    968970
    969         // Auth cookies
     971        // Auth cookies.
    970972        setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN );
    971973        setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN );
     
    975977        setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
    976978
    977         // Settings cookies
     979        // Settings cookies.
    978980        setcookie( 'wp-settings-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
    979981        setcookie( 'wp-settings-time-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
    980982
    981         // Old cookies
     983        // Old cookies.
    982984        setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
    983985        setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
     
    985987        setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
    986988
    987         // Even older cookies
     989        // Even older cookies.
    988990        setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
    989991        setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
     
    991993        setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
    992994
    993         // Post password cookie
     995        // Post password cookie.
    994996        setcookie( 'wp-postpass_' . COOKIEHASH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
    995997    }
     
    10271029     */
    10281030    function auth_redirect() {
    1029         // Checks if a user is logged in, if not redirects them to the login page
    1030 
    10311031        $secure = ( is_ssl() || force_ssl_admin() );
    10321032
     
    10401040        $secure = apply_filters( 'secure_auth_redirect', $secure );
    10411041
    1042         // If https is required and request is http, redirect
     1042        // If https is required and request is http, redirect.
    10431043        if ( $secure && ! is_ssl() && false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) {
    10441044            if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
     
    10821082            }
    10831083
    1084             return;  // The cookie is good so we're done
    1085         }
    1086 
    1087         // The cookie is no good so force login
     1084            return; // The cookie is good, so we're done.
     1085        }
     1086
     1087        // The cookie is no good, so force login.
    10881088        nocache_headers();
    10891089
     
    12631263
    12641264        if ( ! $is_IIS && PHP_SAPI != 'cgi-fcgi' ) {
    1265             status_header( $status ); // This causes problems on IIS and some FastCGI setups
     1265            status_header( $status ); // This causes problems on IIS and some FastCGI setups.
    12661266        }
    12671267
     
    13741374    function wp_safe_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) {
    13751375
    1376         // Need to look at the URL the way it will end up in wp_redirect()
     1376        // Need to look at the URL the way it will end up in wp_redirect().
    13771377        $location = wp_sanitize_redirect( $location );
    13781378
     
    14091409    function wp_validate_redirect( $location, $default = '' ) {
    14101410        $location = trim( $location, " \t\n\r\0\x08\x0B" );
    1411         // browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
     1411        // Browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'.
    14121412        if ( substr( $location, 0, 2 ) == '//' ) {
    14131413            $location = 'http:' . $location;
    14141414        }
    14151415
    1416         // In php 5 parse_url may fail if the URL query part contains http://, bug #38143
     1416        // In PHP 5 parse_url() may fail if the URL query part contains 'http://'.
     1417        // See https://bugs.php.net/bug.php?id=38143
    14171418        $cut  = strpos( $location, '?' );
    14181419        $test = $cut ? substr( $location, 0, $cut ) : $location;
     
    14211422        $lp = @parse_url( $test );
    14221423
    1423         // Give up if malformed URL
     1424        // Give up if malformed URL.
    14241425        if ( false === $lp ) {
    14251426            return $default;
    14261427        }
    14271428
    1428         // Allow only http and https schemes. No data:, etc.
     1429        // Allow only 'http' and 'https' schemes. No 'data:', etc.
    14291430        if ( isset( $lp['scheme'] ) && ! ( 'http' == $lp['scheme'] || 'https' == $lp['scheme'] ) ) {
    14301431            return $default;
     
    14401441        }
    14411442
    1442         // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
     1443        // Reject if certain components are set but host is not.
     1444        // This catches URLs like https:host.com for which parse_url() does not set the host field.
    14431445        if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
    14441446            return $default;
     
    15371539        $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID );
    15381540
    1539         // The comment was left by the author
     1541        // The comment was left by the author.
    15401542        if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) {
    15411543            unset( $emails[ $author->user_email ] );
    15421544        }
    15431545
    1544         // The author moderated a comment on their own post
     1546        // The author moderated a comment on their own post.
    15451547        if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) {
    15461548            unset( $emails[ $author->user_email ] );
    15471549        }
    15481550
    1549         // The post author is no longer a member of the blog
     1551        // The post author is no longer a member of the blog.
    15501552        if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) {
    15511553            unset( $emails[ $author->user_email ] );
    15521554        }
    15531555
    1554         // If there's no email to send the comment to, bail, otherwise flip array back around for use below
     1556        // If there's no email to send the comment to, bail, otherwise flip array back around for use below.
    15551557        if ( ! count( $emails ) ) {
    15561558            return false;
     
    15661568        }
    15671569
    1568         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    1569         // we want to reverse this for the plain text arena of emails.
     1570        // The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
     1571        // We want to reverse this for the plain text arena of emails.
    15701572        $blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    15711573        $comment_content = wp_specialchars_decode( $comment->comment_content );
     
    16001602                break;
    16011603
    1602             default: // Comments
     1604            default: // Comments.
    16031605                /* translators: %s: Post title. */
    16041606                $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n";
     
    17551757        $comments_waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" );
    17561758
    1757         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    1758         // we want to reverse this for the plain text arena of emails.
     1759        // The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
     1760        // We want to reverse this for the plain text arena of emails.
    17591761        $blogname        = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    17601762        $comment_content = wp_specialchars_decode( $comment->comment_content );
     
    17831785                break;
    17841786
    1785             default: // Comments
     1787            default: // Comments.
    17861788                /* translators: %s: Post title. */
    17871789                $notify_message  = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n";
     
    18941896     */
    18951897    function wp_password_change_notification( $user ) {
    1896         // send a copy of password change notification to the admin
    1897         // but check to see if it's the admin whose password we're changing, and skip this
     1898        // Send a copy of password change notification to the admin,
     1899        // but check to see if it's the admin whose password we're changing, and skip this.
    18981900        if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) {
    18991901            /* translators: %s: User name. */
    19001902            $message = sprintf( __( 'Password changed for user: %s' ), $user->user_login ) . "\r\n";
    1901             // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    1902             // we want to reverse this for the plain text arena of emails.
     1903            // The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
     1904            // We want to reverse this for the plain text arena of emails.
    19031905            $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    19041906
     
    19601962        }
    19611963
    1962         // Accepts only 'user', 'admin' , 'both' or default '' as $notify
     1964        // Accepts only 'user', 'admin' , 'both' or default '' as $notify.
    19631965        if ( ! in_array( $notify, array( 'user', 'admin', 'both', '' ), true ) ) {
    19641966            return;
     
    19671969        $user = get_userdata( $user_id );
    19681970
    1969         // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    1970         // we want to reverse this for the plain text arena of emails.
     1971        // The blogname option is escaped with esc_html() on the way into the database in sanitize_option().
     1972        // We want to reverse this for the plain text arena of emails.
    19711973        $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    19721974
     
    20192021        }
    20202022
    2021         // `$deprecated was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification.
     2023        // `$deprecated` was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notification.
    20222024        if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) {
    20232025            return;
     
    21392141        $i     = wp_nonce_tick();
    21402142
    2141         // Nonce generated 0-12 hours ago
     2143        // Nonce generated 0-12 hours ago.
    21422144        $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
    21432145        if ( hash_equals( $expected, $nonce ) ) {
     
    21452147        }
    21462148
    2147         // Nonce generated 12-24 hours ago
     2149        // Nonce generated 12-24 hours ago.
    21482150        $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 );
    21492151        if ( hash_equals( $expected, $nonce ) ) {
     
    21632165        do_action( 'wp_verify_nonce_failed', $nonce, $action, $user, $token );
    21642166
    2165         // Invalid nonce
     2167        // Invalid nonce.
    21662168        return false;
    21672169    }
     
    23372339        if ( empty( $wp_hasher ) ) {
    23382340            require_once( ABSPATH . WPINC . '/class-phpass.php' );
    2339             // By default, use the portable hash from phpass
     2341            // By default, use the portable hash from phpass.
    23402342            $wp_hasher = new PasswordHash( 8, true );
    23412343        }
     
    23932395        }
    23942396
    2395         // If the stored hash is longer than an MD5, presume the
    2396         // new style phpass portable hash.
     2397        // If the stored hash is longer than an MD5,
     2398        // presume the new style phpass portable hash.
    23972399        if ( empty( $wp_hasher ) ) {
    23982400            require_once( ABSPATH . WPINC . '/class-phpass.php' );
    2399             // By default, use the portable hash from phpass
     2401            // By default, use the portable hash from phpass.
    24002402            $wp_hasher = new PasswordHash( 8, true );
    24012403        }
     
    24712473        global $rnd_value;
    24722474
    2473         // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
     2475        // Some misconfigured 32-bit environments (Entropy PHP, for example)
     2476        // truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
    24742477        $max_random_number = 3000000000 === 2147483647 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff
    24752478
    2476         // We only handle Ints, floats are truncated to their integer value.
     2479        // We only handle ints, floats are truncated to their integer value.
    24772480        $min = (int) $min;
    24782481        $max = (int) $max;
    24792482
    2480         // Use PHP's CSPRNG, or a compatible method
     2483        // Use PHP's CSPRNG, or a compatible method.
    24812484        static $use_random_int_functionality = true;
    24822485        if ( $use_random_int_functionality ) {
     
    24992502        }
    25002503
    2501         // Reset $rnd_value after 14 uses
    2502         // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
     2504        // Reset $rnd_value after 14 uses.
     2505        // 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value.
    25032506        if ( strlen( $rnd_value ) < 8 ) {
    25042507            if ( defined( 'WP_SETUP_CONFIG' ) ) {
     
    25162519        }
    25172520
    2518         // Take the first 8 digits for our value
     2521        // Take the first 8 digits for our value.
    25192522        $value = substr( $rnd_value, 0, 8 );
    25202523
     
    25242527        $value = abs( hexdec( $value ) );
    25252528
    2526         // Reduce the value to be within the min - max range
     2529        // Reduce the value to be within the min - max range.
    25272530        if ( $max != 0 ) {
    25282531            $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 );
Note: See TracChangeset for help on using the changeset viewer.