d> 2 年之前 16793 058f31828c first commit 2 年之前 16795 058f31828c first commit 2 年之前 16797 058f31828c first commit 2 年之前 16800 058f31828c first commit 2 年之前 16802 058f31828c first commit 2 年之前 16803 058f31828c first commit 2 年之前 16805 058f31828c first commit 2 年之前 16807 058f31828c first commit 2 年之前 16810 058f31828c first commit 2 年之前 16812 058f31828c first commit 2 年之前 16814 058f31828c first commit 2 年之前 16817 058f31828c first commit 2 年之前 16819 058f31828c first commit 2 年之前 16821 058f31828c first commit 2 年之前 16824 058f31828c first commit 2 年之前 16831 058f31828c first commit 2 年之前 16832 058f31828c first commit 2 年之前 16843 058f31828c first commit 2 年之前 16844 058f31828c first commit 2 年之前 16850 058f31828c first commit 2 年之前 16856 058f31828c first commit 2 年之前 16862 058f31828c first commit 2 年之前 16868 058f31828c first commit 2 年之前 16869 058f31828c first commit 2 年之前 16871 058f31828c first commit 2 年之前 16874 058f31828c first commit 2 年之前 16876 058f31828c first commit 2 年之前 16877 058f31828c first commit 2 年之前 16879 058f31828c first commit 2 年之前 16887 058f31828c first commit 2 年之前 16889 058f31828c first commit 2 年之前 16892 058f31828c first commit 2 年之前 16896 058f31828c first commit 2 年之前 16898 058f31828c first commit 2 年之前 16901 058f31828c first commit 2 年之前 16903 058f31828c first commit 2 年之前 16911 058f31828c first commit 2 年之前 16917 058f31828c first commit 2 年之前 16918 058f31828c first commit 2 年之前 16922 058f31828c first commit 2 年之前 16924 058f31828c first commit 2 年之前 16926 058f31828c first commit 2 年之前 16927 058f31828c first commit 2 年之前 16928 058f31828c first commit 2 年之前 16929 058f31828c first commit 2 年之前 16932 058f31828c first commit 2 年之前 16934 058f31828c first commit 2 年之前 16941 058f31828c first commit 2 年之前 16942 058f31828c first commit 2 年之前 16944 058f31828c first commit 2 年之前 16947 058f31828c first commit 2 年之前 16949 058f31828c first commit 2 年之前 16951 058f31828c first commit 2 年之前 16952 058f31828c first commit 2 年之前 16962 058f31828c first commit 2 年之前 16964 058f31828c first commit 2 年之前 16967 058f31828c first commit 2 年之前 16969 058f31828c first commit 2 年之前 16971 058f31828c first commit 2 年之前 16974 058f31828c first commit 2 年之前 16976 058f31828c first commit 2 年之前 16978 058f31828c first commit 2 年之前 16981 058f31828c first commit 2 年之前 16983 058f31828c first commit 2 年之前 16984 058f31828c first commit 2 年之前 16986 058f31828c first commit 2 年之前 16996 058f31828c first commit 2 年之前 17008 058f31828c first commit 2 年之前 17009 058f31828c first commit 2 年之前 17020 058f31828c first commit 2 年之前 17021 058f31828c first commit 2 年之前 17022 058f31828c first commit 2 年之前 17024 058f31828c first commit 2 年之前 17034 058f31828c first commit 2 年之前 17037 058f31828c first commit 2 年之前 17039 058f31828c first commit 2 年之前 17040 058f31828c first commit 2 年之前 17041 058f31828c first commit 2 年之前 17042 058f31828c first commit 2 年之前 174 058f31828c first commit 2 年之前 175 058f31828c first commit 2 年之前 2187 058f31828c first commit 2 年之前 2224 058f31828c first commit 2 年之前 2328 058f31828c first commit 2 年之前 2336 058f31828c first commit 2 年之前 2337 058f31828c first commit 2 年之前 2579 058f31828c first commit 2 年之前 2600 058f31828c first commit 2 年之前 2600_fsm 058f31828c first commit 2 年之前 2600_vm 058f31828c first commit 2 年之前 2601 058f31828c first commit 2 年之前 2601_fsm 058f31828c first commit 2 年之前 2601_vm 058f31828c first commit 2 年之前 2602 058f31828c first commit 2 年之前 2602_fsm 058f31828c first commit 2 年之前 2602_vm 058f31828c first commit 2 年之前 2603 058f31828c first commit 2 年之前 2603_fsm 058f31828c first commit 2 年之前 2603_vm 058f31828c first commit 2 年之前 2604 058f31828c first commit 2 年之前 2605 058f31828c first commit 2 年之前 2605_fsm 058f31828c first commit 2 年之前 2605_vm 058f31828c first commit 2 年之前 2606 058f31828c first commit 2 年之前 2606_fsm 058f31828c first commit 2 年之前 2606_vm 058f31828c first commit 2 年之前 2607 058f31828c first commit 2 年之前 2607_fsm 058f31828c first commit 2 年之前 2607_vm 058f31828c first commit 2 年之前 2608 058f31828c first commit 2 年之前 2608_fsm 058f31828c first commit 2 年之前 2608_vm 058f31828c first commit 2 年之前 2609 058f31828c first commit 2 年之前 2609_fsm 058f31828c first commit 2 年之前 2609_vm 058f31828c first commit 2 年之前 2610 058f31828c first commit 2 年之前 2610_fsm 058f31828c first commit 2 年之前 2610_vm 058f31828c first commit 2 年之前 2611 058f31828c first commit 2 年之前 2612 058f31828c first commit 2 年之前 2612_fsm 058f31828c first commit 2 年之前 2612_vm 058f31828c first commit 2 年之前 2613 058f31828c first commit 2 年之前 2615 058f31828c first commit 2 年之前 2615_fsm 058f31828c first commit 2 年之前 2615_vm 058f31828c first commit 2 年之前 2616 058f31828c first commit 2 年之前 2616_fsm 058f31828c first commit 2 年之前 2616_vm 058f31828c first commit 2 年之前 2617 058f31828c first commit 2 年之前 2617_fsm 058f31828c first commit 2 年之前 2617_vm 058f31828c first commit 2 年之前 2618 058f31828c first commit 2 年之前 2618_fsm 058f31828c first commit 2 年之前 2618_vm 058f31828c first commit 2 年之前 2619 058f31828c first commit 2 年之前 2619_fsm 058f31828c first commit 2 年之前 2619_vm 058f31828c first commit 2 年之前 2620 058f31828c first commit 2 年之前 2620_fsm 058f31828c first commit 2 年之前 2650 058f31828c first commit 2 年之前 2651 058f31828c first commit 2 年之前 2652 058f31828c first commit 2 年之前 2653 058f31828c first commit 2 年之前 2654 058f31828c first commit 2 年之前 2655 058f31828c first commit 2 年之前 2656 058f31828c first commit 2 年之前 2657 058f31828c first commit 2 年之前 2658 058f31828c first commit 2 年之前 2659 058f31828c first commit 2 年之前 2660 058f31828c first commit 2 年之前 2661 058f31828c first commit 2 年之前 2662 058f31828c first commit 2 年之前 2663 058f31828c first commit 2 年之前 2664 058f31828c first commit 2 年之前 2665 058f31828c first commit 2 年之前 2666 058f31828c first commit 2 年之前 2667 058f31828c first commit 2 年之前 2668 058f31828c first commit 2 年之前 2669 058f31828c first commit 2 年之前 2670 058f31828c first commit 2 年之前 2673 058f31828c first commit 2 年之前 2674 058f31828c first commit 2 年之前 2675 058f31828c first commit 2 年之前 2678 058f31828c first commit 2 年之前 2679 058f31828c first commit 2 年之前 2680 058f31828c first commit 2 年之前 2681 058f31828c first commit 2 年之前 2682 058f31828c first commit 2 年之前 2683 058f31828c first commit 2 年之前 2684 058f31828c first commit 2 年之前 2685 058f31828c first commit 2 年之前 2686 058f31828c first commit 2 年之前 2687 058f31828c first commit 2 年之前 2688 058f31828c first commit 2 年之前 2689 058f31828c first commit 2 年之前 2690 058f31828c first commit 2 年之前 2691 058f31828c first commit 2 年之前 2692 058f31828c first commit 2 年之前 2693 058f31828c first commit 2 年之前 2696 058f31828c first commit 2 年之前 2699 058f31828c first commit 2 年之前 2701 058f31828c first commit 2 年之前 2702 058f31828c first commit 2 年之前 2703 058f31828c first commit 2 年之前 2704 058f31828c first commit 2 年之前 2753 058f31828c first commit 2 年之前 2753_fsm 058f31828c first commit 2 年之前 2753_vm 058f31828c first commit 2 年之前 2754 058f31828c first commit 2 年之前 2755 058f31828c first commit 2 年之前 2756 058f31828c first commit 2 年之前 2757 058f31828c first commit 2 年之前 2830 058f31828c first commit 2 年之前 2831 058f31828c first commit 2 年之前 2832 058f31828c first commit 2 年之前 2833 058f31828c first commit 2 年之前 2834 058f31828c first commit 2 年之前 2835 058f31828c first commit 2 年之前 2836 058f31828c first commit 2 年之前 2837 058f31828c first commit 2 年之前 2838 058f31828c first commit 2 年之前 2838_fsm 058f31828c first commit 2 年之前 2838_vm 058f31828c first commit 2 年之前 2839 058f31828c first commit 2 年之前 2840 058f31828c first commit 2 年之前 2840_fsm 058f31828c first commit 2 年之前 2840_vm 058f31828c first commit 2 年之前 2841 058f31828c first commit 2 年之前 2995 058f31828c first commit 2 年之前 2996 058f31828c first commit 2 年之前 3079 058f31828c first commit 2 年之前 3079_fsm 058f31828c first commit 2 年之前 3079_vm 058f31828c first commit 2 年之前 3080 058f31828c first commit 2 年之前 3081 058f31828c first commit 2 年之前 3085 058f31828c first commit 2 年之前 3118 058f31828c first commit 2 年之前 3119 058f31828c first commit 2 年之前 3164 058f31828c first commit 2 年之前 3256 058f31828c first commit 2 年之前 3257 058f31828c first commit 2 年之前 3258 058f31828c first commit 2 年之前 3350 058f31828c first commit 2 年之前 3351 058f31828c first commit 2 年之前 3379 058f31828c first commit 2 年之前 3380 058f31828c first commit 2 年之前 3381 058f31828c first commit 2 年之前 3394 058f31828c first commit 2 年之前 3394_fsm 058f31828c first commit 2 年之前 3394_vm 058f31828c first commit 2 年之前 3395 058f31828c first commit 2 年之前 3429 058f31828c first commit 2 年之前 3430 058f31828c first commit 2 年之前 3431 058f31828c first commit 2 年之前 3433 058f31828c first commit 2 年之前 3439 058f31828c first commit 2 年之前 3440 058f31828c first commit 2 年之前 3455 058f31828c first commit 2 年之前 3456 058f31828c first commit 2 年之前 3456_fsm 058f31828c first commit 2 年之前 3456_vm 058f31828c first commit 2 年之前 3466 058f31828c first commit 2 年之前 3467 058f31828c first commit 2 年之前 3468 058f31828c first commit 2 年之前 3501 058f31828c first commit 2 年之前 3502 058f31828c first commit 2 年之前 3503 058f31828c first commit 2 年之前 3534 058f31828c first commit 2 年之前 3541 058f31828c first commit 2 年之前 3541_fsm 058f31828c first commit 2 年之前 3541_vm 058f31828c first commit 2 年之前 3542 058f31828c first commit 2 年之前 3574 058f31828c first commit 2 年之前 3575 058f31828c first commit 2 年之前 3576 058f31828c first commit 2 年之前 3596 058f31828c first commit 2 年之前 3597 058f31828c first commit 2 年之前 3598 058f31828c first commit 2 年之前 3599 058f31828c first commit 2 年之前 3600 058f31828c first commit 2 年之前 3600_fsm 058f31828c first commit 2 年之前 3600_vm 058f31828c first commit 2 年之前 3601 058f31828c first commit 2 年之前 3601_fsm 058f31828c first commit 2 年之前 3601_vm 058f31828c first commit 2 年之前 3602 058f31828c first commit 2 年之前 3602_fsm 058f31828c first commit 2 年之前 3602_vm 058f31828c first commit 2 年之前 3603 058f31828c first commit 2 年之前 3603_fsm 058f31828c first commit 2 年之前 3603_vm 058f31828c first commit 2 年之前 3604 058f31828c first commit 2 年之前 3605 058f31828c first commit 2 年之前 3606 058f31828c first commit 2 年之前 3607 058f31828c first commit 2 年之前 3608 058f31828c first commit 2 年之前 3609 058f31828c first commit 2 年之前 3712 058f31828c first commit 2 年之前 3764 058f31828c first commit 2 年之前 3764_fsm 058f31828c first commit 2 年之前 3764_vm 058f31828c first commit 2 年之前 3766 058f31828c first commit 2 年之前 3767 058f31828c first commit 2 年之前 3997 058f31828c first commit 2 年之前 4143 058f31828c first commit 2 年之前 4144 058f31828c first commit 2 年之前 4145 058f31828c first commit 2 年之前 4146 058f31828c first commit 2 年之前 4147 058f31828c first commit 2 年之前 4148 058f31828c first commit 2 年之前 4149 058f31828c first commit 2 年之前 4150 058f31828c first commit 2 年之前 4151 058f31828c first commit 2 年之前 4152 058f31828c first commit 2 年之前 4153 058f31828c first commit 2 年之前 4154 058f31828c first commit 2 年之前 4155 058f31828c first commit 2 年之前 4156 058f31828c first commit 2 年之前 4157 058f31828c first commit 2 年之前 4158 058f31828c first commit 2 年之前 4159 058f31828c first commit 2 年之前 4160 058f31828c first commit 2 年之前 4161 058f31828c first commit 2 年之前 4162 058f31828c first commit 2 年之前 4163 058f31828c first commit 2 年之前 4164 058f31828c first commit 2 年之前 4165 058f31828c first commit 2 年之前 4166 058f31828c first commit 2 年之前 4167 058f31828c first commit 2 年之前 4168 058f31828c first commit 2 年之前 4169 058f31828c first commit 2 年之前 4170 058f31828c first commit 2 年之前 4171 058f31828c first commit 2 年之前 4172 058f31828c first commit 2 年之前 4173 058f31828c first commit 2 年之前 4174 058f31828c first commit 2 年之前 5002 058f31828c first commit 2 年之前 548 058f31828c first commit 2 年之前 549 058f31828c first commit 2 年之前 6102 058f31828c first commit 2 年之前 6104 058f31828c first commit 2 年之前 6106 058f31828c first commit 2 年之前 6110 058f31828c first commit 2 年之前 6111 058f31828c first commit 2 年之前 6112 058f31828c first commit 2 年之前 6113 058f31828c first commit 2 年之前 6117 058f31828c first commit 2 年之前 826 058f31828c first commit 2 年之前 827 058f31828c first commit 2 年之前 828 058f31828c first commit 2 年之前 PG_VERSION 058f31828c first commit 2 年之前 pg_filenode.map 058f31828c first commit 2 年之前 pg_internal.init 058f31828c first commit 2 年之前 tum/whitesports - Gogs: Simplico Git Service

