Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/15/2020 05:30:13 AM (5 years ago)
Author:
imath
Message:

Add Root component slugs to MS Subdirectory site reserved names

This is avoiding slug conflicts between BuddyPress root components slugs and subdirectory site slugs.

PS: bp_core_add_illegal_names() has been deprecated in 6.0.

Props santiazpi2

Fixes #8187

File:
1 edited

Legend:

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

    r12247 r12569  
    840840        $bp->pages = $reset_bp_pages;
    841841    }
     842
     843    /**
     844     * @group bp_core_add_page_mappings
     845     * @ticket 8187
     846     */
     847    public function test_bp_core_add_page_mappings_in_multisite_subdirectory() {
     848        if ( ! is_multisite() || is_subdomain_install() ) {
     849            $this->markTestSkipped();
     850        }
     851
     852        if ( function_exists( 'wp_initialize_site' ) ) {
     853            $this->setExpectedDeprecated( 'wpmu_new_blog' );
     854        }
     855
     856        $bp = buddypress();
     857        $reset_bp_pages = $bp->pages;
     858        $reset_bp_active_components = $bp->active_components;
     859        $reset_option = bp_get_option( 'bp-pages' );
     860
     861        $b = self::factory()->blog->create( array(
     862            'path'   => '/newcomponent/',
     863        ) );
     864
     865        $bp->active_components['newcomponent'] = 1;
     866        add_filter( 'bp_core_get_directory_page_default_titles', array( $this, 'add_newcomponent_page_title' ) );
     867
     868        bp_core_add_page_mappings( $bp->active_components );
     869
     870        remove_filter( 'bp_core_get_directory_page_default_titles', array( $this, 'add_newcomponent_page_title' ) );
     871        $bp_pages = bp_get_option( 'bp-pages' );
     872
     873        $new_component_page_id = $bp_pages['newcomponent'];
     874        $this->assertNotSame( 'newcomponent', get_post_field( 'post_name', $new_component_page_id ), 'The component slug should not conflict with subsite name.' );
     875
     876        // Reset the page mapping.
     877        bp_update_option( 'bp-pages', $reset_option );
     878        wp_delete_post( $bp_pages['newcomponent'], true );
     879        $bp->pages = $reset_bp_pages;
     880        $bp->active_components = $reset_bp_active_components;
     881    }
     882
     883    public function add_newcomponent_page_title( $page_default_titles = array() ) {
     884        return array_merge( $page_default_titles, array( 'newcomponent' => 'NewComponent' ) );
     885    }
    842886}
Note: See TracChangeset for help on using the changeset viewer.