WP_Theme_JSON::update_paragraph_text_indent_selectorprivate staticWP 7.0.0

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

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.

Метод класса: WP_Theme_JSON{}

Хуков нет.

Возвращает

Массив. The updated feature declarations.

Использование

$result = WP_Theme_JSON::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name );
$feature_declarations(массив) (обязательный)
The feature declarations keyed by selector.
$settings(массив) (обязательный)
The theme.json settings.
$block_name(строка) (обязательный)
The block name being processed.

Список изменений

С версии 7.0.0 Введена.

Код WP_Theme_JSON::update_paragraph_text_indent_selector() WP 7.0

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;
}