Make WordPress Core

Opened 5 months ago

Last modified 4 months ago

#63572 new defect (bug)

theme.json file variable could be a directory, add check to prevent notices

Reported by: ramon-fincken's profile ramon fincken Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: Themes Keywords: has-patch needs-test-info
Focuses: Cc:

Description

In class-wp-theme-json-resolver.php

https://github.com/WordPress/wordpress-develop/blob/6.8.1/src/wp-includes/class-wp-theme-json-resolver.php#L254

is the line

if ( is_readable( $theme_json_file ) ) {

However if the $theme_json_file is a directory that will return true, even if it expects a .json local file path.

In this patch I propose adding is_file ( and perhaps even removing is_readable, as is_readable will also return true for directories ).

Change History (3)

This ticket was mentioned in PR #8988 on WordPress/wordpress-develop by @ramon fincken.


5 months ago
#1

In this patch I propose adding is_file ( and perhaps even removing is_readable, as is_readable will also return true for directories ).

Trac
https://core.trac.wordpress.org/ticket/63572#ticket

#2 @poena
4 months ago

  • Keywords needs-test-info added

Hi @ramon-fincken
Can you please include step by step instructions how to reproduce this and test the patch?
(As in first creating a directory called theme.json, what issue is being prevented, what are the notices, and what the expected outcome of the patch is.)

#3 @ramon fincken
4 months ago

If this is added in themes/themename/resources

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

The call will fail without that file check.
I agree this is an error on the theme developers end, therefore we as WP Core must insert an improved "if" handler.

Note: See TracTickets for help on using tickets.