Skip to:
Content

BuddyPress.org

Changeset 14144


Ignore:
Timestamp:
12/15/2025 02:57:47 AM (5 months ago)
Author:
espellcaste
Message:

The is_home() returns false on BuddyPress pages.

This change addresses an issue where is_home returned true on BuddyPress pages (except if a BuddyPress component was set as the front page).

Props r-a-y.

Fixes #9300 (14.0)

Location:
branches/14.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/14.0/src/bp-core/classes/class-bp-component.php

    r14060 r14144  
    12641264    public function parse_query( $query ) {
    12651265        if ( is_buddypress() && 'rewrites' === bp_core_get_query_parser() ) {
     1266            // 'is_home' should always be false when on a BP page.
     1267            if ( $query->is_main_query() ) {
     1268                $query->is_home = false;
     1269            }
     1270
    12661271            add_filter( 'posts_pre_query', array( $this, 'pre_query' ), 10, 2 );
    12671272        }
  • branches/14.0/tests/phpunit/testcases/routing/core.php

    r13507 r14144  
    2222    }
    2323
    24     function test_wordpress_page() {
     24    public function test_wordpress_page() {
    2525        $this->set_permalink_structure( '/%postname%/' );
    2626        $this->go_to( '/' );
    2727        $this->assertEmpty( bp_current_component() );
    2828    }
     29
     30    /**
     31     * @ticket BP9300
     32     */
     33    public function test_buddypress_directory_is_home_false() {
     34        $this->set_permalink_structure( '/%postname%/' );
     35
     36        $is_home_value = null;
     37
     38        // Capture the is_home value during pre_get_posts for the main query.
     39        $callback = function ( $query ) use ( &$is_home_value ) {
     40            if ( $query->is_main_query() ) {
     41                $is_home_value = $query->is_home;
     42            }
     43        };
     44
     45        add_action( 'pre_get_posts', $callback );
     46
     47        $this->go_to( bp_get_members_directory_permalink() );
     48
     49        remove_action( 'pre_get_posts', $callback );
     50
     51        $this->assertFalse( $is_home_value, 'is_home should be false for a BuddyPress directory page on the main query.' );
     52    }
    2953}
Note: See TracChangeset for help on using the changeset viewer.