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-component.php

    r10108 r10110  
    127127    public $global_tables = array();
    128128
     129    /**
     130     * Query argument for component search URLs.
     131     *
     132     * @since 2.4.0
     133     * @var string
     134     */
     135    public $search_query_arg = 's';
     136
    129137    /** Methods ***************************************************************/
    130138
     
    135143     * @since 1.9.0 Added $params as a parameter.
    136144     * @since 2.3.0 Added $params['features'] as a configurable value.
     145     * @since 2.4.0 Added $params['search_query_arg'] as a configurable value.
    137146     *
    138147     * @param string $id   Unique ID. Letters, numbers, and underscores only.
     
    142151     * @param array  $params {
    143152     *     Additional parameters used by the component.
    144      *     @type int   $adminbar_myaccount_order Set the position for our menu under the WP Toolbar's "My Account menu".
    145      *     @type array $features                 An array of feature names. This is used to load additional files from your
    146      *                                           component directory and for feature active checks. eg. array( 'awesome' )
    147      *                                           would look for a file called "bp-{$this->id}-awesome.php" and you could use
    148      *                                           bp_is_active( $this->id, 'awesome' ) to determine if the feature is active.
     153     *     @type int    $adminbar_myaccount_order Set the position for our menu under the WP Toolbar's "My Account menu".
     154     *     @type array  $features                 An array of feature names. This is used to load additional files from your
     155     *                                            component directory and for feature active checks. eg. array( 'awesome' )
     156     *                                            would look for a file called "bp-{$this->id}-awesome.php" and you could use
     157     *                                            bp_is_active( $this->id, 'awesome' ) to determine if the feature is active.
     158     *     @type string $search_query_arg         String to be used as the query argument in component search URLs.
    149159     * }
    150160     */
     
    170180            if ( ! empty( $params['features'] ) ) {
    171181                $this->features = array_map( 'sanitize_title', (array) $params['features'] );
     182            }
     183
     184            if ( ! empty( $params['search_query_arg'] ) ) {
     185                $this->search_query_arg = sanitize_title( $params['search_query_arg'] );
    172186            }
    173187
Note: See TracChangeset for help on using the changeset viewer.