Skip to:
Content

BuddyPress.org

Changeset 14143


Ignore:
Timestamp:
12/15/2025 02:52:55 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.

Closes https://github.com/buddypress/buddypress/pull/423/
See #9300 (trunk)

Location:
trunk
Files:
2 edited

Legend:

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

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

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