WP_Customize_Manager::start_previewing_theme PHP Method

start_previewing_theme() public method

If the theme to be previewed isn't the active theme, add filter callbacks to swap it out at runtime.
Since: 3.4.0
    public function start_previewing_theme()
    {
        // Bail if we're already previewing.
        if ($this->is_preview()) {
            return;
        }
        $this->previewing = true;
        if (!$this->is_theme_active()) {
            add_filter('template', array($this, 'get_template'));
            add_filter('stylesheet', array($this, 'get_stylesheet'));
            add_filter('pre_option_current_theme', array($this, 'current_theme'));
            // @link: https://core.trac.wordpress.org/ticket/20027
            add_filter('pre_option_stylesheet', array($this, 'get_stylesheet'));
            add_filter('pre_option_template', array($this, 'get_template'));
            // Handle custom theme roots.
            add_filter('pre_option_stylesheet_root', array($this, 'get_stylesheet_root'));
            add_filter('pre_option_template_root', array($this, 'get_template_root'));
        }
        /**
         * Fires once the Customizer theme preview has started.
         *
         * @since 3.4.0
         *
         * @param WP_Customize_Manager $this WP_Customize_Manager instance.
         */
        do_action('start_previewing_theme', $this);
    }

Usage Example

 /**
  * @ticket 30937
  * @covers wp_admin_bar_customize_menu()
  */
 public function test_customize_link()
 {
     global $wp_customize;
     require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
     $uuid = wp_generate_uuid4();
     $this->go_to(home_url("/?customize_changeset_uuid={$uuid}"));
     wp_set_current_user(self::$admin_id);
     $this->factory()->post->create(array('post_type' => 'customize_changeset', 'post_status' => 'auto-draft', 'post_name' => $uuid));
     $wp_customize = new WP_Customize_Manager(array('changeset_uuid' => $uuid));
     $wp_customize->start_previewing_theme();
     set_current_screen('front');
     $wp_admin_bar = $this->get_standard_admin_bar();
     $node = $wp_admin_bar->get_node('customize');
     $this->assertNotEmpty($node);
     $parsed_url = wp_parse_url($node->href);
     $query_params = array();
     wp_parse_str($parsed_url['query'], $query_params);
     $this->assertEquals($uuid, $query_params['changeset_uuid']);
     $this->assertNotContains('changeset_uuid', $query_params['url']);
 }
All Usage Examples Of WP_Customize_Manager::start_previewing_theme
WP_Customize_Manager