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-groups/bp-groups-template.php

    r10075 r10110  
    487487 *                                         to groups of which the specified user
    488488 *                                         is a member. Default: null.
    489  *     @type string       $search_terms    If provided, only groups whose names or descriptions
    490  *                                         match the search terms will be returned. Default: false.
     489 *     @type string       $search_terms    If provided, only groups whose names or descriptions match the search terms
     490 *                                         will be returned. Default: value of `$_REQUEST['groups_search']` or
     491 *                                         `$_REQUEST['s']`, if present. Otherwise false.
    491492 *     @type array        $meta_query      An array of meta_query conditions.
    492493 *                                         See {@link WP_Meta_Query::queries} for description.
     
    534535
    535536    // Default search string (too soon to escape here)
    536     if ( ! empty( $_REQUEST['group-filter-box'] ) ) {
     537    $search_query_arg = bp_core_get_component_search_query_arg( 'groups' );
     538    if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
     539        $search_terms = stripslashes( $_REQUEST[ $search_query_arg ] );
     540    } elseif ( ! empty( $_REQUEST['group-filter-box'] ) ) {
    537541        $search_terms = $_REQUEST['group-filter-box'];
    538542    } elseif ( !empty( $_REQUEST['s'] ) ) {
     
    49794983function bp_directory_groups_search_form() {
    49804984
    4981     $default_search_value = bp_get_search_default_text( 'groups' );
    4982     $search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value;
     4985    $query_arg = bp_core_get_component_search_query_arg( 'groups' );
     4986
     4987    if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
     4988        $search_value = stripslashes( $_REQUEST[ $query_arg ] );
     4989    } else {
     4990        $search_value = bp_get_search_default_text( 'groups' );
     4991    }
    49834992
    49844993    $search_form_html = '<form action="" method="get" id="search-groups-form">
    4985         <label><input type="text" name="s" id="groups_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
     4994        <label><input type="text" name="' . esc_attr( $query_arg ) . '" id="groups_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
    49864995        <input type="submit" id="groups_search_submit" name="groups_search_submit" value="'. __( 'Search', 'buddypress' ) .'" />
    49874996    </form>';
Note: See TracChangeset for help on using the changeset viewer.