WordPress.org

Make WordPress Core

Changeset 13483


Ignore:
Timestamp:
02/28/2010 04:15:02 AM (9 years ago)
Author:
dd32
Message:

Add get_search_link() with Permastruct (/search/) support. Props jshreve. Update get_search_link(), get_search_feed_link() & get_search_comments_feed_link() to use it, as well as supporting Permastructs for those feeds. Fixes #10552

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/link-template.php

    r13475 r13483  
    657657
    658658/**
     659* Retrieve permalink for search.
     660*
     661* @since  3.0.0
     662* @param string $query Optional. The query string to use. If empty the current query is used.
     663* @return string
     664*/
     665function get_search_link( $query = '' ) {
     666    global $wp_rewrite;
     667
     668    if ( empty($query) )
     669        $search = get_search_query();
     670    else
     671        $search = stripslashes($query);
     672
     673    $permastruct = $wp_rewrite->get_search_permastruct();
     674
     675    if ( empty( $permastruct ) ) {
     676        $link = home_url('?s=' . urlencode($search) );
     677    } else {
     678        $search = urlencode($search);
     679        $search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it unencoded.
     680        $link = str_replace( '%search%', $search, $permastruct );
     681        $link = home_url( user_trailingslashit( $link, 'search' ) );
     682    }
     683
     684    return apply_filters( 'search_link', $link, $search );
     685}
     686
     687/**
    659688 * Retrieve the permalink for the feed of the search results.
    660689 *
     
    666695 */
    667696function get_search_feed_link($search_query = '', $feed = '') {
    668     if ( empty($search_query) )
    669         $search = esc_attr( urlencode(get_search_query()) );
    670     else
    671         $search = esc_attr( urlencode(stripslashes($search_query)) );
     697    global $wp_rewrite;
     698    $link = get_search_link($search_query);
    672699
    673700    if ( empty($feed) )
    674701        $feed = get_default_feed();
    675702
    676     $link = home_url("?s=$search&feed=$feed");
    677 
    678     $link = apply_filters('search_feed_link', $link);
     703    $permastruct = $wp_rewrite->get_search_permastruct();
     704
     705    if ( empty($permastruct) ) {
     706        $link = add_query_arg('feed', $feed, $link);
     707    } else {
     708        $link = trailingslashit($link);
     709        $link .= "feed/$feed/";
     710    }
     711
     712    $link = apply_filters('search_feed_link', $link, $feed, 'posts');
    679713
    680714    return $link;
     
    691725 */
    692726function get_search_comments_feed_link($search_query = '', $feed = '') {
    693     if ( empty($search_query) )
    694         $search = esc_attr( urlencode(get_search_query()) );
    695     else
    696         $search = esc_attr( urlencode(stripslashes($search_query)) );
     727    global $wp_rewrite;
    697728
    698729    if ( empty($feed) )
    699730        $feed = get_default_feed();
    700731
    701     $link = home_url("?s=$search&feed=comments-$feed");
    702 
    703     $link = apply_filters('search_feed_link', $link);
     732    $link = get_search_feed_link($search_query, $feed);
     733
     734    $permastruct = $wp_rewrite->get_search_permastruct();
     735
     736    if ( empty($permastruct) )
     737        $link = add_query_arg('feed', 'comments-' . $feed, $link);
     738    else
     739        $link = add_query_arg('withcomments', 1, $link);
     740
     741    $link = apply_filters('search_feed_link', $link, $feed, 'comments');
    704742
    705743    return $link;
Note: See TracChangeset for help on using the changeset viewer.