[wp-trac] [WordPress Trac] #64620: function read_json_file throws an error if the file is missing
WordPress Trac
noreply at wordpress.org
Wed Feb 18 07:29:10 UTC 2026
#64620: function read_json_file throws an error if the file is missing
-------------------------------------------------+-------------------------
Reporter: pbearne | Owner: pbearne
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 7.0
Component: Themes | Version: 5.8
Severity: normal | Resolution:
Keywords: has-patch reporter-feedback | Focuses:
changes-requested |
-------------------------------------------------+-------------------------
Changes (by ozgursar):
* keywords: has-patch needs-testing reporter-feedback changes-requested =>
has-patch reporter-feedback changes-requested
Comment:
== Patch Testing Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/10898
=== Environment
- WordPress: 7.0-alpha-61215-src
- PHP: 8.2.29
- Server: nginx/1.29.4
- Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
- Browser: Chrome 145.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.4
- MU Plugins: None activated
- Plugins:
* Code Snippets 3.9.5
* Test Reports 1.2.1
=== Steps taken
As `read_json_file` is protected, I had to subclass it to reproduce the
notice using the code snippet below.
1. Add the snippet via `Code Snippets` plugin or `functions.php` to print
out the notice
2. View any page in the `Dashboard` to display the `notice`
3. ✅ Patch is solving the problem
=== Expected result
- When `read_json_file()` is called with a path to a non-existent file, it
should return an empty array silently without triggering a PHP notice.
=== Screenshots/Screencast with results
Before applying patch:
[[Image(https://i.imgur.com/9F63wM3.png)]]
After applying patch:
[[Image(https://i.imgur.com/9kbD2Ir.png)]]
=== Support Content
- Code snippet below is created with the help of `Claude.ai`
{{{
add_action( 'admin_notices', function() {
class Test_Read_Json_File extends WP_Theme_JSON_Resolver {
public static function test_read_json_file( $file_path ) {
return parent::read_json_file( $file_path );
}
}
$missing_file = get_theme_file_path( 'missing-file.json' );
ob_start();
$result = Test_Read_Json_File::test_read_json_file( $missing_file );
$output = ob_get_clean();
echo '<div class="notice ' . ( $output ? 'notice-error' : 'notice-
success' ) . '"><p>';
echo '<strong>Testing <code>read_json_file()</code> with missing
file:</strong><br>';
echo 'File exists: ' . ( file_exists( $missing_file ) ? 'YES' : 'NO' )
. '<br>';
echo 'Result: <code>' . esc_html( var_export( $result, true ) ) .
'</code><br>';
echo 'Notice thrown: ' . ( $output ? '<strong style="color:red">' .
esc_html( $output ) . '</strong>' : 'none ✓' );
echo '</p></div>';
} );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64620#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list