From c2d8b48d972608c1d1eb7438793e1fba19d6788c Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 25 Feb 2022 13:48:00 +0000 Subject: [PATCH] Code Modernization: Check the return type of `wp_parse_url()` in `wp_mail()`. As per the PHP manual: > If the `component` parameter is omitted, an associative array is returned. > If the `component` parameter is specified, `parse_url()` returns a string (or an int, in the case of `PHP_URL_PORT`) instead of an array. If the requested component doesn't exist within the given URL, `null` will be returned. Reference: [https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues PHP Manual: parse_url(): Return Values] In PHP 8.1, if the home URL does not have a "host" component, it would lead to a `substr(): Passing null to parameter #1 ($string) of type string is deprecated` notice. Changing the logic around and adding validation for the return type value of `wp_parse_url()` prevents that. Follow-up to [48601], [51606], [51622], [51626], [51629], [51630]. Props dennisatyoast, jrf. See #54730. Built from https://develop.svn.wordpress.org/trunk@52799 git-svn-id: http://core.svn.wordpress.org/trunk@52388 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/pluggable.php | 14 +++++++++----- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index ffcd2bdcc3..fdbfdea250 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -378,12 +378,16 @@ if ( ! function_exists( 'wp_mail' ) ) : */ if ( ! isset( $from_email ) ) { // Get the site domain and get rid of www. - $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST ); - if ( 'www.' === substr( $sitename, 0, 4 ) ) { - $sitename = substr( $sitename, 4 ); - } + $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST ); + $from_email = 'wordpress@'; - $from_email = 'wordpress@' . $sitename; + if ( null !== $sitename ) { + if ( 'www.' === substr( $sitename, 0, 4 ) ) { + $sitename = substr( $sitename, 4 ); + } + + $from_email .= $sitename; + } } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index c12126b577..30a6e6632b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-52798'; +$wp_version = '6.0-alpha-52799'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.