From c42f8ef6946b65630232598b09bfe2fee9a9a217 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Thu, 28 Sep 2023 21:26:25 +0000 Subject: [PATCH] Code Modernization: Fix "passing null to non-nullable" deprecation from next_posts(). The `esc_url()` function expects to a string for `$url` parameter. There is no input validation within that function. The function contains a `ltrim()` which also expects a string. Passing `null` to this parameter results in `Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated` notice on PHP 8.1+. Tracing the stack back, a `null` is being passed to it within `next_posts()` when `get_next_posts_page_link()` returns `null` (it can return a string or `null`). On PHP 7.0 to PHP 8.x, an empty string is returned from `esc_url()` when `null` is passed to it. The change in this changeset avoids the deprecation notice by not invoking `esc_url()` when `get_next_posts_page_link()` returns `null` and instead sets the `$output` to an empty string, thus maintain the same behavior as before (minus the deprecation notice). Adds a test to validate an empty string is returned and the absence of the deprecation (when running on PHP 8.1+). Follow-up to [11383], [9632]. Props codersantosh, nihar007, hellofromTonya, mukesh27, oglekler, rajinsharwar. Fixes #59154. Built from https://develop.svn.wordpress.org/trunk@56740 git-svn-id: http://core.svn.wordpress.org/trunk@56252 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 3 ++- wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index a34b34b6ce..34bfd267a3 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -2511,7 +2511,8 @@ function get_next_posts_page_link( $max_page = 0 ) { * @return string|void The link URL for next posts page if `$display = false`. */ function next_posts( $max_page = 0, $display = true ) { - $output = esc_url( get_next_posts_page_link( $max_page ) ); + $link = get_next_posts_page_link( $max_page ); + $output = $link ? esc_url( $link ) : ''; if ( $display ) { echo $output; diff --git a/wp-includes/version.php b/wp-includes/version.php index fe11cbcb0f..85fc397dcd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-beta1-56739'; +$wp_version = '6.4-beta1-56740'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.