WP_Customize_Manager::doing_ajax PHP Method

doing_ajax() public method

Return true if it's an Ajax request.
Since: 3.4.0
Since: 4.2.0 Added `$action` param.
public doing_ajax ( string | null $action = null ) : boolean
$action string | null Whether the supplied Ajax action is being run.
return boolean True if it's an Ajax request, false otherwise.
    public function doing_ajax($action = null)
    {
        if (!wp_doing_ajax()) {
            return false;
        }
        if (!$action) {
            return true;
        } else {
            /*
             * Note: we can't just use doing_action( "wp_ajax_{$action}" ) because we need
             * to check before admin-ajax.php gets to that point.
             */
            return isset($_REQUEST['action']) && wp_unslash($_REQUEST['action']) === $action;
        }
    }

Usage Example

 /**
  * Override sidebars_widgets for theme switch.
  *
  * When switching a theme via the customizer, supply any previously-configured
  * sidebars_widgets from the target theme as the initial sidebars_widgets
  * setting. Also store the old theme's existing settings so that they can
  * be passed along for storing in the sidebars_widgets theme_mod when the
  * theme gets switched.
  *
  * @since 3.9.0
  * @access public
  */
 public function override_sidebars_widgets_for_theme_switch()
 {
     global $sidebars_widgets;
     if ($this->manager->doing_ajax() || $this->manager->is_theme_active()) {
         return;
     }
     $this->old_sidebars_widgets = wp_get_sidebars_widgets();
     add_filter('customize_value_old_sidebars_widgets_data', array($this, 'filter_customize_value_old_sidebars_widgets_data'));
     // retrieve_widgets() looks at the global $sidebars_widgets
     $sidebars_widgets = $this->old_sidebars_widgets;
     $sidebars_widgets = retrieve_widgets('customize');
     add_filter('option_sidebars_widgets', array($this, 'filter_option_sidebars_widgets_for_theme_switch'), 1);
 }
All Usage Examples Of WP_Customize_Manager::doing_ajax
WP_Customize_Manager