Sage 9 file_get_contents warnings after update WP to 6.3

Hi!
I have couple of WordPress pages with Sage 9 theme and after last WP update to 6.3 i have warnings:

**Warning** : file_get_contents(C:/wordpress/sitefolder/app/public/wp-content/themes/themename/resources): Failed to open stream: Permission denied in **C:\wordpress\sitefolder\app\public\wp-includes\functions.php** on line **4570**

Anyone have this warnings? I searched for answers but no luck yet.

This seems like a permissions error. Have you tried resetting file permissions on the server? sometimes they can get changed when a new update comes out.

Hi, we also get the following messages on our sites with Sage 9, Sage 10 works without problems.

**Notice** : file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory in**/srv/www/.../current/web/wp/wp-includes/functions.php** on line**4570**

**Notice** : Fehler beim Dekodieren einer JSON-Datei unter /srv/www/.../current/web/app/themes/...-theme/resources: Syntax error in**/srv/www/.../current/web/wp/wp-includes/functions.php** on line**4578**

**Notice** : file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory in**/srv/www/.../current/web/wp/wp-includes/functions.php** on line**4570**

**Notice** : Fehler beim Dekodieren einer JSON-Datei unter /srv/www/.../current/web/app/themes/...-theme/resources: Syntax error in**/srv/www/.../current/web/wp/wp-includes/functions.php** on line**4578**

It doesn’t say anything about permissions, but it could be the same source of the problem.
I think that the theme.json is needed, which does not exist in Sage 9. But simply creating one did not work.

File permissions are ok. This is more detailed info about this warning from second site:

File app/filters.php referring to this:

add_filter('template_include', function ($template) {
    collect(['get_header', 'wp_head'])->each(function ($tag) {
        ob_start();
        do_action($tag);
        $output = ob_get_clean();
        remove_all_actions($tag);
        add_action($tag, function () use ($output) {
            echo $output;
        });
    });
    $data = collect(get_body_class())->reduce(function ($data, $class) use ($template) {
        return apply_filters("sage/template/{$class}/data", $data, $template);
    }, []);
    if ($template) {
        echo template($template, $data);
        return get_stylesheet_directory().'/index.php';
    }
    return $template;
}, PHP_INT_MAX);

so it probably will be something with blade rendering?

In Wordpress 6.3 the code in the file class-wp-theme-json-resolver.php was changed.

...
$theme_json_file = static::get_file_path_from_theme( 'theme.json' );
$wp_theme        = wp_get_theme();
if ( '' !== $theme_json_file ) {
	$theme_json_data = static::read_json_file( $theme_json_file );
...

Is now:

...
$wp_theme        = wp_get_theme();
$theme_json_file = $wp_theme->get_file_path( 'theme.json' );
if ( is_readable( $theme_json_file ) ) {
	$theme_json_data = static::read_json_file( $theme_json_file );
...

If you put a theme.json in /themes/themename/resources, nothing happens. You get back an empty array. But if you change $theme_json_file = $wp_theme->get_file_path( 'theme.json' ); to $theme_json_file = '/srv/www/.../current/web/app/themes/...-theme/resources/theme.json'; the warnings are gone .

But that is not a good solution :frowning:

1 Like

Thank you for pointing me in the right direction! Using the filter in get_file_path, we can manually override the function’s return value to tell WP we don’t have a theme.json file. Adding this in filters.php did the trick for me:

add_filter('theme_file_path', function($path, $file) {
    if($file === 'theme.json') {
        return false;
    }
    return $path;
}, 0, 2);
12 Likes

thanks! Your solution it works :slight_smile:

The proposed solution doesn’t work for themes WITH a theme.json file. This is an alternative solution that works in both cases (replace in functions.php):

array_map(
    'add_filter',
    ['theme_file_uri', 'parent_theme_file_path', 'parent_theme_file_uri'],
    array_fill(0, 3, 'dirname')
);
add_filter('theme_file_path', function ($path, $file) {
    if ($file === 'theme.json') {
        return $path;
    }
    return dirname($path);
}, 10, 2);
3 Likes

this broke my site btw. The other one didnt

Thank you so much, this worked perfectly and now have no errors on my Sage9 theme running on PHP8. Thank you for sharing that.