WP_Theme_JSON::update_paragraph_text_indent_selector( array $feature_declarations, array $settings, string $block_name ): array

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Updates the text indent selector for paragraph blocks based on the textIndent setting.

Description

The textIndent setting can be ‘subsequent’ (default), ‘all’, or false.
When set to ‘all’, the selector should be ‘.wp-block-paragraph’ instead of ‘.wp-block-paragraph + .wp-block-paragraph’ to apply indent to all paragraphs.

Parameters

$feature_declarationsarrayrequired
The feature declarations keyed by selector.
$settingsarrayrequired
The theme.json settings.
$block_namestringrequired
The block name being processed.

Return

array The updated feature declarations.

Source

private static function update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name ) {
	if ( 'core/paragraph' !== $block_name ) {
		return $feature_declarations;
	}

	// Check block-level settings first, then fall back to global settings.
	$block_settings      = $settings['blocks']['core/paragraph'] ?? null;
	$text_indent_setting = $block_settings['typography']['textIndent']
		?? $settings['typography']['textIndent']
		?? 'subsequent';

	if ( 'all' !== $text_indent_setting ) {
		return $feature_declarations;
	}

	// Look for the text indent selector and replace it.
	$old_selector = '.wp-block-paragraph + .wp-block-paragraph';
	$new_selector = '.wp-block-paragraph';

	if ( isset( $feature_declarations[ $old_selector ] ) ) {
		$declarations = $feature_declarations[ $old_selector ];
		unset( $feature_declarations[ $old_selector ] );
		$feature_declarations[ $new_selector ] = $declarations;
	}

	return $feature_declarations;
}

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.