Beispiel #1
0
 /**
  * Front-end display of widget
  *
  * Load template from parent or child theme if exists.
  *
  * @since 0.9
  * @param array $args Widget arguments
  * @param array $instance Widget instance
  */
 function widget($args, $instance)
 {
     global $post;
     // setup_postdata() needs this
     // Available widgets
     $widgets = ChurchThemeFrameworkWidgets::widgetList();
     // Get template filename
     $template_file = $widgets[$this->id_base]['template_file'];
     // Check if template exists
     $template_path = CTFW_WIDGETS_WIDGET_TEMPLATE_DIR . '/' . $template_file;
     // Sanitize widget instance (field values) before loading template
     $instance = $this->ctc_sanitize($instance);
     // Make instance available to other methods used by template (e.g. get_posts())
     $this->ctc_instance = $instance;
     if (file_exists($template_path)) {
         include $template_path;
     }
 }
            foreach ($files as $file) {
                if (file_exists($file)) {
                    include_once $file;
                }
            }
        }
    }
    public static function widgetList()
    {
        $widgets = array('ctc-categories' => array('class' => 'CTFW_Widget_Categories', 'class_file' => 'widget-categories.php', 'template_file' => 'widget-categories.php', 'ctc_required' => false, 'theme_support' => 'ctc-widget-categories', 'theme_support_required' => array(), 'icon' => 'dashicons-microphone', 'unregister' => array('WP_Widget_Categories')), 'ctc-posts' => array('class' => 'CTFW_Widget_Posts', 'class_file' => 'widget-posts.php', 'template_file' => 'widget-posts.php', 'ctc_required' => false, 'theme_support' => 'ctc-widget-posts', 'theme_support_required' => array(), 'unregister' => array('WP_Widget_Recent_Posts')), 'ctc-sermons' => array('class' => 'CTFW_Widget_Sermons', 'class_file' => 'widget-sermons.php', 'template_file' => 'widget-sermons.php', 'ctc_required' => true, 'theme_support' => 'ctc-widget-sermons', 'theme_support_required' => array('ctc-sermons'), 'unregister' => array()), 'ctc-events' => array('class' => 'CTFW_Widget_Events', 'class_file' => 'widget-events.php', 'template_file' => 'widget-events.php', 'ctc_required' => true, 'theme_support' => 'ctc-widget-events', 'theme_support_required' => array('ctc-events'), 'unregister' => array()), 'ctc-gallery' => array('class' => 'CTFW_Widget_Gallery', 'class_file' => 'widget-gallery.php', 'template_file' => 'widget-gallery.php', 'ctc_required' => false, 'theme_support' => 'ctc-widget-gallery', 'theme_support_required' => array(), 'unregister' => array()), 'ctc-galleries' => array('class' => 'CTFW_Widget_Galleries', 'class_file' => 'widget-galleries.php', 'template_file' => 'widget-galleries.php', 'ctc_required' => false, 'theme_support' => 'ctc-widget-galleries', 'theme_support_required' => array(), 'unregister' => array()), 'ctc-people' => array('class' => 'CTFW_Widget_People', 'class_file' => 'widget-people.php', 'template_file' => 'widget-people.php', 'ctc_required' => true, 'theme_support' => 'ctc-widget-people', 'theme_support_required' => array('ctc-people'), 'unregister' => array()), 'ctc-locations' => array('class' => 'CTFW_Widget_Locations', 'class_file' => 'widget-locations.php', 'template_file' => 'widget-locations.php', 'ctc_required' => true, 'theme_support' => 'ctc-widget-locations', 'theme_support_required' => array('ctc-locations'), 'unregister' => array()), 'ctc-archives' => array('class' => 'CTFW_Widget_Archives', 'class_file' => 'widget-archives.php', 'template_file' => 'widget-archives.php', 'ctc_required' => false, 'theme_support' => 'ctc-widget-archives', 'theme_support_required' => array(), 'unregister' => array('WP_Widget_Archives')), 'ctc-giving' => array('class' => 'CTFW_Widget_Giving', 'class_file' => 'widget-giving.php', 'template_file' => 'widget-giving.php', 'ctc_required' => false, 'theme_support' => 'ctc-widget-giving', 'theme_support_required' => array(), 'unregister' => array()), 'ctc-highlight' => array('class' => 'CTFW_Widget_Highlight', 'class_file' => 'widget-highlight.php', 'template_file' => 'widget-highlight.php', 'ctc_required' => false, 'theme_support' => 'ctc-widget-highlight', 'theme_support_required' => array(), 'unregister' => array()));
        return $widgets;
    }
    public static function registerWidgets()
    {
        $widgets = self::widgetList();
        foreach ($widgets as $widget_id => $widget_data) {
            $widget_class_path = trailingslashit(CTFW_WIDGETS_CLASS_DIR) . $widget_data['class_file'];
            if (file_exists($widget_class_path)) {
                include_once $widget_class_path;
                register_widget($widget_data['class']);
                if (isset($widget_data['unregister'])) {
                    foreach ($widget_data['unregister'] as $unregister_widget) {
                        unregister_widget($unregister_widget);
                    }
                }
            }
        }
    }
}
ChurchThemeFrameworkWidgets::init();