WordPress.org

Make WordPress Core

Ticket #15081: 15081.4.diff

File 15081.4.diff, 2.2 KB (added by SergeyBiryukov, 7 years ago)

Refreshed after [23666]

  • wp-includes/general-template.php

     
    147147 *
    148148 * @since 2.7.0
    149149 * @param boolean $echo Default to echo and not return the form.
     150 * @param string $format Which type to use for the search field. If set to 'html5' it changes to search input type and adds placeholder text.
    150151 * @return string|null String when retrieving, null when displaying or if searchform.php exists.
    151152 */
    152 function get_search_form($echo = true) {
     153function get_search_form( $echo = true, $format = 'xhtml' ) {
    153154        do_action( 'get_search_form' );
    154155
    155         $search_form_template = locate_template('searchform.php');
     156        $search_form_template = locate_template( 'searchform.php' );
    156157        if ( '' != $search_form_template ) {
    157158                ob_start();
    158                 require($search_form_template);
     159                require( $search_form_template );
    159160                $form = ob_get_clean();
    160161        } else {
    161                 $form = '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '" >
    162                 <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
    163                 <input type="text" value="' . get_search_query() . '" name="s" id="s" />
    164                 <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
    165                 </div>
     162                $type        = ( 'html5' === $format ) ? 'search' : 'text';
     163                $placeholder = ( 'html5' === $format ) ? 'placeholder="' . esc_attr_x( 'Search &hellip;', 'placeholder' ) . '" ' : '';
     164
     165                $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
     166                        <div>
     167                                <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
     168                                <input type="' . $type . '" ' . $placeholder . 'value="' . get_search_query() . '" name="s" id="s" />
     169                                <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
     170                        </div>
    166171                </form>';
    167172        }
    168173
    169174        if ( $echo )
    170                 echo apply_filters('get_search_form', $form);
     175                echo apply_filters( 'get_search_form', $form );
    171176        else
    172                 return apply_filters('get_search_form', $form);
     177                return apply_filters( 'get_search_form', $form );
    173178}
    174179
    175180/**