diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index 51c88ef5fcf81..5f24d96a54cca 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -286,13 +286,8 @@ public function __construct( $args = array() ) { $args['messenger_channel'] = sanitize_key( wp_unslash( $_REQUEST['customize_messenger_channel'] ) ); } - // Do not load 'widgets' component if a block theme is activated. - if ( ! wp_is_block_theme() ) { - $this->components[] = 'widgets'; - } - $this->original_stylesheet = get_stylesheet(); - $this->theme = wp_get_theme( 0 === validate_file( $args['theme'] ) ? $args['theme'] : null ); + $this->theme = 0 === validate_file( $args['theme'] ) ? $args['theme'] : null; $this->messenger_channel = $args['messenger_channel']; $this->_changeset_uuid = $args['changeset_uuid']; @@ -515,6 +510,14 @@ public function wp_die_handler() { public function setup_theme() { global $pagenow; + // Do not load 'widgets' component if a block theme is activated. + if ( ! wp_is_block_theme() ) { + $this->components[] = 'widgets'; + } + + // Use the theme value stored during instantiation to get the WP_Theme object. + $this->theme = wp_get_theme( $this->theme ); + // Check permissions for customize.php access since this method is called before customize.php can run any code. if ( 'customize.php' === $pagenow && ! current_user_can( 'customize' ) ) { if ( ! is_user_logged_in() ) {