WordPress.org

Make WordPress Core

Ticket #15081: 15081.3.diff

File 15081.3.diff, 1.8 KB (added by lancewillett, 2 years ago)
  • 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 
    155156        $search_form_template = locate_template('searchform.php'); 
     
    158159                return; 
    159160        } 
    160161 
    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        if ( $echo )