Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/14/2015 03:39:38 PM (10 years ago)
Author:
boonebgorges
Message:

When a copmonent directory is set to the front page, don't interfere with blog searches.

WP's default search query arg is 's', so that URLs like example.com?s=foo lead
to a search of blog posts on the term 'foo'. When a BuddyPress component page
like Members is set to the front page, it interferes with this behavior in two
ways: (1) BuddyPress interprets example.com?s=foo as a Members directory
request, and (2) the 's' query arg is interpreted as a Members search term.

We fix this conflict as follows:

  • During the URL parsing process, don't interpret requests of the form example.com?s=foo as being BP component requests, even if a BP component is set to the front page.
  • In order to make BuddyPress component searches continue to work, we change the default search query arguments for each component to be unique. For example, member directory searches look like example.com?members_search=foo. Components register their own 'search_query_arg', and these args can be filtered with the new 'bp_core_get_component_search_query_arg' filter.

Fixes #5087.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-template.php

    r10100 r10110  
    385385 *     @type array    $include_blog_ids Array of blog IDs to limit results to.
    386386 *     @type string   $sort             'ASC' or 'DESC'. Default: 'DESC'.
    387  *     @type string   $search_terms     Limit results by a search term. Default: the
    388  *                                      value of $_REQUEST['s'], if present.
     387 *     @type string   $search_terms     Limit results by a search term. Default: the value of `$_REQUEST['s']` or
     388 *                                      `$_REQUEST['sites_search']`, if present.
    389389 *     @type int      $user_id          The ID of the user whose blogs should be retrieved.
    390390 *                                      When viewing a user profile page, 'user_id' defaults to the
     
    396396    global $blogs_template;
    397397
    398     // Check for and use search terms
    399     $search_terms = ! empty( $_REQUEST['s'] )
    400         ? $_REQUEST['s']
    401         : false;
     398    // Check for and use search terms.
     399    $search_terms_default = false;
     400    $search_query_arg = bp_core_get_component_search_query_arg( 'blogs' );
     401    if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
     402        $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
     403    } elseif ( ! empty( $_REQUEST['s'] ) ) {
     404        $search_terms_default = stripslashes( $_REQUEST['s'] );
     405    }
    402406
    403407    // Parse arguments
     
    410414        'user_id'           => bp_displayed_user_id(), // Pass a user_id to limit to only blogs this user is a member of
    411415        'include_blog_ids'  => false,
    412         'search_terms'      => $search_terms,          // Pass search terms to filter on the blog title or description.
     416        'search_terms'      => $search_terms_default,
    413417        'update_meta_cache' => true
    414418    ), 'has_blogs' );
     
    14501454 */
    14511455function bp_directory_blogs_search_form() {
    1452     $default_search_value = bp_get_search_default_text();
    1453     $search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value;
     1456
     1457    $query_arg = bp_core_get_component_search_query_arg( 'blogs' );
     1458
     1459    if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
     1460        $search_value = stripslashes( $_REQUEST[ $query_arg ] );
     1461    } else {
     1462        $search_value = bp_get_search_default_text( 'blogs' );
     1463    }
    14541464
    14551465    $search_form_html = '<form action="" method="get" id="search-blogs-form">
    1456         <label><input type="text" name="s" id="blogs_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
     1466        <label><input type="text" name="' . esc_attr( $query_arg ) . '" id="blogs_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
    14571467        <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
    14581468    </form>';
Note: See TracChangeset for help on using the changeset viewer.