WP_Theme_JSON::update_paragraph_text_indent_selector
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.
Method of the class: WP_Theme_JSON{}
No Hooks.
Returns
Array. The updated feature declarations.
Usage
$result = WP_Theme_JSON::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name );
- $feature_declarations(array) (required)
- The feature declarations keyed by selector.
- $settings(array) (required)
- The theme.json settings.
- $block_name(string) (required)
- The block name being processed.
Changelog
| Since 7.0.0 | Introduced. |
WP_Theme_JSON::update_paragraph_text_indent_selector() WP Theme JSON::update paragraph text indent selector code 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;
}