Commit 23c235c745 for wordpress.org

commit 23c235c745e709f7b155cb9dd40d2fd2a9984c62
Author: wildworks <wildworks@git.wordpress.org>
Date:   Fri Nov 27 00:57:59 2026 +0000

    Themes: Check that a JSON file is readable before decoding it.

    When the given path is a directory or an unreadable file, `wp_json_file_decode()` now triggers a notice and returns `null` instead of emitting a PHP warning while reading it. The notice for a missing file now also shows the requested path instead of an empty string.

    Developed in: https://github.com/WordPress/wordpress-develop/pull/10898

    Props mindctrl, mukesh27, ozgursar, pbearne, westonruter, wildworks.
    Fixes #64620.
    Built from https://develop.svn.wordpress.org/trunk@65806


    git-svn-id: http://core.svn.wordpress.org/trunk@64835 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/functions.php b/wp-includes/functions.php
index 6d2130c65b..113050d37b 100644
--- a/wp-includes/functions.php
+++ b/wp-includes/functions.php
@@ -4810,13 +4810,13 @@ function wp_check_jsonp_callback( $callback ) {
  * }
  *
  * @return mixed Returns the value encoded in JSON in appropriate PHP type.
- *               `null` is returned if the file is not found, or its content can't be decoded.
+ *               `null` is returned if the file is not found, is not a readable file,
+ *               or its content can't be decoded.
  */
 function wp_json_file_decode( $filename, $options = array() ) {
-	$result   = null;
-	$filename = wp_normalize_path( realpath( $filename ) );
+	$normalized_filename = wp_normalize_path( realpath( $filename ) );

-	if ( ! $filename ) {
+	if ( ! $normalized_filename ) {
 		wp_trigger_error(
 			__FUNCTION__,
 			sprintf(
@@ -4825,11 +4825,22 @@ function wp_json_file_decode( $filename, $options = array() ) {
 				$filename
 			)
 		);
-		return $result;
+		return null;
+	}
+	if ( ! is_file( $normalized_filename ) || ! is_readable( $normalized_filename ) ) {
+		wp_trigger_error(
+			__FUNCTION__,
+			sprintf(
+				/* translators: %s: Path to the JSON file. */
+				__( '%s is not a readable file.' ),
+				$filename
+			)
+		);
+		return null;
 	}

 	$options      = wp_parse_args( $options, array( 'associative' => false ) );
-	$decoded_file = json_decode( file_get_contents( $filename ), $options['associative'] );
+	$decoded_file = json_decode( file_get_contents( $normalized_filename ), $options['associative'] );

 	if ( JSON_ERROR_NONE !== json_last_error() ) {
 		wp_trigger_error(
@@ -4841,7 +4852,7 @@ function wp_json_file_decode( $filename, $options = array() ) {
 				json_last_error_msg()
 			)
 		);
-		return $result;
+		return null;
 	}

 	return $decoded_file;
diff --git a/wp-includes/version.php b/wp-includes/version.php
index b8f20c249a..6e6775799a 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65805';
+$wp_version = '7.3-alpha-65806';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.