예제 #1
0
파일: widgets.php 프로젝트: pqzada/avispate
 public function widget_display_callback($instance, $widget, $args)
 {
     //Logger::log(__CLASS__.'::'.__FUNCTION__);
     //Logger::log( array_merge( array('instance' => get_class($widget)), $instance) );
     //Widget Display
     $widget_display = isset($instance['widget_display']) ? $instance['widget_display'] : array();
     if (check_wdisplay($widget_display) == false) {
         return false;
     }
     if ($style = $this->getStyleIn($instance)) {
         if (isset($style['before_widget']) && !empty($style['before_widget'])) {
             // Substitute HTML id and class attributes into before_widget
             global $wp_registered_widgets;
             $classname_ = '';
             foreach ((array) $wp_registered_widgets[$widget->id]['classname'] as $cn) {
                 if (is_string($cn)) {
                     $classname_ .= '_' . $cn;
                 } elseif (is_object($cn)) {
                     $classname_ .= '_' . get_class($cn);
                 }
             }
             $classname_ = ltrim($classname_, '_');
             $args['before_widget'] = sprintf($style['before_widget'], $widget->id, $classname_);
         }
         if (isset($style['after_widget'])) {
             $args['after_widget'] = $style['after_widget'];
         }
         if (isset($style['before_title']) || isset($style['after_title'])) {
             $args['before_title'] = $style['before_title'];
             $args['after_title'] = $style['after_title'];
         }
         //var_dump($args);
         $widget->widget($args, $instance);
         return false;
     }
     return $instance;
 }
예제 #2
0
/**
 *  Is active sidebar
 * */
function is_active_sidebar_YA($index)
{
    global $wp_registered_widgets;
    $index = is_int($index) ? "sidebar-{$index}" : sanitize_title($index);
    $sidebars_widgets = wp_get_sidebars_widgets();
    if (!empty($sidebars_widgets[$index])) {
        foreach ($sidebars_widgets[$index] as $i => $id) {
            $id_base = preg_replace('/-[0-9]+$/', '', $id);
            if (isset($wp_registered_widgets[$id])) {
                $widget = new WP_Widget($id_base, $wp_registered_widgets[$id]['name']);
                if (preg_match('/' . $id_base . '-([0-9]+)$/', $id, $matches)) {
                    $number = $matches[1];
                }
                $instances = get_option($widget->option_name);
                if (isset($instances) && isset($number)) {
                    $instance = $instances[$number];
                    if (isset($instance['widget_display']) && check_wdisplay($instance['widget_display']) == false) {
                        unset($sidebars_widgets[$index][$i]);
                    }
                }
            }
        }
        if (empty($sidebars_widgets[$index])) {
            return false;
        }
    } else {
        return false;
    }
    return true;
}