Ticket #8187: 8187.patch
| File 8187.patch, 6.9 KB (added by , 6 years ago) |
|---|
-
src/bp-core/bp-core-filters.php
diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php index adc38a5ab..b13c7b350 100644
function bp_core_render_email_template( $template ) { 1168 1168 return ''; 1169 1169 } 1170 1170 add_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 */ 1180 function 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 } 1185 add_filter( 'subdirectory_reserved_names', 'bp_core_components_subdirectory_reserved_names' ); -
src/bp-core/bp-core-functions.php
diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php index cf67c182d..379aa0a55 100644
function bp_core_add_root_component( $slug ) { 879 879 } 880 880 } 881 881 882 /**883 * Create WordPress pages to be used as BP component directories.884 *885 * @since 1.5.0886 */887 function bp_core_create_root_component_page() {888 889 // Get BuddyPress.890 $bp = buddypress();891 892 $new_page_ids = array();893 894 foreach ( (array) $bp->add_root as $slug ) {895 $new_page_ids[ $slug ] = wp_insert_post( array(896 'comment_status' => 'closed',897 'ping_status' => 'closed',898 'post_title' => ucwords( $slug ),899 'post_status' => 'publish',900 'post_type' => 'page'901 ) );902 }903 904 $page_ids = array_merge( $new_page_ids, bp_core_get_directory_page_ids( 'all' ) );905 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.0914 *915 * @todo Deprecate?916 */917 function bp_core_add_illegal_names() {918 update_site_option( 'illegal_names', get_site_option( 'illegal_names' ), array() );919 }920 921 882 /** 922 883 * Get the 'search' query argument for a given component. 923 884 * -
src/bp-core/deprecated/6.0.php
diff --git src/bp-core/deprecated/6.0.php src/bp-core/deprecated/6.0.php index e69de29bb..caa722464 100644
1 <?php 2 /** 3 * Deprecated functions. 4 * 5 * @deprecated 6.0.0 6 */ 7 8 // Exit if accessed directly. 9 defined( 'ABSPATH' ) || exit; 10 11 /** 12 * Create WordPress pages to be used as BP component directories. 13 * 14 * @since 1.5.0 15 * @deprecated 6.0.0 16 */ 17 function bp_core_create_root_component_page() { 18 _deprecated_function( __FUNCTION__, '6.0' ); 19 20 // Get BuddyPress. 21 $bp = buddypress(); 22 23 $new_page_ids = array(); 24 25 foreach ( (array) $bp->add_root as $slug ) { 26 $new_page_ids[ $slug ] = wp_insert_post( array( 27 'comment_status' => 'closed', 28 'ping_status' => 'closed', 29 'post_title' => ucwords( $slug ), 30 'post_status' => 'publish', 31 'post_type' => 'page' 32 ) ); 33 } 34 35 $page_ids = array_merge( $new_page_ids, bp_core_get_directory_page_ids( 'all' ) ); 36 bp_core_update_directory_page_ids( $page_ids ); 37 } 38 39 /** 40 * Add illegal blog names to WP so that root components will not conflict with blog names on a subdirectory installation. 41 * 42 * For example, it would stop someone creating a blog with the slug "groups". 43 * 44 * @since 1.0.0 45 * @deprecated 6.0.0 46 */ 47 function bp_core_add_illegal_names() { 48 _deprecated_function( __FUNCTION__, '6.0' ); 49 50 update_site_option( 'illegal_names', get_site_option( 'illegal_names' ), array() ); 51 } -
src/class-buddypress.php
diff --git src/class-buddypress.php src/class-buddypress.php index 756dd5009..90d29afe0 100644
class BuddyPress { 508 508 require( $this->plugin_dir . 'bp-core/deprecated/2.9.php' ); 509 509 require( $this->plugin_dir . 'bp-core/deprecated/3.0.php' ); 510 510 require( $this->plugin_dir . 'bp-core/deprecated/4.0.php' ); 511 require( $this->plugin_dir . 'bp-core/deprecated/6.0.php' ); 511 512 } 512 513 513 514 // Load wp-cli module if PHP 5.4+ -
tests/phpunit/testcases/core/filters.php
diff --git tests/phpunit/testcases/core/filters.php tests/phpunit/testcases/core/filters.php index e69de29bb..54c747660 100644
1 <?php 2 3 /** 4 * @group core 5 */ 6 7 class BP_Tests_Core_Filters extends BP_UnitTestCase { 8 /** 9 * @group bp_core_components_subdirectory_reserved_names 10 * @ticket 8187 11 */ 12 public function test_bp_core_components_subdirectory_reserved_names() { 13 if ( ! is_multisite() || is_subdomain_install() ) { 14 $this->markTestSkipped(); 15 } 16 17 $u = self::factory()->user->create(); 18 19 $site_data = wpmu_validate_blog_signup( 'members', 'Members', $u ); 20 21 $this->assertTrue( is_wp_error( $site_data['errors'] ), 'On MS subdomain installs, a new site should not be able to use a component slug' ); 22 } 23 } -
tests/phpunit/testcases/core/functions.php
diff --git tests/phpunit/testcases/core/functions.php tests/phpunit/testcases/core/functions.php index 3648d74e1..4290cffdf 100644
class BP_Tests_Core_Functions extends BP_UnitTestCase { 839 839 840 840 $bp->pages = $reset_bp_pages; 841 841 } 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 } 842 886 }