示例#1
0
/**
 * Registers Widget Areas(Sidebars) and pre-sets default widgets
 *
 * @uses thematic_presetwidgets
 * @todo consider deprecating the widgets directory search this seems to have never been used
 */
function thematic_widgets_init()
{
    $thematic_widgetized_areas = thematic_widgets_array();
    foreach ($thematic_widgetized_areas as $key => $value) {
        register_sidebar($thematic_widgetized_areas[$key]['args']);
    }
    // Finished intializing Widgets plugin, now let's load the thematic default widgets
    register_widget('Thematic_Widget_Meta');
    register_widget('Thematic_Widget_RSSlinks');
    // Pre-set Widgets
    $preset_widgets = array('primary-aside' => array('search-2', 'pages-2', 'categories-2', 'archives-2'), 'secondary-aside' => array('links-2', 'rss-links-2', 'meta-2'));
    if (isset($_GET['activated'])) {
        thematic_presetwidgets();
        update_option('sidebars_widgets', apply_filters('thematic_preset_widgets', $preset_widgets));
    }
}
function thematic_widgets_init()
{
    $thematic_widgetized_areas = thematic_widgets_array();
    if (!function_exists('register_sidebars')) {
        return;
    }
    foreach ($thematic_widgetized_areas as $key => $value) {
        register_sidebar($thematic_widgetized_areas[$key]['args']);
    }
    // we will check for a Thematic widgets directory and and add and activate additional widgets
    // Thanks to Joern Kretzschmar
    $widgets_dir = @dir(ABSPATH . '/wp-content/themes/' . get_template() . '/widgets');
    if ($widgets_dir) {
        while (($widgetFile = $widgets_dir->read()) !== false) {
            if (!preg_match('|^\\.+$|', $widgetFile) && preg_match('|\\.php$|', $widgetFile)) {
                include ABSPATH . '/wp-content/themes/' . get_template() . '/widgets/' . $widgetFile;
            }
        }
    }
    // we will check for the child themes widgets directory and add and activate additional widgets
    // Thanks to Joern Kretzschmar
    $widgets_dir = @dir(ABSPATH . '/wp-content/themes/' . get_stylesheet() . '/widgets');
    if (TEMPLATENAME != THEMENAME && $widgets_dir) {
        while (($widgetFile = $widgets_dir->read()) !== false) {
            if (!preg_match('|^\\.+$|', $widgetFile) && preg_match('|\\.php$|', $widgetFile)) {
                include ABSPATH . '/wp-content/themes/' . get_stylesheet() . '/widgets/' . $widgetFile;
            }
        }
    }
    // Remove WP default Widgets
    // WP 2.8 function using $widget_class
    unregister_widget('WP_Widget_Meta');
    unregister_widget('WP_Widget_Search');
    // Finished intializing Widgets plugin, now let's load the thematic default widgets
    register_widget('THM_Widget_Search');
    register_widget('THM_Widget_Meta');
    register_widget('THM_Widget_RSSlinks');
    // Pre-set Widgets
    $preset_widgets = array('primary-aside' => array('search-2', 'pages-2', 'categories-2', 'archives-2'), 'secondary-aside' => array('links-2', 'rss-links-2', 'meta-2'));
    if (isset($_GET['activated'])) {
        thematic_presetwidgets();
        update_option('sidebars_widgets', apply_filters('thematic_preset_widgets', $preset_widgets));
    }
}