public function letsDoIt($sidebars) { $all_possible_conditions = smk_sidebar_conditions_filter(); $generated_data = $this->allGeneratedSidebars(); foreach ($generated_data as $sidebar_id => $sidebar_settings) { $sidebars_to_replace = !empty($sidebar_settings['replace']) ? $sidebar_settings['replace'] : false; $conditions = !empty($sidebar_settings['conditions']) && is_array($sidebar_settings['conditions']) ? $sidebar_settings['conditions'] : false; $enabled_conditions = !empty($sidebar_settings['enable-conditions']) && 'enabled' == $sidebar_settings['enable-conditions'] ? $sidebar_settings['enable-conditions'] : false; // If conditions are enabled if ($sidebars_to_replace && $enabled_conditions && $conditions) { foreach ($conditions as $condition) { if (!empty($condition['if']) && 'none' !== $condition['if']) { $the_type = explode('::', $condition['if']); if (!empty($the_type[0]) && !empty($the_type[1])) { if (array_key_exists($the_type[0], $all_possible_conditions)) { $class = $all_possible_conditions[$the_type[0]]; if (class_exists($class)) { $newclass = new $class(); $second_condition = !empty($condition['equalto']) ? $condition['equalto'] : array(); $can_replace = $newclass->canReplace($the_type[1], $second_condition); if ($can_replace) { foreach ($sidebars_to_replace as $sidebar_to_replace_id) { if (array_key_exists($sidebar_to_replace_id, $sidebars) && isset($sidebars[$sidebar_id])) { $sidebars[$sidebar_to_replace_id] = $sidebars[$sidebar_id]; } } } } } } } } } elseif ($sidebars_to_replace) { foreach ($sidebars_to_replace as $sidebar_to_replace_id) { if (array_key_exists($sidebar_to_replace_id, $sidebars) && isset($sidebars[$sidebar_id])) { $sidebars[$sidebar_to_replace_id] = $sidebars[$sidebar_id]; } } } } return $sidebars; }
/** * Get Equal to Options * * @param string $type Example pot_type::page * @return array */ public function getEqualToOptions($type) { $the_type = explode('::', $type); $options = array(); $all_conditions = smk_sidebar_conditions_filter(); if (!empty($all_conditions) && is_array($all_conditions)) { if (array_key_exists($the_type[0], $all_conditions)) { $class = $all_conditions[$the_type[0]]; if (class_exists($class)) { $newclass = new $class(); $newoptions = $newclass->getSecondaryData($type); if (!empty($newoptions) && is_array($newoptions)) { $options = $options + (array) $newoptions; } } } } return $options; }
public function __construct($name) { $this->name = $name; $this->allCond = smk_sidebar_conditions_filter(); add_filter('smk_sidebar_conditions_filter', array($this, 'add')); }