WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 2 months ago

#53738 closed defect (bug) (fixed)

Broken loop in WP_Theme_JSON_Resolver

Reported by: schlessera Owned by: desrosj
Milestone: 5.8.1 Priority: normal
Severity: normal Version:
Component: Themes Keywords: fixed-major
Focuses: Cc:

Description

Originally reported at https://github.com/WordPress/gutenberg/issues/33552.

The loop in WP_Theme_JSON_Resolver to extract translatable paths is broken, as it contains an immediate and unconditional return. This causes the loop to immediately exit again after the first iteration, thus never actually looping.

foreach ( $partial_child as $key => $context ) { 
	return array( 
		array( 
			'path'    => $current_path, 
			'key'     => $key, 
			'context' => $context, 
		), 
	); 
} 

This means that the extraction only works where there's only a single item in the array of translatable strings per section (i.e. the 'name' field).

The suggested code would be:

foreach ( $partial_child as $key => $context ) { 
	$result[] = array(
		'path'    => $current_path, 
		'key'     => $key, 
		'context' => $context, 
	);
}
return $result;

Change History (3)

#1 @SergeyBiryukov
2 months ago

  • Reporter changed from SergeyBiryukov to schlessera

Changing the Reporter field to the reporter of the original issue.

#2 @SergeyBiryukov
2 months ago

This was fixed for 5.9 in [51472].

This ticket was created for 5.8.1 consideration, per the Slack discussion.

#3 @desrosj
2 months ago

  • Owner set to desrosj
  • Resolution set to fixed
  • Status changed from new to closed

In 51515:

I18n: Fix broken loop in WP_Theme_JSON_Resolver

Related issue in Gutenberg: https://github.com/WordPress/gutenberg/issues/33552.

The loop in WP_Theme_JSON_Resolver to extract translatable paths was broken, as it contained an immediate and unconditional return. This caused the loop to immediately exit again after the first iteration, thus never actually looping.

Follow-up to [50959].

Props schlessera.
Merges [51472] to the 5.8 branch.
Fixes #53738.

Note: See TracTickets for help on using tickets.