Changeset 47122 for trunk/src/wp-includes/pluggable.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pluggable.php
r47114 r47122 169 169 */ 170 170 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. 172 172 173 173 /** … … 210 210 global $phpmailer; 211 211 212 // (Re)create it, if it's gone missing 212 // (Re)create it, if it's gone missing. 213 213 if ( ! ( $phpmailer instanceof PHPMailer ) ) { 214 214 require_once ABSPATH . WPINC . '/class-phpmailer.php'; … … 217 217 } 218 218 219 // Headers 219 // Headers. 220 220 $cc = array(); 221 221 $bcc = array(); … … 226 226 } else { 227 227 if ( ! is_array( $headers ) ) { 228 // Explode the headers out, so this function can take both229 // 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. 230 230 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) ); 231 231 } else { … … 234 234 $headers = array(); 235 235 236 // If it's actually got contents 236 // If it's actually got contents. 237 237 if ( ! empty( $tempheaders ) ) { 238 // Iterate through the raw headers 238 // Iterate through the raw headers. 239 239 foreach ( (array) $tempheaders as $header ) { 240 240 if ( strpos( $header, ':' ) === false ) { … … 245 245 continue; 246 246 } 247 // Explode them out 247 // Explode them out. 248 248 list( $name, $content ) = explode( ':', trim( $header ), 2 ); 249 249 250 // Cleanup crew 250 // Cleanup crew. 251 251 $name = trim( $name ); 252 252 $content = trim( $content ); 253 253 254 254 switch ( strtolower( $name ) ) { 255 // Mainly for legacy -- process a From: header if it's there255 // Mainly for legacy -- process a "From:" header if it's there. 256 256 case 'from': 257 257 $bracket_pos = strpos( $content, '<' ); … … 299 299 break; 300 300 default: 301 // Add it to our grand headers array 301 // Add it to our grand headers array. 302 302 $headers[ trim( $name ) ] = trim( $content ); 303 303 break; … … 307 307 } 308 308 309 // Empty out the values that may be set 309 // Empty out the values that may be set. 310 310 $phpmailer->clearAllRecipients(); 311 311 $phpmailer->clearAttachments(); … … 313 313 $phpmailer->clearReplyTos(); 314 314 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. 317 318 if ( ! isset( $from_name ) ) { 318 319 $from_name = 'WordPress'; 319 320 } 320 321 321 /* If we don't have an email from the input headers default to wordpress@$sitename322 * Some hosts will block outgoing mail from this address if it doesn't exist but323 * there's no easy alternative. Defaulting to admin_email might appear to be another324 * option but some hosts may refuse to relay mail from an unknown domain. See325 * 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 */ 328 329 if ( ! isset( $from_email ) ) { 329 330 // Get the site domain and get rid of www. … … 366 367 } 367 368 368 // Set mail's subject and body 369 // Set mail's subject and body. 369 370 $phpmailer->Subject = $subject; 370 371 $phpmailer->Body = $message; 371 372 372 // Set destination addresses, using appropriate methods for handling addresses 373 // Set destination addresses, using appropriate methods for handling addresses. 373 374 $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' ); 374 375 … … 380 381 foreach ( (array) $addresses as $address ) { 381 382 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>". 383 384 $recipient_name = ''; 384 385 … … 410 411 } 411 412 412 // Set to use PHP's mail() 413 // Set to use PHP's mail(). 413 414 $phpmailer->isMail(); 414 415 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. 417 419 if ( ! isset( $content_type ) ) { 418 420 $content_type = 'text/plain'; … … 430 432 $phpmailer->ContentType = $content_type; 431 433 432 // Set whether it's plaintext, depending on $content_type 434 // Set whether it's plaintext, depending on $content_type. 433 435 if ( 'text/html' == $content_type ) { 434 436 $phpmailer->isHTML( true ); 435 437 } 436 438 437 // If we don't have a charset from the input headers 439 // If we don't have a charset from the input headers. 438 440 if ( ! isset( $charset ) ) { 439 441 $charset = get_bloginfo( 'charset' ); … … 538 540 539 541 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?) 541 543 // Only needed if all authentication handlers fail to return anything. 542 544 $user = new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: Invalid username, email address or incorrect password.' ) ); … … 626 628 $expiration = $cookie_elements['expiration']; 627 629 628 // Allow a grace period for POST and Ajax requests 630 // Allow a grace period for POST and Ajax requests. 629 631 if ( wp_doing_ajax() || 'POST' == $_SERVER['REQUEST_METHOD'] ) { 630 632 $expired += HOUR_IN_SECONDS; 631 633 } 632 634 633 // Quick check to see if an honest cookie has expired 635 // Quick check to see if an honest cookie has expired. 634 636 if ( $expired < time() ) { 635 637 /** … … 690 692 } 691 693 692 // Ajax/POST grace period set above 694 // Ajax/POST grace period set above. 693 695 if ( $expiration < time() ) { 694 696 $GLOBALS['login_grace_period'] = 1; … … 967 969 } 968 970 969 // Auth cookies 971 // Auth cookies. 970 972 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); 971 973 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); … … 975 977 setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); 976 978 977 // Settings cookies 979 // Settings cookies. 978 980 setcookie( 'wp-settings-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH ); 979 981 setcookie( 'wp-settings-time-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH ); 980 982 981 // Old cookies 983 // Old cookies. 982 984 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); 983 985 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); … … 985 987 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); 986 988 987 // Even older cookies 989 // Even older cookies. 988 990 setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); 989 991 setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); … … 991 993 setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); 992 994 993 // Post password cookie 995 // Post password cookie. 994 996 setcookie( 'wp-postpass_' . COOKIEHASH, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); 995 997 } … … 1027 1029 */ 1028 1030 function auth_redirect() { 1029 // Checks if a user is logged in, if not redirects them to the login page1030 1031 1031 $secure = ( is_ssl() || force_ssl_admin() ); 1032 1032 … … 1040 1040 $secure = apply_filters( 'secure_auth_redirect', $secure ); 1041 1041 1042 // If https is required and request is http, redirect 1042 // If https is required and request is http, redirect. 1043 1043 if ( $secure && ! is_ssl() && false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) ) { 1044 1044 if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { … … 1082 1082 } 1083 1083 1084 return; // The cookie is good so we're done1085 } 1086 1087 // The cookie is no good so force login1084 return; // The cookie is good, so we're done. 1085 } 1086 1087 // The cookie is no good, so force login. 1088 1088 nocache_headers(); 1089 1089 … … 1263 1263 1264 1264 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. 1266 1266 } 1267 1267 … … 1374 1374 function wp_safe_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) { 1375 1375 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(). 1377 1377 $location = wp_sanitize_redirect( $location ); 1378 1378 … … 1409 1409 function wp_validate_redirect( $location, $default = '' ) { 1410 1410 $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 '//'. 1412 1412 if ( substr( $location, 0, 2 ) == '//' ) { 1413 1413 $location = 'http:' . $location; 1414 1414 } 1415 1415 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 1417 1418 $cut = strpos( $location, '?' ); 1418 1419 $test = $cut ? substr( $location, 0, $cut ) : $location; … … 1421 1422 $lp = @parse_url( $test ); 1422 1423 1423 // Give up if malformed URL 1424 // Give up if malformed URL. 1424 1425 if ( false === $lp ) { 1425 1426 return $default; 1426 1427 } 1427 1428 1428 // Allow only http and https schemes. No data:, etc.1429 // Allow only 'http' and 'https' schemes. No 'data:', etc. 1429 1430 if ( isset( $lp['scheme'] ) && ! ( 'http' == $lp['scheme'] || 'https' == $lp['scheme'] ) ) { 1430 1431 return $default; … … 1440 1441 } 1441 1442 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. 1443 1445 if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) { 1444 1446 return $default; … … 1537 1539 $notify_author = apply_filters( 'comment_notification_notify_author', false, $comment->comment_ID ); 1538 1540 1539 // The comment was left by the author 1541 // The comment was left by the author. 1540 1542 if ( $author && ! $notify_author && $comment->user_id == $post->post_author ) { 1541 1543 unset( $emails[ $author->user_email ] ); 1542 1544 } 1543 1545 1544 // The author moderated a comment on their own post 1546 // The author moderated a comment on their own post. 1545 1547 if ( $author && ! $notify_author && $post->post_author == get_current_user_id() ) { 1546 1548 unset( $emails[ $author->user_email ] ); 1547 1549 } 1548 1550 1549 // The post author is no longer a member of the blog 1551 // The post author is no longer a member of the blog. 1550 1552 if ( $author && ! $notify_author && ! user_can( $post->post_author, 'read_post', $post->ID ) ) { 1551 1553 unset( $emails[ $author->user_email ] ); 1552 1554 } 1553 1555 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. 1555 1557 if ( ! count( $emails ) ) { 1556 1558 return false; … … 1566 1568 } 1567 1569 1568 // The blogname option is escaped with esc_html on the way into the database in sanitize_option1569 // 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. 1570 1572 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1571 1573 $comment_content = wp_specialchars_decode( $comment->comment_content ); … … 1600 1602 break; 1601 1603 1602 default: // Comments 1604 default: // Comments. 1603 1605 /* translators: %s: Post title. */ 1604 1606 $notify_message = sprintf( __( 'New comment on your post "%s"' ), $post->post_title ) . "\r\n"; … … 1755 1757 $comments_waiting = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '0'" ); 1756 1758 1757 // The blogname option is escaped with esc_html on the way into the database in sanitize_option1758 // 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. 1759 1761 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1760 1762 $comment_content = wp_specialchars_decode( $comment->comment_content ); … … 1783 1785 break; 1784 1786 1785 default: // Comments 1787 default: // Comments. 1786 1788 /* translators: %s: Post title. */ 1787 1789 $notify_message = sprintf( __( 'A new comment on the post "%s" is waiting for your approval' ), $post->post_title ) . "\r\n"; … … 1894 1896 */ 1895 1897 function wp_password_change_notification( $user ) { 1896 // send a copy of password change notification to the admin1897 // 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. 1898 1900 if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) { 1899 1901 /* translators: %s: User name. */ 1900 1902 $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_option1902 // 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. 1903 1905 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1904 1906 … … 1960 1962 } 1961 1963 1962 // Accepts only 'user', 'admin' , 'both' or default '' as $notify 1964 // Accepts only 'user', 'admin' , 'both' or default '' as $notify. 1963 1965 if ( ! in_array( $notify, array( 'user', 'admin', 'both', '' ), true ) ) { 1964 1966 return; … … 1967 1969 $user = get_userdata( $user_id ); 1968 1970 1969 // The blogname option is escaped with esc_html on the way into the database in sanitize_option1970 // 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. 1971 1973 $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1972 1974 … … 2019 2021 } 2020 2022 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. 2022 2024 if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) { 2023 2025 return; … … 2139 2141 $i = wp_nonce_tick(); 2140 2142 2141 // Nonce generated 0-12 hours ago 2143 // Nonce generated 0-12 hours ago. 2142 2144 $expected = substr( wp_hash( $i . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); 2143 2145 if ( hash_equals( $expected, $nonce ) ) { … … 2145 2147 } 2146 2148 2147 // Nonce generated 12-24 hours ago 2149 // Nonce generated 12-24 hours ago. 2148 2150 $expected = substr( wp_hash( ( $i - 1 ) . '|' . $action . '|' . $uid . '|' . $token, 'nonce' ), -12, 10 ); 2149 2151 if ( hash_equals( $expected, $nonce ) ) { … … 2163 2165 do_action( 'wp_verify_nonce_failed', $nonce, $action, $user, $token ); 2164 2166 2165 // Invalid nonce 2167 // Invalid nonce. 2166 2168 return false; 2167 2169 } … … 2337 2339 if ( empty( $wp_hasher ) ) { 2338 2340 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. 2340 2342 $wp_hasher = new PasswordHash( 8, true ); 2341 2343 } … … 2393 2395 } 2394 2396 2395 // If the stored hash is longer than an MD5, presume the2396 // new style phpass portable hash.2397 // If the stored hash is longer than an MD5, 2398 // presume the new style phpass portable hash. 2397 2399 if ( empty( $wp_hasher ) ) { 2398 2400 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. 2400 2402 $wp_hasher = new PasswordHash( 8, true ); 2401 2403 } … … 2471 2473 global $rnd_value; 2472 2474 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. 2474 2477 $max_random_number = 3000000000 === 2147483647 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff 2475 2478 2476 // We only handle Ints, floats are truncated to their integer value.2479 // We only handle ints, floats are truncated to their integer value. 2477 2480 $min = (int) $min; 2478 2481 $max = (int) $max; 2479 2482 2480 // Use PHP's CSPRNG, or a compatible method 2483 // Use PHP's CSPRNG, or a compatible method. 2481 2484 static $use_random_int_functionality = true; 2482 2485 if ( $use_random_int_functionality ) { … … 2499 2502 } 2500 2503 2501 // Reset $rnd_value after 14 uses 2502 // 32 (md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value2504 // Reset $rnd_value after 14 uses. 2505 // 32 (md5) + 40 (sha1) + 40 (sha1) / 8 = 14 random numbers from $rnd_value. 2503 2506 if ( strlen( $rnd_value ) < 8 ) { 2504 2507 if ( defined( 'WP_SETUP_CONFIG' ) ) { … … 2516 2519 } 2517 2520 2518 // Take the first 8 digits for our value 2521 // Take the first 8 digits for our value. 2519 2522 $value = substr( $rnd_value, 0, 8 ); 2520 2523 … … 2524 2527 $value = abs( hexdec( $value ) ); 2525 2528 2526 // Reduce the value to be within the min - max range 2529 // Reduce the value to be within the min - max range. 2527 2530 if ( $max != 0 ) { 2528 2531 $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 );
Note: See TracChangeset
for help on using the changeset viewer.