Skip to:
Content

BuddyPress.org

Changeset 12569


Ignore:
Timestamp:
03/15/2020 05:30:13 AM (4 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

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-filters.php

    r12545 r12569  
    11691169}
    11701170add_action( 'bp_template_include', 'bp_core_render_email_template', 12 );
     1171
     1172/**
     1173 * Adds BuddyPress components' slugs to the WordPress Multisite subdirectory reserved names.
     1174 *
     1175 * @since 6.0.0
     1176 *
     1177 * @param array $names The WordPress Multisite subdirectory reserved names.
     1178 * @return array       The WordPress & BuddyPress Multisite subdirectory reserved names.
     1179 */
     1180function bp_core_components_subdirectory_reserved_names( $names = array() ) {
     1181    $bp_pages = (array) buddypress()->pages;
     1182
     1183    return array_merge( $names, wp_list_pluck( $bp_pages, 'slug' ) );
     1184}
     1185add_filter( 'subdirectory_reserved_names', 'bp_core_components_subdirectory_reserved_names' );
  • trunk/src/bp-core/bp-core-functions.php

    r12545 r12569  
    904904    $page_ids = array_merge( $new_page_ids, bp_core_get_directory_page_ids( 'all' ) );
    905905    bp_core_update_directory_page_ids( $page_ids );
    906 }
    907 
    908 /**
    909  * Add illegal blog names to WP so that root components will not conflict with blog names on a subdirectory installation.
    910  *
    911  * For example, it would stop someone creating a blog with the slug "groups".
    912  *
    913  * @since 1.0.0
    914  *
    915  * @todo Deprecate?
    916  */
    917 function bp_core_add_illegal_names() {
    918     update_site_option( 'illegal_names', get_site_option( 'illegal_names' ), array() );
    919906}
    920907
  • trunk/src/bp-core/deprecated/6.0.php

    r12568 r12569  
    144144        _deprecated_function( __FUNCTION__, '6.0' );
    145145    }
     146
     147/**
     148 * Add illegal blog names to WP so that root components will not conflict with blog names on a subdirectory installation.
     149 *
     150 * For example, it would stop someone creating a blog with the slug "groups".
     151 *
     152 * @since 1.0.0
     153 * @deprecated 6.0.0
     154 */
     155function bp_core_add_illegal_names() {
     156    _deprecated_function( __FUNCTION__, '6.0' );
     157
     158    update_site_option( 'illegal_names', get_site_option( 'illegal_names' ), array() );
     159}
  • 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.