本文整理汇总了PHP中WP_Customize_Manager::doing_ajax方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Customize_Manager::doing_ajax方法的具体用法?PHP WP_Customize_Manager::doing_ajax怎么用?PHP WP_Customize_Manager::doing_ajax使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Customize_Manager
的用法示例。
在下文中一共展示了WP_Customize_Manager::doing_ajax方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: override_sidebars_widgets_for_theme_switch
/**
* 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);
}
示例2: array
/**
* Register Customizer settings and controls for the given widget IDs.
*
* @param array $register_widget_ids
*/
function customize_register_widgets($register_widget_ids)
{
global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_sidebars;
$new_setting_ids = array();
$sidebars_widgets = wp_get_sidebars_widgets();
foreach ($register_widget_ids as $widget_id) {
$setting_id = $this->manager->widgets->get_setting_id($widget_id);
if (!$this->manager->get_setting($setting_id)) {
$setting_class = 'WP_Customize_Setting';
// This will likely get filtered to WP_Customize_Widget_Setting.
$setting_args = $this->manager->widgets->get_setting_args($setting_id);
/** This filter is documented in wp-includes/class-wp-customize-manager.php */
$setting_args = apply_filters('customize_dynamic_setting_args', $setting_args, $setting_id);
/** This filter is documented in wp-includes/class-wp-customize-manager.php */
$setting_class = apply_filters('customize_dynamic_setting_class', $setting_class, $setting_id, $setting_args);
$setting = new $setting_class($this->manager, $setting_id, $setting_args);
$this->manager->add_setting($setting);
$new_setting_ids[] = $setting_id;
}
}
// Add a control for each active widget (located in a sidebar).
foreach ($sidebars_widgets as $sidebar_id => $sidebar_widget_ids) {
if (empty($sidebar_widget_ids) || !isset($wp_registered_sidebars[$sidebar_id])) {
continue;
}
foreach ($sidebar_widget_ids as $i => $widget_id) {
$setting_id = $this->manager->widgets->get_setting_id($widget_id);
$should_register = in_array($widget_id, $register_widget_ids) && isset($wp_registered_widgets[$widget_id]) && !$this->manager->get_control($setting_id);
if (!$should_register) {
continue;
}
$registered_widget = $wp_registered_widgets[$widget_id];
$id_base = $wp_registered_widget_controls[$widget_id]['id_base'];
$control = new \WP_Widget_Form_Customize_Control($this->manager, $setting_id, array('label' => $registered_widget['name'], 'section' => sprintf('sidebar-widgets-%s', $sidebar_id), 'sidebar_id' => $sidebar_id, 'widget_id' => $widget_id, 'widget_id_base' => $id_base, 'priority' => $i, 'width' => $wp_registered_widget_controls[$widget_id]['width'], 'height' => $wp_registered_widget_controls[$widget_id]['height'], 'is_wide' => $this->manager->widgets->is_wide_widget($widget_id)));
$this->manager->add_control($control);
}
}
if (!$this->manager->doing_ajax('customize_save')) {
foreach ($new_setting_ids as $new_setting_id) {
$this->manager->get_setting($new_setting_id)->preview();
}
}
}
开发者ID:BE-Webdesign,项目名称:wp-customize-widgets-plus,代码行数:48,代码来源:class-optimized-widget-registration.php
示例3: customize_register
/**
* Register Customizer settings and controls for all sidebars and widgets.
*
* @since 3.9.0
* @access public
*
* @global array $wp_registered_widgets
* @global array $wp_registered_widget_controls
* @global array $wp_registered_sidebars
*/
public function customize_register()
{
global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_sidebars;
$sidebars_widgets = array_merge(array('wp_inactive_widgets' => array()), array_fill_keys(array_keys($wp_registered_sidebars), array()), wp_get_sidebars_widgets());
$new_setting_ids = array();
/*
* Register a setting for all widgets, including those which are active,
* inactive, and orphaned since a widget may get suppressed from a sidebar
* via a plugin (like Widget Visibility).
*/
foreach (array_keys($wp_registered_widgets) as $widget_id) {
$setting_id = $this->get_setting_id($widget_id);
$setting_args = $this->get_setting_args($setting_id);
if (!$this->manager->get_setting($setting_id)) {
$this->manager->add_setting($setting_id, $setting_args);
}
$new_setting_ids[] = $setting_id;
}
/*
* Add a setting which will be supplied for the theme's sidebars_widgets
* theme_mod when the the theme is switched.
*/
if (!$this->manager->is_theme_active()) {
$setting_id = 'old_sidebars_widgets_data';
$setting_args = $this->get_setting_args($setting_id, array('type' => 'global_variable', 'dirty' => true));
$this->manager->add_setting($setting_id, $setting_args);
}
$this->manager->add_panel('widgets', array('type' => 'widgets', 'title' => __('Widgets'), 'description' => __('Widgets are independent sections of content that can be placed into widgetized areas provided by your theme (commonly called sidebars).'), 'priority' => 110, 'active_callback' => array($this, 'is_panel_active')));
foreach ($sidebars_widgets as $sidebar_id => $sidebar_widget_ids) {
if (empty($sidebar_widget_ids)) {
$sidebar_widget_ids = array();
}
$is_registered_sidebar = is_registered_sidebar($sidebar_id);
$is_inactive_widgets = 'wp_inactive_widgets' === $sidebar_id;
$is_active_sidebar = $is_registered_sidebar && !$is_inactive_widgets;
// Add setting for managing the sidebar's widgets.
if ($is_registered_sidebar || $is_inactive_widgets) {
$setting_id = sprintf('sidebars_widgets[%s]', $sidebar_id);
$setting_args = $this->get_setting_args($setting_id);
if (!$this->manager->get_setting($setting_id)) {
if (!$this->manager->is_theme_active()) {
$setting_args['dirty'] = true;
}
$this->manager->add_setting($setting_id, $setting_args);
}
$new_setting_ids[] = $setting_id;
// Add section to contain controls.
$section_id = sprintf('sidebar-widgets-%s', $sidebar_id);
if ($is_active_sidebar) {
$section_args = array('title' => $wp_registered_sidebars[$sidebar_id]['name'], 'description' => $wp_registered_sidebars[$sidebar_id]['description'], 'priority' => array_search($sidebar_id, array_keys($wp_registered_sidebars)), 'panel' => 'widgets', 'sidebar_id' => $sidebar_id);
/**
* Filter Customizer widget section arguments for a given sidebar.
*
* @since 3.9.0
*
* @param array $section_args Array of Customizer widget section arguments.
* @param string $section_id Customizer section ID.
* @param int|string $sidebar_id Sidebar ID.
*/
$section_args = apply_filters('customizer_widgets_section_args', $section_args, $section_id, $sidebar_id);
$section = new WP_Customize_Sidebar_Section($this->manager, $section_id, $section_args);
$this->manager->add_section($section);
$control = new WP_Widget_Area_Customize_Control($this->manager, $setting_id, array('section' => $section_id, 'sidebar_id' => $sidebar_id, 'priority' => count($sidebar_widget_ids)));
$new_setting_ids[] = $setting_id;
$this->manager->add_control($control);
}
}
// Add a control for each active widget (located in a sidebar).
foreach ($sidebar_widget_ids as $i => $widget_id) {
// Skip widgets that may have gone away due to a plugin being deactivated.
if (!$is_active_sidebar || !isset($wp_registered_widgets[$widget_id])) {
continue;
}
$registered_widget = $wp_registered_widgets[$widget_id];
$setting_id = $this->get_setting_id($widget_id);
$id_base = $wp_registered_widget_controls[$widget_id]['id_base'];
$control = new WP_Widget_Form_Customize_Control($this->manager, $setting_id, array('label' => $registered_widget['name'], 'section' => $section_id, 'sidebar_id' => $sidebar_id, 'widget_id' => $widget_id, 'widget_id_base' => $id_base, 'priority' => $i, 'width' => $wp_registered_widget_controls[$widget_id]['width'], 'height' => $wp_registered_widget_controls[$widget_id]['height'], 'is_wide' => $this->is_wide_widget($widget_id)));
$this->manager->add_control($control);
}
}
if (!$this->manager->doing_ajax('customize_save')) {
foreach ($new_setting_ids as $new_setting_id) {
$this->manager->get_setting($new_setting_id)->preview();
}
}
add_filter('sidebars_widgets', array($this, 'preview_sidebars_widgets'), 1);
}
示例4: customize_register
/**
* Add the customizer settings and controls.
*
* @since 4.3.0
* @access public
*/
public function customize_register()
{
// Preview settings for nav menus early so that the sections and controls will be added properly.
$nav_menus_setting_ids = array();
foreach (array_keys($this->manager->unsanitized_post_values()) as $setting_id) {
if (preg_match('/^(nav_menu_locations|nav_menu|nav_menu_item)\\[/', $setting_id)) {
$nav_menus_setting_ids[] = $setting_id;
}
}
$this->manager->add_dynamic_settings($nav_menus_setting_ids);
if (!$this->manager->doing_ajax('customize_save')) {
foreach ($nav_menus_setting_ids as $setting_id) {
$setting = $this->manager->get_setting($setting_id);
if ($setting) {
$setting->preview();
}
}
}
// Require JS-rendered control types.
$this->manager->register_panel_type('WP_Customize_Nav_Menus_Panel');
$this->manager->register_control_type('WP_Customize_Nav_Menu_Control');
$this->manager->register_control_type('WP_Customize_Nav_Menu_Name_Control');
$this->manager->register_control_type('WP_Customize_Nav_Menu_Auto_Add_Control');
$this->manager->register_control_type('WP_Customize_Nav_Menu_Item_Control');
// Create a panel for Menus.
$description = '<p>' . __('This panel is used for managing navigation menus for content you have already published on your site. You can create menus and add items for existing content such as pages, posts, categories, tags, formats, or custom links.') . '</p>';
if (current_theme_supports('widgets')) {
/* translators: URL to the widgets panel of the customizer */
$description .= '<p>' . sprintf(__('Menus can be displayed in locations defined by your theme or in <a href="%s">widget areas</a> by adding a “Custom Menu” widget.'), "javascript:wp.customize.panel( 'widgets' ).focus();") . '</p>';
} else {
$description .= '<p>' . __('Menus can be displayed in locations defined by your theme.') . '</p>';
}
$this->manager->add_panel(new WP_Customize_Nav_Menus_Panel($this->manager, 'nav_menus', array('title' => __('Menus'), 'description' => $description, 'priority' => 100)));
$menus = wp_get_nav_menus();
// Menu locations.
$locations = get_registered_nav_menus();
$num_locations = count(array_keys($locations));
if (1 == $num_locations) {
$description = '<p>' . __('Your theme supports one menu. Select which menu you would like to use.') . '</p>';
} else {
/* translators: %s: number of menu locations */
$description = '<p>' . sprintf(_n('Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations), number_format_i18n($num_locations)) . '</p>';
}
if (current_theme_supports('widgets')) {
/* translators: URL to the widgets panel of the customizer */
$description .= '<p>' . sprintf(__('You can also place menus in <a href="%s">widget areas</a> with the “Custom Menu” widget.'), "javascript:wp.customize.panel( 'widgets' ).focus();") . '</p>';
}
$this->manager->add_section('menu_locations', array('title' => __('Menu Locations'), 'panel' => 'nav_menus', 'priority' => 5, 'description' => $description));
$choices = array('0' => __('— Select —'));
foreach ($menus as $menu) {
$choices[$menu->term_id] = wp_html_excerpt($menu->name, 40, '…');
}
foreach ($locations as $location => $description) {
$setting_id = "nav_menu_locations[{$location}]";
$setting = $this->manager->get_setting($setting_id);
if ($setting) {
$setting->transport = 'postMessage';
remove_filter("customize_sanitize_{$setting_id}", 'absint');
add_filter("customize_sanitize_{$setting_id}", array($this, 'intval_base10'));
} else {
$this->manager->add_setting($setting_id, array('sanitize_callback' => array($this, 'intval_base10'), 'theme_supports' => 'menus', 'type' => 'theme_mod', 'transport' => 'postMessage', 'default' => 0));
}
$this->manager->add_control(new WP_Customize_Nav_Menu_Location_Control($this->manager, $setting_id, array('label' => $description, 'location_id' => $location, 'section' => 'menu_locations', 'choices' => $choices)));
}
// Register each menu as a Customizer section, and add each menu item to each menu.
foreach ($menus as $menu) {
$menu_id = $menu->term_id;
// Create a section for each menu.
$section_id = 'nav_menu[' . $menu_id . ']';
$this->manager->add_section(new WP_Customize_Nav_Menu_Section($this->manager, $section_id, array('title' => html_entity_decode($menu->name, ENT_QUOTES, get_bloginfo('charset')), 'priority' => 10, 'panel' => 'nav_menus')));
$nav_menu_setting_id = 'nav_menu[' . $menu_id . ']';
$this->manager->add_setting(new WP_Customize_Nav_Menu_Setting($this->manager, $nav_menu_setting_id, array('transport' => 'postMessage')));
// Add the menu contents.
$menu_items = (array) wp_get_nav_menu_items($menu_id);
foreach (array_values($menu_items) as $i => $item) {
// Create a setting for each menu item (which doesn't actually manage data, currently).
$menu_item_setting_id = 'nav_menu_item[' . $item->ID . ']';
$value = (array) $item;
if (empty($value['post_title'])) {
$value['title'] = '';
}
$value['nav_menu_term_id'] = $menu_id;
$this->manager->add_setting(new WP_Customize_Nav_Menu_Item_Setting($this->manager, $menu_item_setting_id, array('value' => $value, 'transport' => 'postMessage')));
// Create a control for each menu item.
$this->manager->add_control(new WP_Customize_Nav_Menu_Item_Control($this->manager, $menu_item_setting_id, array('label' => $item->title, 'section' => $section_id, 'priority' => 10 + $i)));
}
// Note: other controls inside of this section get added dynamically in JS via the MenuSection.ready() function.
}
// Add the add-new-menu section and controls.
$this->manager->add_section(new WP_Customize_New_Menu_Section($this->manager, 'add_menu', array('title' => __('Add a Menu'), 'panel' => 'nav_menus', 'priority' => 999)));
$this->manager->add_control('new_menu_name', array('label' => '', 'section' => 'add_menu', 'type' => 'text', 'settings' => array(), 'input_attrs' => array('class' => 'menu-name-field', 'placeholder' => __('New menu name'))));
$this->manager->add_control(new WP_Customize_New_Menu_Control($this->manager, 'create_new_menu', array('section' => 'add_menu', 'settings' => array())));
$this->manager->add_setting(new WP_Customize_Filter_Setting($this->manager, 'nav_menus_created_posts', array('transport' => 'postMessage', 'type' => 'option', 'default' => array(), 'sanitize_callback' => array($this, 'sanitize_nav_menus_created_posts'))));
}