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

    r9977 r10110  
    532532 *     @type string|array          $member_type__not_in Array or comma-separated list of member types to exclude
    533533 *                                                      from results.
    534  *     @type string                $search_terms        Limit results by a search term. Default: null.
     534 *     @type string                $search_terms        Limit results by a search term. Default: value of
     535 *                                                      `$_REQUEST['members_search']` or `$_REQUEST['s']`, if present.
     536 *                                                      Otherwise false.
    535537 *     @type string                $meta_key            Limit results by the presence of a usermeta key.
    536538 *                                                      Default: false.
     
    563565    }
    564566
     567    $search_terms_default = null;
     568    $search_query_arg = bp_core_get_component_search_query_arg( 'members' );
     569    if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
     570        $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
     571    }
     572
    565573    // type: active ( default ) | random | newest | popular | online | alphabetical
    566574    $r = bp_parse_args( $args, array(
     
    579587        'member_type__in'     => '',
    580588        'member_type__not_in' => '',
    581         'search_terms'        => null,     // Pass search_terms to filter users by their profile data
     589        'search_terms'        => $search_terms_default,
    582590
    583591        'meta_key'            => false,    // Only return users with this usermeta
     
    13351343function bp_directory_members_search_form() {
    13361344
    1337     $default_search_value = bp_get_search_default_text( 'members' );
    1338     $search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value;
     1345    $query_arg = bp_core_get_component_search_query_arg( 'members' );
     1346
     1347    if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
     1348        $search_value = stripslashes( $_REQUEST[ $query_arg ] );
     1349    } else {
     1350        $search_value = bp_get_search_default_text( 'members' );
     1351    }
    13391352
    13401353    $search_form_html = '<form action="" method="get" id="search-members-form">
    1341         <label><input type="text" name="s" id="members_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
     1354        <label><input type="text" name="' . esc_attr( $query_arg ) . '" id="members_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
    13421355        <input type="submit" id="members_search_submit" name="members_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
    13431356    </form>';
Note: See TracChangeset for help on using the changeset viewer.