Exemple #1
0
/**
 * Assigns a default set of widgets
 */
function k2_default_widgets()
{
    $sidebars_widgets = wp_get_widget_defaults();
    if (isset($sidebars_widgets['sidebar-1']) and isset($sidebars_widgets['sidebar-2'])) {
        $sidebars_widgets['sidebar-1'] = $sidebars_widgets['sidebar-2'] = array();
        k2_add_widget($sidebars_widgets['sidebar-1'], 'search');
        k2_add_widget($sidebars_widgets['sidebar-1'], 'k2-about');
        k2_add_widget($sidebars_widgets['sidebar-1'], 'recent-posts');
        k2_add_widget($sidebars_widgets['sidebar-1'], 'recent-comments');
        k2_add_widget($sidebars_widgets['sidebar-2'], 'archives');
        k2_add_widget($sidebars_widgets['sidebar-2'], 'tag_cloud');
        k2_add_widget($sidebars_widgets['sidebar-2'], 'links');
        wp_set_sidebars_widgets($sidebars_widgets);
    }
}
Exemple #2
0
$title = __('Widgets');
$parent_file = 'themes.php';
get_current_screen()->add_help_tab(array('id' => 'overview', 'title' => __('Overview'), 'content' => '<p>' . __('Widgets are independent sections of content that can be placed into any widgetized area provided by your theme (commonly called sidebars). To populate your sidebars/widget areas with individual widgets, drag and drop the title bars into the desired area. By default, only the first widget area is expanded. To populate additional widget areas, click on their title bars to expand them.') . '</p>
	<p>' . __('The Available Widgets section contains all the widgets you can choose from. Once you drag a widget into a sidebar, it will open to allow you to configure its settings. When you are happy with the widget settings, click the Save button and the widget will go live on your site. If you click Delete, it will remove the widget.') . '</p>'));
get_current_screen()->add_help_tab(array('id' => 'removing-reusing', 'title' => __('Removing and Reusing'), 'content' => '<p>' . __('If you want to remove the widget but save its setting for possible future use, just drag it into the Inactive Widgets area. You can add them back anytime from there. This is especially helpful when you switch to a theme with fewer or different widget areas.') . '</p>
	<p>' . __('Widgets may be used multiple times. You can give each widget a title, to display on your site, but it&#8217;s not required.') . '</p>
	<p>' . __('Enabling Accessibility Mode, via Screen Options, allows you to use Add and Edit buttons instead of using drag and drop.') . '</p>'));
get_current_screen()->add_help_tab(array('id' => 'missing-widgets', 'title' => __('Missing Widgets'), 'content' => '<p>' . __('Many themes show some sidebar widgets by default until you edit your sidebars, but they are not automatically displayed in your sidebar management tool. After you make your first widget change, you can re-add the default widgets by adding them from the Available Widgets area.') . '</p>' . '<p>' . __('When changing themes, there is often some variation in the number and setup of widget areas/sidebars and sometimes these conflicts make the transition a bit less smooth. If you changed themes and seem to be missing widgets, scroll down on this screen to the Inactive Widgets area, where all of your widgets and their settings will have been saved.') . '</p>'));
get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Widgets_Screen" target="_blank">Documentation on Widgets</a>') . '</p>' . '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>');
if (!current_theme_supports('widgets')) {
    wp_die(__('The theme you are currently using isn&#8217;t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="http://codex.wordpress.org/Widgetizing_Themes">follow these instructions</a>.'));
}
// These are the widgets grouped by sidebar
$sidebars_widgets = wp_get_sidebars_widgets();
if (empty($sidebars_widgets)) {
    $sidebars_widgets = wp_get_widget_defaults();
}
foreach ($sidebars_widgets as $sidebar_id => $widgets) {
    if ('wp_inactive_widgets' == $sidebar_id) {
        continue;
    }
    if (!isset($wp_registered_sidebars[$sidebar_id])) {
        if (!empty($widgets)) {
            // register the inactive_widgets area as sidebar
            register_sidebar(array('name' => __('Inactive Sidebar (not used)'), 'id' => $sidebar_id, 'class' => 'inactive-sidebar orphan-sidebar', 'description' => __('This sidebar is no longer available and does not show anywhere on your site. Remove each of the widgets below to fully remove this inactive sidebar.'), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => ''));
        } else {
            unset($sidebars_widgets[$sidebar_id]);
        }
    }
}
// register the inactive_widgets area as sidebar
        function display_layout_detail($layout_id, $post_ID)
        {
            $i = 1;
            $update = array('layout_id' => $layout_id, 'post_ID' => $post_ID, 'zones' => array());
            require_once ABSPATH . 'wp-admin/includes/widgets.php';
            global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets;
            $this->register_zones_as_sidebars();
            $sidebars_widgets = wp_get_sidebars_widgets();
            if (empty($sidebars_widgets)) {
                $sidebars_widgets = wp_get_widget_defaults();
            }
            ?>
				
				<h4><?php 
            _e("Select a zone and drag a widget", BAOL_PL_TEXTDOMAIN);
            ?>
</h4>
				<div id="widget-list" class="float-break clear">
				<?php 
            wp_list_widgets();
            ?>
				</div>
						
				<div class="details clear">
				<ul><?php 
            foreach ($this->registered_layouts[$layout_id]['zones'] as $i => $zone) {
                register_sidebar(array('name' => $zone, 'id' => 'zone-' . $i . '-page-' . $post_ID, 'before_widget' => '<div id="%1$s" class="widget zone %2$s">', 'after_widget' => '</div>', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>'));
                $update['zones'][] = 'zone-' . $i . '-page-' . $post_ID;
                ?>
				
					<li><a href="#zone-<?php 
                echo $i;
                ?>
-panel"><span><?php 
                echo $zone;
                ?>
</span></a></li><?php 
            }
            $this->current_layout = $this->set_current_layout($post_ID, $update);
            ?>
				
				</ul><?php 
            foreach ($this->registered_layouts[$layout_id]['zones'] as $i => $zone) {
                ?>
			
					<div id="zone-<?php 
                echo $i;
                ?>
-panel">
						<div class="widgets-zone-sortables zone-name">
						<?php 
                wp_list_widget_controls('zone-' . $i . '-page-' . $post_ID);
                ?>
						</div>
					</div><?php 
            }
            ?>
				
				</div>
				
				<div style="display:none !important">
				
				<?php 
            foreach ($wp_registered_sidebars as $sidebar => $registered_sidebar) {
                if (in_array($sidebar, $update['zones'])) {
                    continue;
                }
                wp_list_widget_controls($sidebar);
            }
            ?>
				
				</div><?php 
        }