WordPress.org

Make WordPress Core

Ticket #10552: link-template.2.diff

File link-template.2.diff, 1.1 KB (added by jshreve, 8 years ago)
  • link-template.php

     
    656656}
    657657
    658658/**
     659* Retrieve permalink for search.
     660*
     661* @since  3.0.0
     662* @param string $query Optional. The query string to link to uses current query if empty.
     663* @return string
     664* use home_url
     665*/
     666function get_search_link( $query = '' ) {
     667        global $wp_rewrite;
     668
     669        if ( empty($query) )
     670                $search = get_search_query();
     671        else
     672                $search = stripslashes($query);
     673
     674        $permalink = $wp_rewrite->get_search_permastruct();
     675
     676        if ( empty( $permalink ) ) {
     677                $permalink = home_url('?s=' . urlencode($search) );
     678        } else {
     679                $search = urlencode($search);
     680                $search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, Pre-encode it so its double-encoded.
     681                $permalink = str_replace( '%search%', $search, $permalink );
     682                $permalink = home_url( user_trailingslashit( $permalink, 'search' ) );
     683        }
     684
     685        return apply_filters( 'search_link', $permalink, $search );
     686}
     687
     688/**
    659689 * Retrieve the permalink for the feed of the search results.
    660690 *
    661691 * @since 2.5.0