Changeset 55200
- Timestamp:
- 02/03/2023 12:13:52 AM (23 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r55192 r55200 627 627 add_action( 'init', 'wp_widgets_init', 1 ); 628 628 add_action( 'change_locale', array( 'WP_Widget_Media', 'reset_default_labels' ) ); 629 add_action( 'widgets_init', '_wp_block_theme_register_classic_sidebars', 1 ); 629 630 630 631 // Admin Bar. -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php
r53760 r55200 340 340 } 341 341 342 if ( wp_is_block_theme() ) { 343 $sidebar['status'] = 'inactive'; 344 } 345 342 346 $fields = $this->get_fields_for_response( $request ); 343 347 if ( rest_is_field_included( 'widgets', $fields ) ) { -
trunk/src/wp-includes/theme.php
r55014 r55200 734 734 * @global WP_Customize_Manager $wp_customize 735 735 * @global array $sidebars_widgets 736 * @global array $wp_registered_sidebars 736 737 * 737 738 * @param string $stylesheet Stylesheet name. 738 739 */ 739 740 function switch_theme( $stylesheet ) { 740 global $wp_theme_directories, $wp_customize, $sidebars_widgets ;741 global $wp_theme_directories, $wp_customize, $sidebars_widgets, $wp_registered_sidebars; 741 742 742 743 $requirements = validate_theme_requirements( $stylesheet ); … … 813 814 remove_theme_mod( 'sidebars_widgets' ); 814 815 } 816 } 817 818 // Stores classic sidebars for later use by block themes. 819 if ( $new_theme->is_block_theme() ) { 820 set_theme_mod( 'wp_classic_sidebars', $wp_registered_sidebars ); 815 821 } 816 822 -
trunk/src/wp-includes/widgets.php
r54541 r55200 2106 2106 } 2107 2107 } 2108 2109 /** 2110 * Registers the previous theme's sidebars for the block themes. 2111 * 2112 * @since 6.2.0 2113 * @access private 2114 * 2115 * @global array $wp_registered_sidebars Registered sidebars. 2116 */ 2117 function _wp_block_theme_register_classic_sidebars() { 2118 global $wp_registered_sidebars; 2119 2120 if ( ! wp_is_block_theme() ) { 2121 return; 2122 } 2123 2124 $classic_sidebars = get_theme_mod( 'wp_classic_sidebars' ); 2125 if ( empty( $classic_sidebars ) ) { 2126 return; 2127 } 2128 2129 // Don't use `register_sidebar` since it will enable the `widgets` support for a theme. 2130 foreach ( $classic_sidebars as $sidebar ) { 2131 $wp_registered_sidebars[ $sidebar['id'] ] = $sidebar; 2132 } 2133 } -
trunk/tests/phpunit/tests/rest-api/rest-sidebars-controller.php
r54896 r55200 862 862 863 863 /** 864 * @ticket 57531 865 * @covers WP_Test_REST_Sidebars_Controller::prepare_item_for_response 866 */ 867 public function test_prepare_item_for_response_to_set_inactive_on_theme_switch() { 868 $request = new WP_REST_Request( 'GET', '/wp/v2/sidebars/sidebar-1' ); 869 870 // Set up the test. 871 wp_widgets_init(); 872 $this->setup_widget( 873 'widget_rss', 874 1, 875 array( 876 'title' => 'RSS test', 877 ) 878 ); 879 $this->setup_widget( 880 'widget_text', 881 1, 882 array( 883 'text' => 'Custom text test', 884 ) 885 ); 886 $this->setup_sidebar( 887 'sidebar-1', 888 array( 889 'name' => 'Sidebar 1', 890 ), 891 array( 'text-1', 'rss-1' ) 892 ); 893 894 // Validate the state before a theme switch. 895 $response = rest_get_server()->dispatch( $request ); 896 $data = $response->get_data(); 897 $data = $this->remove_links( $data ); 898 899 $this->assertSame( 'active', $data['status'] ); 900 $this->assertFalse( 901 get_theme_mod( 'wp_classic_sidebars' ), 902 'wp_classic_sidebars theme mod should not exist before switching to block theme' 903 ); 904 905 switch_theme( 'block-theme' ); 906 wp_widgets_init(); 907 908 // Validate the state after a theme switch. 909 $response = rest_get_server()->dispatch( $request ); 910 $data = $response->get_data(); 911 $data = $this->remove_links( $data ); 912 913 $this->assertSame( 914 'inactive', 915 $data['status'], 916 'Sidebar status should have changed to inactive' 917 ); 918 $this->assertSame( 919 array( 'text-1', 'rss-1' ), 920 $data['widgets'], 921 'The text and rss widgets should still in sidebar-1' 922 ); 923 $this->assertArrayHasKey( 924 'sidebar-1', 925 get_theme_mod( 'wp_classic_sidebars' ), 926 'sidebar-1 should be in "wp_classic_sidebars" theme mod' 927 ); 928 } 929 930 /** 864 931 * @ticket 41683 865 932 */
Note: See TracChangeset
for help on using the changeset viewer.