WP_Customize_Manager::wp_loaded PHP Method

wp_loaded() public method

Register styles/scripts and initialize the preview of each setting
Since: 3.4.0
public wp_loaded ( )
    public function wp_loaded()
    {
        /**
         * Fires once WordPress has loaded, allowing scripts and styles to be initialized.
         *
         * @since 3.4.0
         *
         * @param WP_Customize_Manager $this WP_Customize_Manager instance.
         */
        do_action('customize_register', $this);
        /*
         * Note that settings must be previewed here even outside the customizer preview
         * and also in the customizer pane itself. This is to enable loading an existing
         * changeset into the customizer. Previewing the settings only has to be prevented
         * in the case of a customize_save action because then update_option()
         * may short-circuit because it will detect that there are no changes to
         * make.
         */
        if (!$this->doing_ajax('customize_save')) {
            foreach ($this->settings as $setting) {
                $setting->preview();
            }
        }
        if ($this->is_preview() && !is_admin()) {
            $this->customize_preview_init();
        }
    }

Usage Example

 /**
  * Test WP_Customize_Manager::wp_loaded().
  *
  * Ensure that post values are previewed even without being in preview.
  *
  * @ticket 30937
  * @covers WP_Customize_Manager::wp_loaded()
  */
 function test_wp_loaded()
 {
     wp_set_current_user(self::$admin_user_id);
     $wp_customize = new WP_Customize_Manager();
     $title = 'Hello World';
     $wp_customize->set_post_value('blogname', $title);
     $this->assertNotEquals($title, get_option('blogname'));
     $wp_customize->wp_loaded();
     $this->assertFalse($wp_customize->is_preview());
     $this->assertEquals($title, $wp_customize->get_setting('blogname')->value());
     $this->assertEquals($title, get_option('blogname'));
 }
WP_Customize_Manager