暫無描述

search.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <?php
  2. /**
  3. * Server-side rendering of the `core/search` block.
  4. *
  5. * @package WordPress
  6. */
  7. /**
  8. * Dynamically renders the `core/search` block.
  9. *
  10. * @param array $attributes The block attributes.
  11. *
  12. * @return string The search block markup.
  13. */
  14. function render_block_core_search( $attributes ) {
  15. static $instance_id = 0;
  16. // Older versions of the Search block defaulted the label and buttonText
  17. // attributes to `__( 'Search' )` meaning that many posts contain `<!--
  18. // wp:search /-->`. Support these by defaulting an undefined label and
  19. // buttonText to `__( 'Search' )`.
  20. $attributes = wp_parse_args(
  21. $attributes,
  22. array(
  23. 'label' => __( 'Search' ),
  24. 'buttonText' => __( 'Search' ),
  25. )
  26. );
  27. $input_id = 'wp-block-search__input-' . ++$instance_id;
  28. $classnames = classnames_for_block_core_search( $attributes );
  29. $show_label = ( ! empty( $attributes['showLabel'] ) ) ? true : false;
  30. $use_icon_button = ( ! empty( $attributes['buttonUseIcon'] ) ) ? true : false;
  31. $show_input = ( ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'] ) ? false : true;
  32. $show_button = ( ! empty( $attributes['buttonPosition'] ) && 'no-button' === $attributes['buttonPosition'] ) ? false : true;
  33. $input_markup = '';
  34. $button_markup = '';
  35. $inline_styles = styles_for_block_core_search( $attributes );
  36. $color_classes = get_color_classes_for_block_core_search( $attributes );
  37. $is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
  38. 'button-inside' === $attributes['buttonPosition'];
  39. // Border color classes need to be applied to the elements that have a border color.
  40. $border_color_classes = get_border_color_classes_for_block_core_search( $attributes );
  41. $label_inner_html = empty( $attributes['label'] ) ? __( 'Search' ) : wp_kses_post( $attributes['label'] );
  42. $label_markup = sprintf(
  43. '<label for="%1$s" class="wp-block-search__label screen-reader-text">%2$s</label>',
  44. esc_attr( $input_id ),
  45. $label_inner_html
  46. );
  47. if ( $show_label && ! empty( $attributes['label'] ) ) {
  48. $label_markup = sprintf(
  49. '<label for="%1$s" class="wp-block-search__label">%2$s</label>',
  50. $input_id,
  51. $label_inner_html
  52. );
  53. }
  54. if ( $show_input ) {
  55. $input_classes = ! $is_button_inside ? $border_color_classes : '';
  56. $input_markup = sprintf(
  57. '<input type="search" id="%s" class="wp-block-search__input %s" name="s" value="%s" placeholder="%s" %s required />',
  58. $input_id,
  59. esc_attr( $input_classes ),
  60. esc_attr( get_search_query() ),
  61. esc_attr( $attributes['placeholder'] ),
  62. $inline_styles['input']
  63. );
  64. }
  65. if ( $show_button ) {
  66. $button_internal_markup = '';
  67. $button_classes = $color_classes;
  68. $aria_label = '';
  69. if ( ! $is_button_inside ) {
  70. $button_classes .= ' ' . $border_color_classes;
  71. }
  72. if ( ! $use_icon_button ) {
  73. if ( ! empty( $attributes['buttonText'] ) ) {
  74. $button_internal_markup = wp_kses_post( $attributes['buttonText'] );
  75. }
  76. } else {
  77. $aria_label = sprintf( 'aria-label="%s"', esc_attr( wp_strip_all_tags( $attributes['buttonText'] ) ) );
  78. $button_classes .= ' has-icon';
  79. $button_internal_markup =
  80. '<svg id="search-icon" class="search-icon" viewBox="0 0 24 24" width="24" height="24">
  81. <path d="M13.5 6C10.5 6 8 8.5 8 11.5c0 1.1.3 2.1.9 3l-3.4 3 1 1.1 3.4-2.9c1 .9 2.2 1.4 3.6 1.4 3 0 5.5-2.5 5.5-5.5C19 8.5 16.5 6 13.5 6zm0 9.5c-2.2 0-4-1.8-4-4s1.8-4 4-4 4 1.8 4 4-1.8 4-4 4z"></path>
  82. </svg>';
  83. }
  84. $button_markup = sprintf(
  85. '<button type="submit" class="wp-block-search__button %s" %s %s>%s</button>',
  86. esc_attr( $button_classes ),
  87. $inline_styles['button'],
  88. $aria_label,
  89. $button_internal_markup
  90. );
  91. }
  92. $field_markup_classes = $is_button_inside ? $border_color_classes : '';
  93. $field_markup = sprintf(
  94. '<div class="wp-block-search__inside-wrapper %s" %s>%s</div>',
  95. esc_attr( $field_markup_classes ),
  96. $inline_styles['wrapper'],
  97. $input_markup . $button_markup
  98. );
  99. $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) );
  100. return sprintf(
  101. '<form role="search" method="get" action="%s" %s>%s</form>',
  102. esc_url( home_url( '/' ) ),
  103. $wrapper_attributes,
  104. $label_markup . $field_markup
  105. );
  106. }
  107. /**
  108. * Registers the `core/search` block on the server.
  109. */
  110. function register_block_core_search() {
  111. register_block_type_from_metadata(
  112. __DIR__ . '/search',
  113. array(
  114. 'render_callback' => 'render_block_core_search',
  115. )
  116. );
  117. }
  118. add_action( 'init', 'register_block_core_search' );
  119. /**
  120. * Builds the correct top level classnames for the 'core/search' block.
  121. *
  122. * @param array $attributes The block attributes.
  123. *
  124. * @return string The classnames used in the block.
  125. */
  126. function classnames_for_block_core_search( $attributes ) {
  127. $classnames = array();
  128. if ( ! empty( $attributes['buttonPosition'] ) ) {
  129. if ( 'button-inside' === $attributes['buttonPosition'] ) {
  130. $classnames[] = 'wp-block-search__button-inside';
  131. }
  132. if ( 'button-outside' === $attributes['buttonPosition'] ) {
  133. $classnames[] = 'wp-block-search__button-outside';
  134. }
  135. if ( 'no-button' === $attributes['buttonPosition'] ) {
  136. $classnames[] = 'wp-block-search__no-button';
  137. }
  138. if ( 'button-only' === $attributes['buttonPosition'] ) {
  139. $classnames[] = 'wp-block-search__button-only';
  140. }
  141. }
  142. if ( isset( $attributes['buttonUseIcon'] ) ) {
  143. if ( ! empty( $attributes['buttonPosition'] ) && 'no-button' !== $attributes['buttonPosition'] ) {
  144. if ( $attributes['buttonUseIcon'] ) {
  145. $classnames[] = 'wp-block-search__icon-button';
  146. } else {
  147. $classnames[] = 'wp-block-search__text-button';
  148. }
  149. }
  150. }
  151. return implode( ' ', $classnames );
  152. }
  153. /**
  154. * Builds an array of inline styles for the search block.
  155. *
  156. * The result will contain one entry for shared styles such as those for the
  157. * inner input or button and a second for the inner wrapper should the block
  158. * be positioning the button "inside".
  159. *
  160. * @param array $attributes The block attributes.
  161. *
  162. * @return array Style HTML attribute.
  163. */
  164. function styles_for_block_core_search( $attributes ) {
  165. $wrapper_styles = array();
  166. $button_styles = array();
  167. $input_styles = array();
  168. $is_button_inside = ! empty( $attributes['buttonPosition'] ) &&
  169. 'button-inside' === $attributes['buttonPosition'];
  170. // Add width styles.
  171. $has_width = ! empty( $attributes['width'] ) && ! empty( $attributes['widthUnit'] );
  172. $button_only = ! empty( $attributes['buttonPosition'] ) && 'button-only' === $attributes['buttonPosition'];
  173. if ( $has_width && ! $button_only ) {
  174. $wrapper_styles[] = sprintf(
  175. 'width: %d%s;',
  176. esc_attr( $attributes['width'] ),
  177. esc_attr( $attributes['widthUnit'] )
  178. );
  179. }
  180. // Add border width styles.
  181. $has_border_width = ! empty( $attributes['style']['border']['width'] );
  182. if ( $has_border_width ) {
  183. $border_width = $attributes['style']['border']['width'];
  184. if ( $is_button_inside ) {
  185. $wrapper_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
  186. } else {
  187. $button_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
  188. $input_styles[] = sprintf( 'border-width: %s;', esc_attr( $border_width ) );
  189. }
  190. }
  191. // Add border radius styles.
  192. $has_border_radius = ! empty( $attributes['style']['border']['radius'] );
  193. if ( $has_border_radius ) {
  194. $default_padding = '4px';
  195. $border_radius = $attributes['style']['border']['radius'];
  196. if ( is_array( $border_radius ) ) {
  197. // Apply styles for individual corner border radii.
  198. foreach ( $border_radius as $key => $value ) {
  199. if ( null !== $value ) {
  200. // Convert camelCase key to kebab-case.
  201. $name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $key ) );
  202. // Add shared styles for individual border radii for input & button.
  203. $border_style = sprintf(
  204. 'border-%s-radius: %s;',
  205. esc_attr( $name ),
  206. esc_attr( $value )
  207. );
  208. $input_styles[] = $border_style;
  209. $button_styles[] = $border_style;
  210. // Add adjusted border radius styles for the wrapper element
  211. // if button is positioned inside.
  212. if ( $is_button_inside && intval( $value ) !== 0 ) {
  213. $wrapper_styles[] = sprintf(
  214. 'border-%s-radius: calc(%s + %s);',
  215. esc_attr( $name ),
  216. esc_attr( $value ),
  217. $default_padding
  218. );
  219. }
  220. }
  221. }
  222. } else {
  223. // Numeric check is for backwards compatibility purposes.
  224. $border_radius = is_numeric( $border_radius ) ? $border_radius . 'px' : $border_radius;
  225. $border_style = sprintf( 'border-radius: %s;', esc_attr( $border_radius ) );
  226. $input_styles[] = $border_style;
  227. $button_styles[] = $border_style;
  228. if ( $is_button_inside && intval( $border_radius ) !== 0 ) {
  229. // Adjust wrapper border radii to maintain visual consistency
  230. // with inner elements when button is positioned inside.
  231. $wrapper_styles[] = sprintf(
  232. 'border-radius: calc(%s + %s);',
  233. esc_attr( $border_radius ),
  234. $default_padding
  235. );
  236. }
  237. }
  238. }
  239. // Add border color styles.
  240. $has_border_color = ! empty( $attributes['style']['border']['color'] );
  241. if ( $has_border_color ) {
  242. $border_color = $attributes['style']['border']['color'];
  243. // Apply wrapper border color if button placed inside.
  244. if ( $is_button_inside ) {
  245. $wrapper_styles[] = sprintf( 'border-color: %s;', esc_attr( $border_color ) );
  246. } else {
  247. $button_styles[] = sprintf( 'border-color: %s;', esc_attr( $border_color ) );
  248. $input_styles[] = sprintf( 'border-color: %s;', esc_attr( $border_color ) );
  249. }
  250. }
  251. // Add color styles.
  252. $has_text_color = ! empty( $attributes['style']['color']['text'] );
  253. if ( $has_text_color ) {
  254. $button_styles[] = sprintf( 'color: %s;', esc_attr( $attributes['style']['color']['text'] ) );
  255. }
  256. $has_background_color = ! empty( $attributes['style']['color']['background'] );
  257. if ( $has_background_color ) {
  258. $button_styles[] = sprintf( 'background-color: %s;', esc_attr( $attributes['style']['color']['background'] ) );
  259. }
  260. $has_custom_gradient = ! empty( $attributes['style']['color']['gradient'] );
  261. if ( $has_custom_gradient ) {
  262. $button_styles[] = sprintf( 'background: %s;', $attributes['style']['color']['gradient'] );
  263. }
  264. return array(
  265. 'input' => ! empty( $input_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $input_styles ) ) ) : '',
  266. 'button' => ! empty( $button_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $button_styles ) ) ) : '',
  267. 'wrapper' => ! empty( $wrapper_styles ) ? sprintf( ' style="%s"', safecss_filter_attr( implode( ' ', $wrapper_styles ) ) ) : '',
  268. );
  269. }
  270. /**
  271. * Returns border color classnames depending on whether there are named or custom border colors.
  272. *
  273. * @param array $attributes The block attributes.
  274. *
  275. * @return string The border color classnames to be applied to the block elements.
  276. */
  277. function get_border_color_classes_for_block_core_search( $attributes ) {
  278. $has_custom_border_color = ! empty( $attributes['style']['border']['color'] );
  279. $border_color_classes = ! empty( $attributes['borderColor'] ) ? sprintf( 'has-border-color has-%s-border-color', $attributes['borderColor'] ) : '';
  280. // If there's a border color style and no `borderColor` text string, we still want to add the generic `has-border-color` class name to the element.
  281. if ( $has_custom_border_color && empty( $attributes['borderColor'] ) ) {
  282. $border_color_classes = 'has-border-color';
  283. }
  284. return $border_color_classes;
  285. }
  286. /**
  287. * Returns color classnames depending on whether there are named or custom text and background colors.
  288. *
  289. * @param array $attributes The block attributes.
  290. *
  291. * @return string The color classnames to be applied to the block elements.
  292. */
  293. function get_color_classes_for_block_core_search( $attributes ) {
  294. $classnames = array();
  295. // Text color.
  296. $has_named_text_color = ! empty( $attributes['textColor'] );
  297. $has_custom_text_color = ! empty( $attributes['style']['color']['text'] );
  298. if ( $has_named_text_color ) {
  299. $classnames[] = sprintf( 'has-text-color has-%s-color', $attributes['textColor'] );
  300. } elseif ( $has_custom_text_color ) {
  301. // If a custom 'textColor' was selected instead of a preset, still add the generic `has-text-color` class.
  302. $classnames[] = 'has-text-color';
  303. }
  304. // Background color.
  305. $has_named_background_color = ! empty( $attributes['backgroundColor'] );
  306. $has_custom_background_color = ! empty( $attributes['style']['color']['background'] );
  307. $has_named_gradient = ! empty( $attributes['gradient'] );
  308. $has_custom_gradient = ! empty( $attributes['style']['color']['gradient'] );
  309. if (
  310. $has_named_background_color ||
  311. $has_custom_background_color ||
  312. $has_named_gradient ||
  313. $has_custom_gradient
  314. ) {
  315. $classnames[] = 'has-background';
  316. }
  317. if ( $has_named_background_color ) {
  318. $classnames[] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] );
  319. }
  320. if ( $has_named_gradient ) {
  321. $classnames[] = sprintf( 'has-%s-gradient-background', $attributes['gradient'] );
  322. }
  323. return implode( ' ', $classnames );
  324. }