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-core/bp-core-functions.php

    r10108 r10110  
    852852function bp_core_add_illegal_names() {
    853853    update_site_option( 'illegal_names', get_site_option( 'illegal_names' ), array() );
     854}
     855
     856/**
     857 * Get the 'search' query argument for a given component.
     858 *
     859 * @since 2.4.0
     860 *
     861 * @param string $component Component name.
     862 * @return string|bool Query argument on success. False on failure.
     863 */
     864function bp_core_get_component_search_query_arg( $component ) {
     865    $query_arg = false;
     866    if ( isset( buddypress()->{$component}->search_query_arg ) ) {
     867        $query_arg = sanitize_title( buddypress()->{$component}->search_query_arg );
     868    }
     869
     870    /**
     871     * Filters the query arg for a component search string.
     872     *
     873     * @since 2.4.0
     874     *
     875     * @param string $query_arg Query argument.
     876     * @param string $component Component name.
     877     */
     878    return apply_filters( 'bp_core_get_component_search_query_arg', $query_arg, $component );
    854879}
    855880
Note: See TracChangeset for help on using the changeset viewer.