register_control_type() публичный Метод

Registered types are eligible to be rendered via JS and created dynamically.
С версии: 4.1.0
public register_control_type ( string $control )
$control string Name of a custom control which is a subclass of WP_Customize_Control.
Пример #1
0
/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function blue_planet_customize_register($wp_customize)
{
    $new_defaults = blue_planet_get_default_options();
    $options = blue_planet_get_option_all();
    // Custom Controls.
    require get_template_directory() . '/inc/customizer-includes/controls.php';
    $wp_customize->register_control_type('Blue_Planet_Customize_Heading_Control');
    $wp_customize->register_control_type('Blue_Planet_Customize_Dropdown_Taxonomies_Control');
    // Theme Settings.
    require get_template_directory() . '/inc/customizer-includes/theme.php';
    // Slider Settings.
    require get_template_directory() . '/inc/customizer-includes/slider.php';
    // Reset Settings.
    require get_template_directory() . '/inc/customizer-includes/reset.php';
}
 /**
  * Add the customizer settings and controls.
  *
  * @since 4.3.0
  * @access public
  */
 public function customize_register()
 {
     // 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')) {
         $description .= '<p>' . sprintf(__('Menus can be displayed in locations defined by your theme or in <a href="%s">widget areas</a> by adding a &#8220;Custom Menu&#8221; 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.');
     } else {
         $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));
     }
     $description .= '</p><p>' . __('You can also place menus in widget areas with the Custom Menu widget.') . '</p>';
     $this->manager->add_section('menu_locations', array('title' => __('Menu Locations'), 'panel' => 'nav_menus', 'priority' => 5, 'description' => $description));
     $choices = array('0' => __('&mdash; Select &mdash;'));
     foreach ($menus as $menu) {
         $choices[$menu->term_id] = wp_html_excerpt($menu->name, 40, '&hellip;');
     }
     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));
         // 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;
             $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)));
             // 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_setting('new_menu_name', array('type' => 'new_menu', 'default' => '', 'transport' => 'postMessage'));
     $this->manager->add_control('new_menu_name', array('label' => '', 'section' => 'add_menu', 'type' => 'text', 'input_attrs' => array('class' => 'menu-name-field', 'placeholder' => __('New menu name'))));
     $this->manager->add_setting('create_new_menu', array('type' => 'new_menu'));
     $this->manager->add_control(new WP_Customize_New_Menu_Control($this->manager, 'create_new_menu', array('section' => 'add_menu')));
 }
 /**
  * Register section and controls for REST resources.
  *
  * Note that this needs to happen at a priority greater than 11 for
  * customize_register so that dynamic settings will have been registered via
  * {@see \WP_Customize_Manager::register_dynamic_settings}.
  *
  * @param \WP_Customize_Manager $wp_customize Manager.
  */
 public function customize_register(\WP_Customize_Manager $wp_customize)
 {
     $wp_customize->register_control_type(__NAMESPACE__ . '\\WP_Customize_REST_Resource_Control');
     $section_id = 'rest_resources';
     $section = new WP_Customize_REST_Resources_Section($wp_customize, $section_id, array('title' => __('REST Resources', 'customize-rest-resources')));
     $wp_customize->add_section($section);
     // @todo Create a panel with multiple sections correspondng to each endpoint.
     // @todo Mirror this in JS.
     $i = 0;
     foreach ($wp_customize->settings() as $setting) {
         $needs_rest_control = $setting instanceof WP_Customize_REST_Resource_Setting && !$wp_customize->get_control($setting->id);
         if ($needs_rest_control) {
             $control = new WP_Customize_REST_Resource_Control($wp_customize, $setting->id, array('section' => $section_id, 'settings' => $setting->id, 'priority' => $i));
             $wp_customize->add_control($control);
             $i += 1;
         }
     }
 }