diff --git wp-includes/general-template.php wp-includes/general-template.php
index 11d4b77ff4..52e1b662f7 100644
|
|
function get_template_part( $slug, $name = null ) { |
175 | 175 | * search. To give a few examples of what it can be used for. |
176 | 176 | * |
177 | 177 | * @since 2.7.0 |
| 178 | * @since 5.2.0 the $args array paramiter was added in place of an $echo boolean flag. |
178 | 179 | * |
179 | | * @param bool $echo Default to echo and not return the form. |
180 | | * @return string|void String when $echo is false. |
| 180 | * @param array $args Default args are to echo and include no custom label. |
181 | 181 | */ |
182 | | function get_search_form( $echo = true ) { |
| 182 | function get_search_form( $args = array() ) { |
183 | 183 | /** |
184 | 184 | * Fires before the search form is retrieved, at the start of get_search_form(). |
185 | 185 | * |
… |
… |
function get_search_form( $echo = true ) { |
192 | 192 | |
193 | 193 | $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml'; |
194 | 194 | |
| 195 | /* |
| 196 | * Back compat: to ensure previous uses of get_search_form continue to |
| 197 | * function as expected we handle a value for $echo as though nothing has |
| 198 | * changed. Then we deal with the $args array and cast it's defaults. |
| 199 | */ |
| 200 | $echo = true; |
| 201 | if ( false === $args ) { |
| 202 | $echo = false; |
| 203 | } |
| 204 | if ( ! is_array( $args ) ) { |
| 205 | // we can set an empty array and allow default args to take over. |
| 206 | $args = array(); |
| 207 | } |
| 208 | |
| 209 | // defaults are to echo and to output no custom label on the landmark. |
| 210 | $defaults = array( |
| 211 | 'echo' => $echo, |
| 212 | 'label' => false, |
| 213 | ); |
| 214 | |
| 215 | // merge any args with the defaults. |
| 216 | $args = wp_parse_args( $args, $defaults ); |
| 217 | |
| 218 | /** |
| 219 | * Filters the array of args used when generating the search form. |
| 220 | * |
| 221 | * @since 5.2.0 |
| 222 | * |
| 223 | * @param array $args The array of args used when building the search form. |
| 224 | */ |
| 225 | $args = apply_filters( 'search_form_args', $args ); |
| 226 | |
195 | 227 | /** |
196 | 228 | * Filters the HTML format of the search form. |
197 | 229 | * |
… |
… |
function get_search_form( $echo = true ) { |
208 | 240 | require( $search_form_template ); |
209 | 241 | $form = ob_get_clean(); |
210 | 242 | } else { |
| 243 | // form a string containaing a label to use for the search role. |
| 244 | if ( $args['label'] ) { |
| 245 | $label = 'aria-label="' . esc_attr( $args['label'] ) . '" '; |
| 246 | } else { |
| 247 | // if there is no custom label we can set a default here. ATM it is |
| 248 | // empty as there's uncertainty about what the default should be. |
| 249 | $label = ''; |
| 250 | } |
211 | 251 | if ( 'html5' == $format ) { |
212 | | $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '"> |
| 252 | $form = '<form role="search" ' . $label . 'method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '"> |
213 | 253 | <label> |
214 | 254 | <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span> |
215 | 255 | <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" /> |
… |
… |
function get_search_form( $echo = true ) { |
217 | 257 | <input type="submit" class="search-submit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" /> |
218 | 258 | </form>'; |
219 | 259 | } else { |
220 | | $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '"> |
| 260 | $form = '<form role="search" ' . $label . 'method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '"> |
221 | 261 | <div> |
222 | 262 | <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label> |
223 | 263 | <input type="text" value="' . get_search_query() . '" name="s" id="s" /> |
… |
… |
function get_search_form( $echo = true ) { |
240 | 280 | $result = $form; |
241 | 281 | } |
242 | 282 | |
243 | | if ( $echo ) { |
| 283 | if ( array_key_exists( 'echo', $args ) && $args['echo'] ) { |
244 | 284 | echo $result; |
245 | 285 | } else { |
246 | 286 | return $result; |