/**
  * Constructor.
  *
  */
 public function __construct($manager, $id, $args = array())
 {
     //let the parent educate us
     parent::__construct($manager, $id, $args);
     $this->contexts = hu_get_contexts_list();
     $_default_locations = hu_get_builtin_widget_zones_location();
     //generates the locations for json
     $locations = array();
     foreach ($_default_locations as $_id => $data) {
         $_k = key($data);
         $locations[$_k] = $data[$_k];
     }
     $this->locations = $locations;
     //generates the default widget zone for json
     $default_zones = array();
     foreach (hu_get_default_widget_zones() as $_zone_id => $_data) {
         //get the default location
         $_loc = isset($_default_locations[$_zone_id]) ? key($_default_locations[$_zone_id]) : '';
         $default_zones[] = array('id' => $_data['id'], 'title' => $_data['name'], 'contexts' => array('_all_'), 'locations' => array($_loc), 'is_builtin' => true, 'description' => $_data['description']);
     }
     $this->default_zones = $default_zones;
     //print the pre add view content
     add_action('customize_controls_print_footer_scripts', array($this, 'hu_print_pre_add_view_template'), 1);
     //print template for built-in models like primary, secondary, footer-1, etc...
     add_action('customize_controls_print_footer_scripts', array($this, 'hu_print_built_in_templates'), 1);
 }
Exemplo n.º 2
0
 function hu_update_widget_database_option()
 {
     if (!hu_user_started_before_version('3.1.2')) {
         return;
     }
     $_options = get_option('hu_theme_options');
     $_update_widget_areas = array();
     if (!isset($_options['sidebar-areas']) || !is_array($_options['sidebar-areas'])) {
         return;
     }
     $_zones = hu_get_default_widget_zones();
     foreach ($_options['sidebar-areas'] as $key => $data) {
         if (!array_key_exists($data['id'], $_zones)) {
             continue;
         }
         $_id = $data['id'];
         $_options['sidebar-areas'][$key]['title'] = $_zones[$_id]['name'];
     }
     update_option('hu_theme_options', $_options);
 }
Exemplo n.º 3
0
 function hu_maybe_register_custom_widget_zones()
 {
     $customized = array();
     if (hu_is_customizing() && isset($_POST['customized'])) {
         $customized = json_decode(wp_unslash($_POST['customized']), true);
         if (isset($customized['hu_theme_options[sidebar-areas]'])) {
             $sidebars = $customized['hu_theme_options[sidebar-areas]'];
         } else {
             $sidebars = hu_get_option('sidebar-areas', array());
         }
     } else {
         $sidebars = hu_get_option('sidebar-areas', array());
     }
     //at this point we need smthg really clean
     if (!is_array($sidebars) || empty($sidebars)) {
         return;
     }
     $default_args = array('name' => '', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>');
     $default_zones = hu_get_default_widget_zones();
     foreach ($sidebars as $sb) {
         if (!isset($sb['id']) || empty($sb['id'])) {
             return;
         }
         //is it a built-in one?
         //=> in this case it's been registered another way
         $_id = $sb['id'];
         if (isset($default_zones[$_id])) {
             continue;
         }
         $args = wp_parse_args(array('name' => isset($sb['title']) ? '' . esc_attr($sb['title']) . '' : '', 'id' => '' . esc_attr(strtolower($sb['id'])) . ''), $default_args);
         register_sidebar($args);
     }
     //for each
 }