Opened 7 weeks ago
Last modified 10 days ago
#64620 assigned defect (bug)
function read_json_file throws an error if the file is missing
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.1 | Priority: | normal |
| Severity: | normal | Version: | 5.8 |
| Component: | Themes | Keywords: | has-patch reporter-feedback changes-requested |
| Focuses: | Cc: |
Description
I got a notice if the file trying to load is missing
Change History (9)
This ticket was mentioned in PR #10898 on WordPress/wordpress-develop by @pbearne.
7 weeks ago
#1
- Keywords has-patch added
#2
@
7 weeks ago
- Milestone changed from Awaiting Review to 7.0
- Owner set to pbearne
- Status changed from new to assigned
- Version set to 6.8
#4
@
6 weeks ago
- Keywords reporter-feedback changes-requested added
- Version changed from 6.8 to 5.8
The function introduce in 5.8
#5
@
6 weeks ago
- Keywords needs-testing removed
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.
- Add the snippet via
Code Snippetsplugin orfunctions.phpto print out the notice - View any page in the
Dashboardto display thenotice - ✅ 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
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>';
} );
This ticket was mentioned in Slack in #core-performance by westonruter. View the logs.
5 weeks ago
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
10 days ago
Note: See
TracTickets for help on using
tickets.


… potential errors.