roots / sage

WordPress starter theme with Laravel Blade components and templates, Tailwind CSS, and a modern development workflow
https://roots.io/sage/
MIT License
12.77k stars 3.06k forks source link

Sage 9 + Wordpress 6.3 : Notice: Error when decoding a JSON file at path... #3143

Closed ligne13 closed 1 year ago

ligne13 commented 1 year ago

Version

9.0.9

What did you expect to happen?

I expect my old theme built with Sage 9 to work with the latest version of Wordpress 6.3.

What actually happens?

The theme works but I get a Notice message on the page :

Notice: Error when decoding a JSON file at path /wp-content/themes/sage/resources : Syntax error in /wp-includes/functions.php on line 4579

The errors seems to come from the add_filter call in resources/functions.php:

array_map( 'add_filter', ['theme_file_path', 'theme_file_uri', 'parent_theme_file_path', 'parent_theme_file_uri'], array_fill(0, 4, 'dirname') );

This filter removes the file name from the theme_file_path variable (=> dirname).

Steps to reproduce

Use a Sage 9 theme with Wordpress 6.3.

System info

No response

Log output

No response

Please confirm this isn't a support request.

Yes

figureone commented 1 year ago

We are seeing this also on WordPress 6.3 and narrowed it down to a check for theme.json here: https://github.com/WordPress/wordpress-develop/blob/6.3/src/wp-includes/class-wp-theme-json-resolver.php#L242-L243 Since theme_file_path discards the filename, but is_readable() still is true because the directory is readable, we end up with the error.

Full stack trace for us:

#00 /wp-includes/class-wp-theme-json-resolver.php(110): wp_json_file_decode('/wp-content/themes/sage/resources', ['associative' => true])
#01 /wp-includes/class-wp-theme-json-resolver.php(244): read_json_file('/wp-content/themes/sage/resources')
#02 /wp-includes/class-wp-theme-json-resolver.php(591): get_theme_data()
#03 /wp-includes/global-styles-and-settings.php(80): get_merged_data('theme')
#04 /wp-includes/block-supports/typography.php(500): wp_get_global_settings()
#05 /wp-includes/class-wp-theme-json.php(1696): wp_get_typography_font_size_value(...)
#06 /wp-includes/class-wp-theme-json.php(1773): get_settings_values_by_slug(...)
#07 /wp-includes/class-wp-theme-json.php(1516): compute_preset_vars(...)
#08 /wp-includes/class-wp-theme-json.php(1072): get_css_variables(...)
#09 /wp-includes/global-styles-and-settings.php(206): get_stylesheet(...)
#10 /wp-includes/script-loader.php(2467): wp_get_global_stylesheet()
#11 /wp-includes/class-wp-hook.php(310): wp_enqueue_global_styles('')
#12 /wp-includes/class-wp-hook.php(334): apply_filters(NULL, [0 => ''])
#13 /wp-includes/plugin.php(517): do_action([0 => ''])
#14 /wp-includes/script-loader.php(2225): do_action('wp_enqueue_scripts')
#15 /wp-includes/class-wp-hook.php(310): wp_enqueue_scripts('')
#16 /wp-includes/class-wp-hook.php(334): apply_filters(NULL, [0 => ''])
#17 /wp-includes/plugin.php(517): do_action([0 => ''])
#18 /wp-content/themes/sage/app/filters.php(96): do_action('wp_head')
#19 /wp-content/themes/sage/vendor/illuminate/collections/Traits/EnumeratesValues.php(245): App\{closure}('wp_head', 1)
#20 /wp-content/themes/sage/app/filters.php(102): each(Closure::__set_state(array()))
#21 /wp-includes/class-wp-hook.php(310): App\{closure}('/wp-content/themes/sage/resources/views/single-work.blade.php')
#22 /wp-includes/plugin.php(205): apply_filters('/wp-content/themes/sage/resources/views/single-work.blade.php', array(0 => '/wp-content/themes/sage/resources/views/single-work.blade.php',))
#23 /wp-includes/template-loader.php(104): apply_filters('template_include', '/wp-content/themes/sage/resources/views/single-work.blade.php')
#24 /wp-blog-header.php(19): require_once('/wp-includes/template-loader.php')
#25 /index.php(17): require('/wp-blog-header.php')
oxyc commented 1 year ago

A quickfix I used was changing it to:

foreach (['theme_file_path', 'theme_file_uri', 'parent_theme_file_path', 'parent_theme_file_uri'] as $hook) {
    add_filter($hook, function ($path) {
        if (is_file($path)) {
            return $path;
        }
        return dirname($path);
    });
}
ligne13 commented 1 year ago

@oxyc Thanks ! I also had to create a dummy theme.json file inside the resources directory with just an empty object:

resources/theme.json

{}