[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Server-side rendering of the `core/search` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Dynamically renders the `core/search` block. 10 * 11 * @since 6.3.0 Using block.json `viewScript` to register script, and update `view_script_handles()` only when needed. 12 * 13 * @param array $attributes The block attributes. 14 * @param string $content The saved content. 15 * @param WP_Block $block The parsed block. 16 * 17 * @return string The search block markup. 18 */ 19 function render_block_core_search( $attributes ) { 20 // Older versions of the Search block defaulted the label and buttonText 21 // attributes to `__( 'Search' )` meaning that many posts contain `<!-- 22 // wp:search /-->`. Support these by defaulting an undefined label and 23 // buttonText to `__( 'Search' )`. 24 $attributes = wp_parse_args( 25 $attributes, 26 array( 27 'label' => __( 'Search' ), 28 'buttonText' => __( 'Search' ), 29 ) 30 ); 31 32 $input_id = wp_unique_id( 'wp-block-search__input-' ); 33 $classnames = classnames_for_block_core_search( $attributes ); 34 $show_label = ( ! empty( $attributes['showLabel'] ) ) ? true : false; 35 $use_icon_button = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false; 36 $show_button = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true; 37 $button_position = $show_button ? $attributes['buttonPosition'] : null; 38 $query_params = ( ! empty( $attributes['query'] ) ) ? $attributes['query'] : array(); 39 $button = ''; 40 $query_params_markup = ''; 41 $inline_styles = styles_for_block_core_search( $attributes ); 42 $color_classes = get_color_classes_for_block_core_search( $attributes ); 43 $typography_classes = get_typography_classes_for_block_core_search( $attributes ); 44 $is_button_inside = ! empty( $attributes['buttonPosition'] ) && 45 'button-inside' === $attributes['buttonPosition']; 46 // Border color classes need to be applied to the elements that have a border color. 47 $border_color_classes = get_border_color_classes_for_block_core_search( $attributes ); 48 // This variable is a constant and its value is always false at this moment. 49 // It is defined this way because some values depend on it, in case it changes in the future. 50 $open_by_default = false; 51 52 $label_inner_html = empty( $attributes['label'] ) ? __( 'Search' ) : wp_kses_post( $attributes['label'] ); 53 $label = new WP_HTML_Tag_Processor( sprintf( '<label %1$s>%2$s</label>', $inline_styles['label'], $label_inner_html ) ); 54 if ( $label->next_tag() ) { 55 $label->set_attribute( 'for', $input_id ); 56 $label->add_class( 'wp-block-search__label' ); 57 if ( $show_label && ! empty( $attributes['label'] ) ) { 58 if ( ! empty( $typography_classes ) ) { 59 $label->add_class( $typography_classes ); 60 } 61 } else { 62 $label->add_class( 'screen-reader-text' ); 63 } 64 } 65 66 $input = new WP_HTML_Tag_Processor( sprintf( '<input type="search" name="s" required %s/>', $inline_styles['input'] ) ); 67 $input_classes = array( 'wp-block-search__input' ); 68 if ( ! $is_button_inside && ! empty( $border_color_classes ) ) { 69 $input_classes[] = $border_color_classes; 70 } 71 if ( ! empty( $typography_classes ) ) { 72 $input_classes[] = $typography_classes; 73 } 74 if ( $input->next_tag() ) { 75 $input->add_class( implode( ' ', $input_classes ) ); 76 $input->set_attribute( 'id', $input_id ); 77 $input->set_attribute( 'value', get_search_query() ); 78 $input->set_attribute( 'placeholder', $attributes['placeholder'] ); 79 80 // If it's interactive, enqueue the script module and add the directives. 81 $is_expandable_searchfield = 'button-only' === $button_position; 82 if ( $is_expandable_searchfield ) { 83 $suffix = wp_scripts_get_suffix(); 84 if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { 85 $module_url = gutenberg_url( '/build/interactivity/search.min.js' ); 86 } 87 88 wp_register_script_module( 89 '@wordpress/block-library/search', 90 isset( $module_url ) ? $module_url : includes_url( "blocks/search/view{$suffix}.js" ), 91 array( '@wordpress/interactivity' ), 92 defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) 93 ); 94 wp_enqueue_script_module( '@wordpress/block-library/search' ); 95 96 $input->set_attribute( 'data-wp-bind--aria-hidden', '!context.isSearchInputVisible' ); 97 $input->set_attribute( 'data-wp-bind--tabindex', 'state.tabindex' ); 98 99 // Adding these attributes manually is needed until the Interactivity API 100 // SSR logic is added to core. 101 $input->set_attribute( 'aria-hidden', 'true' ); 102 $input->set_attribute( 'tabindex', '-1' ); 103 } 104 } 105 106 if ( count( $query_params ) > 0 ) { 107 foreach ( $query_params as $param => $value ) { 108 $query_params_markup .= sprintf( 109 '<input type="hidden" name="%s" value="%s" />', 110 esc_attr( $param ), 111 esc_attr( $value ) 112 ); 113 } 114 } 115 116 if ( $show_button ) { 117 $button_classes = array( 'wp-block-search__button' ); 118 $button_internal_markup = ''; 119 if ( ! empty( $color_classes ) ) { 120 $button_classes[] = $color_classes; 121 } 122 if ( ! empty( $typography_classes ) ) { 123 $button_classes[] = $typography_classes; 124 } 125 126 if ( ! $is_button_inside && ! empty( $border_color_classes ) ) { 127 $button_classes[] = $border_color_classes; 128 } 129 if ( ! $use_icon_button ) { 130 if ( ! empty( $attributes['buttonText'] ) ) { 131 $button_internal_markup = wp_kses_post( $attributes['buttonText'] ); 132 } 133 } else { 134 $button_classes[] = 'has-icon'; 135 $button_internal_markup = 136 '<svg class="search-icon" viewBox="0 0 24 24" width="24" height="24"> 137 <path d="M13 5c-3.3 0-6 2.7-6 6 0 1.4.5 2.7 1.3 3.7l-3.8 3.8 1.1 1.1 3.8-3.8c1 .8 2.3 1.3 3.7 1.3 3.3 0 6-2.7 6-6S16.3 5 13 5zm0 10.5c-2.5 0-4.5-2-4.5-4.5s2-4.5 4.5-4.5 4.5 2 4.5 4.5-2 4.5-4.5 4.5z"></path> 138 </svg>'; 139 } 140 141 // Include the button element class. 142 $button_classes[] = wp_theme_get_element_class_name( 'button' ); 143 $button = new WP_HTML_Tag_Processor( sprintf( '<button type="submit" %s>%s</button>', $inline_styles['button'], $button_internal_markup ) ); 144 145 if ( $button->next_tag() ) { 146 $button->add_class( implode( ' ', $button_classes ) ); 147 if ( 'button-only' === $attributes['buttonPosition'] ) { 148 $button->set_attribute( 'data-wp-bind--aria-label', 'state.ariaLabel' ); 149 $button->set_attribute( 'data-wp-bind--aria-controls', 'state.ariaControls' ); 150 $button->set_attribute( 'data-wp-bind--aria-expanded', 'context.isSearchInputVisible' ); 151 $button->set_attribute( 'data-wp-bind--type', 'state.type' ); 152 $button->set_attribute( 'data-wp-on--click', 'actions.openSearchInput' ); 153 154 // Adding these attributes manually is needed until the Interactivity 155 // API SSR logic is added to core. 156 $button->set_attribute( 'aria-label', __( 'Expand search field' ) ); 157 $button->set_attribute( 'aria-controls', 'wp-block-search__input-' . $input_id ); 158 $button->set_attribute( 'aria-expanded', 'false' ); 159 $button->set_attribute( 'type', 'button' ); 160 } else { 161 $button->set_attribute( 'aria-label', wp_strip_all_tags( $attributes['buttonText'] ) ); 162 } 163 } 164 } 165 166 $field_markup_classes = $is_button_inside ? $border_color_classes : ''; 167 $field_markup = sprintf( 168 '<div class="wp-block-search__inside-wrapper %s" %s>%s</div>', 169 esc_attr( $field_markup_classes ), 170 $inline_styles['wrapper'], 171 $input . $query_params_markup . $button 172 ); 173 $wrapper_attributes = get_block_wrapper_attributes( 174 array( 'class' => $classnames ) 175 ); 176 $form_directives = ''; 177 178 // If it's interactive, add the directives. 179 if ( $is_expandable_searchfield ) { 180 $aria_label_expanded = __( 'Submit Search' ); 181 $aria_label_collapsed = __( 'Expand search field' ); 182 $form_context = wp_interactivity_data_wp_context( 183 array( 184 'isSearchInputVisible' => $open_by_default, 185 'inputId' => $input_id, 186 'ariaLabelExpanded' => $aria_label_expanded, 187 'ariaLabelCollapsed' => $aria_label_collapsed, 188 ) 189 ); 190 $form_directives = ' 191 data-wp-interactive="core/search"' 192 . $form_context . 193 'data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible" 194 data-wp-on--keydown="actions.handleSearchKeydown" 195 data-wp-on--focusout="actions.handleSearchFocusout" 196 '; 197 } 198 199 return sprintf( 200 '<form role="search" method="get" action="%1s" %2s %3s>%4s</form>', 201 esc_url( home_url( '/' ) ), 202 $wrapper_attributes, 203 $form_directives, 204 $label . $field_markup 205 ); 206 } 207 208 /** 209 * Registers the `core/search` block on the server. 210 */ 211 function register_block_core_search() { 212 register_block_type_from_metadata( 213 __DIR__ . '/search', 214 array( 215 'render_callback' => 'render_block_core_search', 216 ) 217 ); 218 } 219 add_action( 'init', 'register_block_core_search' ); 220 221 /** 222 * Builds the correct top level classnames for the 'core/search' block. 223 * 224 * @param array $attributes The block attributes. 225 * 226 * @return string The classnames used in the block. 227 */ 228 function classnames_for_block_core_search( $attributes ) { 229 $classnames = array(); 230 231 if ( ! empty( $attributes['buttonPosition'] ) ) { 232 if ( 'button-inside' === $attributes['buttonPosition'] ) { 233 $classnames[] = 'wp-block-search__button-inside'; 234 } 235 236 if ( 'button-outside' === $attributes['buttonPosition'] ) { 237 $classnames[] = 'wp-block-search__button-outside'; 238 } 239 240 if ( 'no-button' === $attributes['buttonPosition'] ) { 241 $classnames[] = 'wp-block-search__no-button'; 242 } 243 244 if ( 'button-only' === $attributes['buttonPosition'] ) { 245 $classnames[] = 'wp-block-search__button-only wp-block-search__searchfield-hidden'; 246 } 247 } 248 249 if ( isset( $attributes['buttonUseIcon'] ) ) { 250 if ( ! empty( $attributes['buttonPosition'] ) && 'no-button' !== $attributes['buttonPosition'] ) { 251 if ( $attributes['buttonUseIcon'] ) { 252 $classnames[] = 'wp-block-search__icon-button'; 253 } else { 254 $classnames[] = 'wp-block-search__text-button'; 255 } 256 } 257 } 258 259 return implode( ' ', $classnames ); 260 } 261 262 /** 263 * This generates a CSS rule for the given border property and side if provided. 264 * Based on whether the Search block is configured to display the button inside 265 * or not, the generated rule is injected into the appropriate collection of 266 * styles for later application in the block's markup. 267 * 268 * @param array $attributes The block attributes. 269 * @param string $property Border property to generate rule for e.g. width or color. 270 * @param string $side Optional side border. The dictates the value retrieved and final CSS property. 271 * @param array $wrapper_styles Current collection of wrapper styles. 272 * @param array $button_styles Current collection of button styles. 273 * @param array $input_styles Current collection of input styles. 274 */ 275 function apply_block_core_search_border_style( $attributes, $property, $side, &$wrapper_styles, &$button_styles, &$input_styles ) { 276 $is_button_inside = isset( $attributes['buttonPosition'] ) && 'button-inside' === $attributes['buttonPosition']; 277 278 $path = array( 'style', 'border', $property ); 279 280 if ( $side ) { 281 array_splice( $path, 2, 0, $side ); 282 } 283 284 $value = _wp_array_get( $attributes, $path, false ); 285 286 if ( empty( $value ) ) { 287 return; 288 } 289 290 if ( 'color' === $property && $side ) { 291 $has_color_preset = str_contains( $value, 'var:preset|color|' ); 292 if ( $has_color_preset ) { 293 $named_color_value = substr( $value, strrpos( $value, '|' ) + 1 ); 294 $value = sprintf( 'var(--wp--preset--color--%s)', $named_color_value ); 295 } 296 } 297 298 $property_suffix = $side ? sprintf( '%s-%s', $side, $property ) : $property; 299 300 if ( $is_button_inside ) { 301 $wrapper_styles[] = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) ); 302 } else { 303 $button_styles[] = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) ); 304 $input_styles[] = sprintf( 'border-%s: %s;', $property_suffix, esc_attr( $value ) ); 305 } 306 } 307 308 /** 309 * This adds CSS rules for a given border property e.g. width or color. It 310 * injects rules into the provided wrapper, button and input style arrays for 311 * uniform "flat" borders or those with individual sides configured. 312 * 313 * @param array $attributes The block attributes. 314 * @param string $property Border property to generate rule for e.g. width or color. 315 * @param array $wrapper_styles Current collection of wrapper styles. 316 * @param array $button_styles Current collection of button styles. 317 * @param array $input_styles Current collection of input styles. 318 */ 319 function apply_block_core_search_border_styles( $attributes, $property, &$wrapper_styles, &$button_styles, &$input_styles ) { 320 apply_block_core_search_border_style( $attributes, $property, null, $wrapper_styles, $button_styles, $input_styles ); 321 apply_block_core_search_border_style( $attributes, $property, 'top', $wrapper_styles, $button_styles, $input_styles ); 322 apply_block_core_search_border_style( $attributes, $property, 'right', $wrapper_styles, $button_styles, $input_styles ); 323 apply_block_core_search_border_style( $attributes, $property, 'bottom', $wrapper_styles, $button_styles, $input_styles ); 324 apply_block_core_search_border_style( $attributes, $property, 'left', $wrapper_styles, $button_styles, $input_styles ); 325 } 326 327 /** 328 * Builds an array of inline styles for the search block. 329 * 330 * The result will contain one entry for shared styles such as those for the 331 * inner input or button and a second for the inner wrapper should the block 332 * be positioning the button "inside". 333 * 334 * @param array $attributes The block attributes. 335 * 336 * @return array Style HTML attribute. 337 */ 338 function styles_for_block_core_search( $attributes ) { 339 $wrapper_styles = array(); 340 $button_styles = array(); 341 $input_styles = array(); 342 $label_styles = array(); 343 $is_button_inside = ! empty( $attributes['buttonPosition'] ) && 344 'button-inside' === $attributes['buttonPosition']; 345 $show_label = ( isset( $attributes['showLabel'] ) ) && false !== $attributes['showLabel']; 346 347 // Add width styles. 348 $has_width = ! empty( $attributes['width'] ) && ! empty( $attributes['widthUnit'] ); 349 350 if ( $has_width ) { 351 $wrapper_styles[] = sprintf( 352 'width: %d%s;', 353 esc_attr( $attributes['width'] ), 354 esc_attr( $attributes['widthUnit'] ) 355 ); 356 } 357 358 // Add border width and color styles. 359 apply_block_core_search_border_styles( $attributes, 'width', $wrapper_styles, $button_styles, $input_styles ); 360 apply_block_core_search_border_styles( $attributes, 'color', $wrapper_styles, $button_styles, $input_styles ); 361 apply_block_core_search_border_styles( $attributes, 'style', $wrapper_styles, $button_styles, $input_styles ); 362 363 // Add border radius styles. 364 $has_border_radius = ! empty( $attributes['style']['border']['radius'] ); 365 366 if ( $has_border_radius ) { 367 $default_padding = '4px'; 368 $border_radius = $attributes['style']['border']['radius']; 369 370 if ( is_array( $border_radius ) ) { 371 // Apply styles for individual corner border radii. 372 foreach ( $border_radius as $key => $value ) { 373 if ( null !== $value ) { 374 // Convert camelCase key to kebab-case. 375 $name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $key ) ); 376 377 // Add shared styles for individual border radii for input & button. 378 $border_style = sprintf( 379 'border-%s-radius: %s;', 380 esc_attr( $name ), 381 esc_attr( $value ) 382 ); 383 $input_styles[] = $border_style; 384 $button_styles[] = $border_style; 385 386 // Add adjusted border radius styles for the wrapper element 387 // if button is positioned inside. 388 if ( $is_button_inside && intval( $value ) !== 0 ) { 389 $wrapper_styles[] = sprintf( 390 'border-%s-radius: calc(%s + %s);', 391 esc_attr( $name ), 392 esc_attr( $value ), 393 $default_padding 394 ); 395 } 396 } 397 } 398 } else { 399 // Numeric check is for backwards compatibility purposes. 400 $border_radius = is_numeric( $border_radius ) ? $border_radius . 'px' : $border_radius; 401 $border_style = sprintf( 'border-radius: %s;', esc_attr( $border_radius ) ); 402 $input_styles[] = $border_style; 403 $button_styles[] = $border_style; 404 405 if ( $is_button_inside && intval( $border_radius ) !== 0 ) { 406 // Adjust wrapper border radii to maintain visual consistency 407 // with inner elements when button is positioned inside. 408 $wrapper_styles[] = sprintf( 409 'border-radius: calc(%s + %s);', 410 esc_attr( $border_radius ), 411 $default_padding 412 ); 413 } 414 } 415 } 416 417 // Add color styles. 418 $has_text_color = ! empty( $attributes['style']['color']['text'] ); 419 if ( $has_text_color ) { 420 $button_styles[] = sprintf( 'color: %s;', $attributes['style']['color']['text'] ); 421 } 422 423 $has_background_color = ! empty( $attributes['style']['color']['background'] ); 424 if ( $has_background_color ) { 425 $button_styles[] = sprintf( 'background-color: %s;', $attributes['style']['color']['background'] ); 426 } 427 428 $has_custom_gradient = ! empty( $attributes['style']['color']['gradient'] ); 429 if ( $has_custom_gradient ) { 430 $button_styles[] = sprintf( 'background: %s;', $attributes['style']['color']['gradient'] ); 431 } 432 433 // Get typography styles to be shared across inner elements. 434 $typography_styles = esc_attr( get_typography_styles_for_block_core_search( $attributes ) ); 435 if ( ! empty( $typography_styles ) ) { 436 $label_styles [] = $typography_styles; 437 $button_styles[] = $typography_styles; 438 $input_styles [] = $typography_styles; 439 } 440 441 // Typography text-decoration is only applied to the label and button. 442 if ( ! empty( $attributes['style']['typography']['textDecoration'] ) ) { 443 $text_decoration_value = sprintf( 'text-decoration: %s;', esc_attr( $attributes['style']['typography']['textDecoration'] ) ); 444 $button_styles[] = $text_decoration_value; 445 // Input opts out of text decoration. 446 if ( $show_label ) { 447 $label_styles[] = $text_decoration_value; 448 } 449 } 450 451 return array( 452 'input' => ! empty( $input_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $input_styles ) ) ) ) : '', 453 'button' => ! empty( $button_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $button_styles ) ) ) ) : '', 454 'wrapper' => ! empty( $wrapper_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $wrapper_styles ) ) ) ) : '', 455 'label' => ! empty( $label_styles ) ? sprintf( ' style="%s"', esc_attr( safecss_filter_attr( implode( ' ', $label_styles ) ) ) ) : '', 456 ); 457 } 458 459 /** 460 * Returns typography classnames depending on whether there are named font sizes/families . 461 * 462 * @param array $attributes The block attributes. 463 * 464 * @return string The typography color classnames to be applied to the block elements. 465 */ 466 function get_typography_classes_for_block_core_search( $attributes ) { 467 $typography_classes = array(); 468 $has_named_font_family = ! empty( $attributes['fontFamily'] ); 469 $has_named_font_size = ! empty( $attributes['fontSize'] ); 470 471 if ( $has_named_font_size ) { 472 $typography_classes[] = sprintf( 'has-%s-font-size', esc_attr( $attributes['fontSize'] ) ); 473 } 474 475 if ( $has_named_font_family ) { 476 $typography_classes[] = sprintf( 'has-%s-font-family', esc_attr( $attributes['fontFamily'] ) ); 477 } 478 479 return implode( ' ', $typography_classes ); 480 } 481 482 /** 483 * Returns typography styles to be included in an HTML style tag. 484 * This excludes text-decoration, which is applied only to the label and button elements of the search block. 485 * 486 * @param array $attributes The block attributes. 487 * 488 * @return string A string of typography CSS declarations. 489 */ 490 function get_typography_styles_for_block_core_search( $attributes ) { 491 $typography_styles = array(); 492 493 // Add typography styles. 494 if ( ! empty( $attributes['style']['typography']['fontSize'] ) ) { 495 $typography_styles[] = sprintf( 496 'font-size: %s;', 497 wp_get_typography_font_size_value( 498 array( 499 'size' => $attributes['style']['typography']['fontSize'], 500 ) 501 ) 502 ); 503 504 } 505 506 if ( ! empty( $attributes['style']['typography']['fontFamily'] ) ) { 507 $typography_styles[] = sprintf( 'font-family: %s;', $attributes['style']['typography']['fontFamily'] ); 508 } 509 510 if ( ! empty( $attributes['style']['typography']['letterSpacing'] ) ) { 511 $typography_styles[] = sprintf( 'letter-spacing: %s;', $attributes['style']['typography']['letterSpacing'] ); 512 } 513 514 if ( ! empty( $attributes['style']['typography']['fontWeight'] ) ) { 515 $typography_styles[] = sprintf( 'font-weight: %s;', $attributes['style']['typography']['fontWeight'] ); 516 } 517 518 if ( ! empty( $attributes['style']['typography']['fontStyle'] ) ) { 519 $typography_styles[] = sprintf( 'font-style: %s;', $attributes['style']['typography']['fontStyle'] ); 520 } 521 522 if ( ! empty( $attributes['style']['typography']['lineHeight'] ) ) { 523 $typography_styles[] = sprintf( 'line-height: %s;', $attributes['style']['typography']['lineHeight'] ); 524 } 525 526 if ( ! empty( $attributes['style']['typography']['textTransform'] ) ) { 527 $typography_styles[] = sprintf( 'text-transform: %s;', $attributes['style']['typography']['textTransform'] ); 528 } 529 530 return implode( '', $typography_styles ); 531 } 532 533 /** 534 * Returns border color classnames depending on whether there are named or custom border colors. 535 * 536 * @param array $attributes The block attributes. 537 * 538 * @return string The border color classnames to be applied to the block elements. 539 */ 540 function get_border_color_classes_for_block_core_search( $attributes ) { 541 $border_color_classes = array(); 542 $has_custom_border_color = ! empty( $attributes['style']['border']['color'] ); 543 $has_named_border_color = ! empty( $attributes['borderColor'] ); 544 545 if ( $has_custom_border_color || $has_named_border_color ) { 546 $border_color_classes[] = 'has-border-color'; 547 } 548 549 if ( $has_named_border_color ) { 550 $border_color_classes[] = sprintf( 'has-%s-border-color', esc_attr( $attributes['borderColor'] ) ); 551 } 552 553 return implode( ' ', $border_color_classes ); 554 } 555 556 /** 557 * Returns color classnames depending on whether there are named or custom text and background colors. 558 * 559 * @param array $attributes The block attributes. 560 * 561 * @return string The color classnames to be applied to the block elements. 562 */ 563 function get_color_classes_for_block_core_search( $attributes ) { 564 $classnames = array(); 565 566 // Text color. 567 $has_named_text_color = ! empty( $attributes['textColor'] ); 568 $has_custom_text_color = ! empty( $attributes['style']['color']['text'] ); 569 if ( $has_named_text_color ) { 570 $classnames[] = sprintf( 'has-text-color has-%s-color', $attributes['textColor'] ); 571 } elseif ( $has_custom_text_color ) { 572 // If a custom 'textColor' was selected instead of a preset, still add the generic `has-text-color` class. 573 $classnames[] = 'has-text-color'; 574 } 575 576 // Background color. 577 $has_named_background_color = ! empty( $attributes['backgroundColor'] ); 578 $has_custom_background_color = ! empty( $attributes['style']['color']['background'] ); 579 $has_named_gradient = ! empty( $attributes['gradient'] ); 580 $has_custom_gradient = ! empty( $attributes['style']['color']['gradient'] ); 581 if ( 582 $has_named_background_color || 583 $has_custom_background_color || 584 $has_named_gradient || 585 $has_custom_gradient 586 ) { 587 $classnames[] = 'has-background'; 588 } 589 if ( $has_named_background_color ) { 590 $classnames[] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] ); 591 } 592 if ( $has_named_gradient ) { 593 $classnames[] = sprintf( 'has-%s-gradient-background', $attributes['gradient'] ); 594 } 595 596 return implode( ' ', $classnames ); 597 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Apr 20 08:20:01 2024 | Cross-referenced by PHPXref |