Opened 4 months ago
Last modified 7 days ago
#9330 new defect (bug)
Fix `bp_is_site_home()` to ignore query strings
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Under Consideration | Priority: | normal |
| Severity: | normal | Version: | 12.1.1 |
| Component: | Core | Keywords: | has-patch changes-requested reporter-feedback |
| Cc: |
Description
The Bug
bp_is_site_home() (introduced in 12.1.0) performs an exact string comparison of the full requested URL against home_url( '/' ):
function bp_is_site_home() {
$requested_url = bp_get_requested_url();
$home_url = home_url( '/' );
// ...
return $home_url === $requested_url;
}
bp_get_requested_url() includes the query string from $_SERVER['REQUEST_URI'], but home_url( '/' ) does not. This means any query parameter on the homepage URL causes bp_is_site_home() to return false:
https://example.com/→true✓https://example.com/?custom_param=value→false✗
Impact
This breaks component directory detection when a BuddyPress directory page is set as the WordPress static front page (page_on_front). Every component's parse_query() method relies on this check:
// From BP_Activity_Component::parse_query()
if ( bp_is_site_home() && bp_is_directory_homepage( $this->id ) ) {
$query->set( $this->rewrite_ids['directory'], 1 );
}
When bp_is_site_home() returns false, the directory flag is never set, so:
$bp->current_componentis never assigned$wp_query->queried_objectis never set to the directory pageis_buddypress()returnsfalse— BuddyPress template loading does not kick in- The theme falls through to WordPress's default page rendering, which displays empty content or a "page not found" for the BuddyPress directory page
This affects any plugin that adds query parameters to a BuddyPress directory homepage — not just custom parameters. For example, a plugin adding topic filtering (?bp-topic=slug), search refinement, or pagination parameters to the activity directory would trigger this when the activity page is the front page.
When the directory is NOT the front page (e.g., /activity/?param=value), this issue does not occur because WordPress's rewrite rules match the path and set the directory query var directly, bypassing the bp_is_site_home() check entirely.
Steps to Reproduce
- Set up BuddyPress with the Activity component enabled
- Go to Settings → Reading → set "Your homepage displays" to "A static page"
- Set "Homepage" to the Activity directory page
- Visit
https://example.com/— activity directory loads correctly ✓ - Visit
https://example.com/?anything=value— page not found / empty page ✗
Proposed Fix
Compare URL paths only, ignoring query strings. This matches how WordPress's own redirect_canonical() handles URL comparison (it strips query args before comparing):
function bp_is_site_home() {
$requested_url = bp_get_requested_url();
$home_url = home_url( '/' );
if ( is_customize_preview() && ! bp_is_email_customizer() ) {
$requested_url = wp_parse_url( $requested_url, PHP_URL_PATH );
$home_url = wp_parse_url( $home_url, PHP_URL_PATH );
}
// Compare paths only — query strings should not affect homepage detection.
$requested_path = wp_parse_url( $requested_url, PHP_URL_PATH );
$home_path = wp_parse_url( $home_url, PHP_URL_PATH );
return trailingslashit( (string) $requested_path ) === trailingslashit( (string) $home_path );
}
Scope
- 2 lines of functional code changed in one function in
bp-core-template.php - Zero behavioral change for URLs without query strings (the
trailingslashitpath comparison produces the same result as the current exact comparison for bare homepage URLs) - Fixes directory homepage detection for all components (Activity, Members, Groups, etc.) when query parameters are present
- The
is_customize_preview()branch already useswp_parse_url( ..., PHP_URL_PATH )— the fix extends this approach to the general case
Workaround
Plugins can work around this by filtering bp_get_requested_url to strip their custom query parameters:
add_filter( 'bp_get_requested_url', function ( $url ) {
if ( isset( $_GET['custom-param'] ) ) {
$url = remove_query_arg( 'custom-param', $url );
}
return $url;
}, 5 );
This is fragile because every plugin must independently strip its own parameters. The core fix is preferable.
I'm happy to submit a patch for this change.
Attachments (1)
Change History (4)
#3
@
7 days ago
- Keywords changes-requested reporter-feedback added
- Milestone changed from Awaiting Review to Under Consideration
- Version set to 12.1.1
@indigetal,
The submitted patch (9330.patch) needs additional work. It appears that you didn't notice that it breaks "BP Email" customization, which is just one layer of "peeling the onion".
Set component to Core. The fix is in
bp-core-template.phpand applies to any directory used as the static front page.Many BuddyPress communities set a directory (Activity, Members, Groups, etc.) as the WordPress homepage. That is a supported, common setup. However, once the homepage URL carries *any* query string, such as a filter, pagination, campaign tracking, or a shared link like
/?ref=newsletter,bp_is_site_home()can return false and BuddyPress never treats the request as the directory front page. Members see a broken or empty homepage instead of the community feed they expect.The ticket describes the technical cause, but the actual community impact is much broader: query args are a normal part of the web, not an edge case. Extensions that add directory filtering, search refinements, or deep links should not each ship a
bp_get_requested_urlworkaround to strip their own parameters. That does not scale when several plugins are active, and it is easy to miss a parameter and still break routing.9330.patchcompares URL paths only (the same path-only approach already used in the Customizer preview branch). No change for plainhttps://example.com/requests; fixes homepage-as-directory for all components when query args are present.That fix would help the ecosystem in practical ways:
Core behavior stays the same for sites that do not use a directory as the homepage. The patch is attached whenever review fits your schedule.
Thanks for considering it.