Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/04/2021 02:53:34 PM (3 years ago)
Author:
imath
Message:

Make sure BP directory page IDs are not wrongly unset on multisite

In case a post of a different site of the multisite network has the same ID than one of the BP directory page IDs, the function can wrongly return an array in which the corresponding directory page ID is missing.

We need to make sure this function always run into the BP Root Blog context.

Props thomaslhotta

Fixes #8592

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/functions/bpCoreGetDirectoryPageIds.php

    r13133 r13159  
    286286
    287287    /**
     288     * @ticket BP8592
     289     */
     290    public function test_bp_core_get_directory_pages_ids_ms_non_root_blog_trashed_same_page_id() {
     291        if ( ! is_multisite() ) {
     292            $this->markTestSkipped();
     293        }
     294
     295        // create a blog
     296        $u  = self::factory()->user->create();
     297        $b1 = self::factory()->blog->create(
     298            array(
     299                'user_id' => $u,
     300            )
     301        );
     302
     303        // Switch to blog and create a post with the same BP Members page ID.
     304        switch_to_blog( $b1 );
     305
     306        $dir_page_ids = bp_core_get_directory_page_ids();
     307
     308        $p = self::factory()->post->create(
     309            array(
     310                'import_id' => $dir_page_ids['members'],
     311            )
     312        );
     313
     314        // Trash the post that matches the BP Members page ID on this sub-site
     315        wp_trash_post( $dir_page_ids['members'] );
     316
     317        // refetch BP directory page IDs
     318        $page_ids = bp_core_get_directory_page_ids();
     319
     320        // restore blog
     321        restore_current_blog();
     322
     323        // Now verify that our BP Members page was not wiped out
     324        $this->assertTrue( $dir_page_ids['members'] === $page_ids['members'] );
     325    }
     326
     327    /**
    288328     * @ticket BP7193
    289329     */
Note: See TracChangeset for help on using the changeset viewer.