/** * check you theme exists function bind to this hook 'dynamic_sidebar_params' before use this. * @param array $params: sidebar widgets params */ public function _hw_awc_widget_change_params($params) { global $wp_registered_widgets; global $wp_registered_sidebars; $this_id = $params[0]['id']; // Get the id for the current sidebar we're processing $widget_id = $params[0]['widget_id']; $widget_obj = $wp_registered_widgets[$widget_id]; $widget_opt = get_option($widget_obj['callback'][0]->option_name); $widget_num = $widget_obj['params'][0]['number']; $arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets if (!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) { // Check if the current sidebar has no widgets return $params; // No widgets in this sidebar... bail early. } if (!is_active_sidebar($this_id)) { return $params; } //this sidebar should be actived $current_widget = $widget_opt[$widget_num]; //get current widget //check if this sidebar have any modified from user setting $enable_override_sidebar = HW_AWC_Sidebar_Settings::get_sidebar_setting('enable_override_sidebar', $this_id); //parse settings if (isset($current_widget['bgcolor_widget'])) { $color_widget = self::valid_hex_color($current_widget['bgcolor_widget']); } //callback if (!is_admin()) { $wp_registered_widgets[$widget_id]['original_callback'] = $wp_registered_widgets[$widget_id]['callback']; $wp_registered_widgets[$widget_id]['callback'] = array($this, '_hw_custom_widget_callback_function'); } /** * apply skin for specific widget */ if ($enable_override_sidebar && isset($current_widget['widget_skin'])) { //get widget skin $skin_data = HW_AWC_Sidebar_Settings::get_sidebar_setting($current_widget['widget_skin'], $this_id); if (isset($skin_data['hash_skin'])) { $hash_skin = $skin_data['hash_skin']; } if (isset($skin_data['hwskin_config'])) { $skin_config = $skin_data['hwskin_config']; } if (isset($skin_config) && $skin_config && isset($hash_skin)) { $skin = HW_SKIN::resume_skin($skin_config); //resume HW_SKIN with given config if (method_exists($skin, 'get_skin_file')) { $file = $skin->get_skin_file($hash_skin); } if (isset($file) && file_exists($file)) { $theme = array(); //valid include $file; //don't use include_one or require_once, and don't create function in skin file because will cause duplicate function $wp_registered_sidebars[$this_id]['skin'] = $skin; //bring skin object into params /** * override sidebar param */ if (isset($theme['params']) && is_array($theme['params'])) { $params[0] = array_merge($params[0], $theme['params']); } /** * this snipet from WP Core (wp-includes/widgets.php) - since version 4.0 * Substitute HTML id and class attributes into before_widget */ $classname_ = self::format_widget_sidebar_params($widget_id); $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_); /** * enqueue css & js -> depricated */ /*if(!isset($theme['styles'])) $theme['styles'] = array(); if(!isset($theme['scripts'])) $theme['scripts'] = array(); if(count($theme['styles']) || count($theme['scripts'])) { $skin->enqueue_files_from_skin($theme['styles'], $theme['scripts']); }*/ } } } $params[0] = self::format_sidebar_params($this_id, $params[0], $current_widget); //$params[0] = array_merge($params[0], $new_params); /*clear widget title*/ if (isset($current_widget['awc_clear_widget_title']) && $current_widget['awc_clear_widget_title']) { //clear before_title & after_title $params[0]['before_title'] = ''; $params[0]['after_title'] = ''; //valid HTML combine from before_widget + after_widget $tidyconfig = array('indent' => false, 'show-body-only' => true, 'clean' => false, 'output-xhtml' => true, 'input-xml' => true); $sign_str = '_______'; $html = $params[0]['before_widget'] . $sign_str . $params[0]['after_widget']; $html = HW_String::tidy_cleaning($html, $tidyconfig, 'body'); //hwawc_tidy_cleaning($html,$tidyconfig,'body'); $t = explode($sign_str, $html); if (count($t) == 2) { $params[0]['before_widget'] = $t[0]; //get new before widget $params[0]['after_widget'] = $t[1]; //get new after_widget param } } /** * show widgets with order number */ if ($enable_override_sidebar && HW_AWC_Sidebar_Settings::get_sidebar_setting('alphabe_widgets', $this_id)) { global $hwawc_widget_num; // Global a counter array if (!$hwawc_widget_num) { // If the counter array doesn't exist, create it $hwawc_widget_num = array(); } if (isset($hwawc_widget_num[$this_id])) { // See if the counter array has an entry for this sidebar $hwawc_widget_num[$this_id]++; } else { // If not, create it starting with 1 $hwawc_widget_num[$this_id] = 1; } $class_id = 'widget-' . $hwawc_widget_num[$this_id]; $class = 'class="'; // Add a widget number class for additional styling options //if(!$this->exists_class($class_id, $params[0]['before_widget'])) { $class .= $class_id . ' '; //} if ($hwawc_widget_num[$this_id] == 1) { // If this is the first widget //if(!$this->exists_class('widget-first', $params[0]['before_widget'])) $class .= 'widget-first '; } elseif ($hwawc_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) { // If this is the last widget //if(!$this->exists_class('widget-last', $params[0]['before_widget'])) $class .= 'widget-last '; } $params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']); // Insert our new classes into "before widget" } //finally if ($enable_override_sidebar) { //mark modify before_widget class by adding new class for this plugin to prevent conflict other css in your theme $params[0]['before_widget'] = str_replace('class="', 'class="hw-awc-override ', $params[0]['before_widget']); } return $params; }