/**
  * Tally the sidebars rendered via dynamic_sidebar().
  *
  * Keep track of the times that dynamic_sidebar() is called in the template,
  * and assume this means the sidebar would be rendered on the template if
  * there were widgets populating it.
  *
  * @since 3.9.0
  * @access public
  *
  * @param bool   $has_widgets Whether the current sidebar has widgets.
  * @param string $sidebar_id  Sidebar ID.
  * @return bool
  */
 public function tally_sidebars_via_dynamic_sidebar_calls($has_widgets, $sidebar_id)
 {
     if (is_registered_sidebar($sidebar_id)) {
         $this->rendered_sidebars[] = $sidebar_id;
     }
     /*
      * We may need to force this to true, and also force-true the value
      * for 'is_active_sidebar' if we want to ensure there is an area to
      * drop widgets into, if the sidebar is empty.
      */
     return $has_widgets;
 }
Beispiel #2
0
	<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="https://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="https://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 (!is_registered_sidebar($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
register_sidebar(array('name' => __('Inactive Widgets'), 'id' => 'wp_inactive_widgets', 'class' => 'inactive-sidebar', 'description' => __('Drag widgets here to remove them from the sidebar but keep their settings.'), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => ''));
retrieve_widgets();
// We're saving a widget without js
if (isset($_POST['savewidget']) || isset($_POST['removewidget'])) {
    $widget_id = $_POST['widget-id'];
    check_admin_referer("save-delete-widget-{$widget_id}");
Beispiel #3
0
/**
 * Creates multiple sidebars.
 *
 * If you wanted to quickly create multiple sidebars for a theme or internally.
 * This function will allow you to do so. If you don't pass the 'name' and/or
 * 'id' in `$args`, then they will be built for you.
 *
 * @since 2.2.0
 *
 * @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
 *
 * @global array $wp_registered_sidebars
 *
 * @param int          $number Optional. Number of sidebars to create. Default 1.
 * @param array|string $args {
 *     Optional. Array or string of arguments for building a sidebar.
 *
 *     @type string $id   The base string of the unique identifier for each sidebar. If provided, and multiple
 *                        sidebars are being defined, the id will have "-2" appended, and so on.
 *                        Default 'sidebar-' followed by the number the sidebar creation is currently at.
 *     @type string $name The name or title for the sidebars displayed in the admin dashboard. If registering
 *                        more than one sidebar, include '%d' in the string as a placeholder for the uniquely
 *                        assigned number for each sidebar.
 *                        Default 'Sidebar' for the first sidebar, otherwise 'Sidebar %d'.
 * }
 */
function register_sidebars($number = 1, $args = array())
{
    global $wp_registered_sidebars;
    $number = (int) $number;
    if (is_string($args)) {
        parse_str($args, $args);
    }
    for ($i = 1; $i <= $number; $i++) {
        $_args = $args;
        if ($number > 1) {
            $_args['name'] = isset($args['name']) ? sprintf($args['name'], $i) : sprintf(__('Sidebar %d'), $i);
        } else {
            $_args['name'] = isset($args['name']) ? $args['name'] : __('Sidebar');
        }
        // Custom specified ID's are suffixed if they exist already.
        // Automatically generated sidebar names need to be suffixed regardless starting at -0
        if (isset($args['id'])) {
            $_args['id'] = $args['id'];
            $n = 2;
            // Start at -2 for conflicting custom ID's
            while (is_registered_sidebar($_args['id'])) {
                $_args['id'] = $args['id'] . '-' . $n++;
            }
        } else {
            $n = count($wp_registered_sidebars);
            do {
                $_args['id'] = 'sidebar-' . ++$n;
            } while (is_registered_sidebar($_args['id']));
        }
        register_sidebar($_args);
    }
}
 /**
  * Renders a specific widget using the supplied sidebar arguments.
  *
  * @since 4.5.0
  * @access public
  *
  * @see dynamic_sidebar()
  *
  * @param WP_Customize_Partial $partial Partial.
  * @param array                $context {
  *     Sidebar args supplied as container context.
  *
  *     @type string $sidebar_id              ID for sidebar for widget to render into.
  *     @type int    $sidebar_instance_number Disambiguating instance number.
  * }
  * @return string|false
  */
 public function render_widget_partial($partial, $context)
 {
     $id_data = $partial->id_data();
     $widget_id = array_shift($id_data['keys']);
     if (!is_array($context) || empty($context['sidebar_id']) || !is_registered_sidebar($context['sidebar_id'])) {
         return false;
     }
     $this->rendering_sidebar_id = $context['sidebar_id'];
     if (isset($context['sidebar_instance_number'])) {
         $this->context_sidebar_instance_number = intval($context['sidebar_instance_number']);
     }
     // Filter sidebars_widgets so that only the queried widget is in the sidebar.
     $this->rendering_widget_id = $widget_id;
     $filter_callback = array($this, 'filter_sidebars_widgets_for_rendering_widget');
     add_filter('sidebars_widgets', $filter_callback, 1000);
     // Render the widget.
     ob_start();
     dynamic_sidebar($this->rendering_sidebar_id = $context['sidebar_id']);
     $container = ob_get_clean();
     // Reset variables for next partial render.
     remove_filter('sidebars_widgets', $filter_callback, 1000);
     $this->context_sidebar_instance_number = null;
     $this->rendering_sidebar_id = null;
     $this->rendering_widget_id = null;
     return $container;
 }
 /**
  * Render a specific widget using the supplied sidebar arguments.
  *
  * @since 4.5.0
  * @access public
  *
  * @see dynamic_sidebar()
  *
  * @param WP_Customize_Partial $partial      Partial.
  * @param array                $context {
  *     Sidebar args supplied as container context.
  *
  *     @type string [$sidebar_id]        ID for sidebar for widget to render into.
  *     @type array  [$sidebar_args]      Sidebar args supplied as container context.
  *     @type string [$sidebar_args_hmac] HMAC for sidebar args.
  * }
  * @return string|false
  */
 public function render_widget_partial($partial, $context)
 {
     $id_data = $partial->id_data();
     $widget_id = array_shift($id_data['keys']);
     $sidebar_id = null;
     $sidebar_args = array();
     if (!is_array($context)) {
         return false;
     }
     if (!empty($context['sidebar_args'])) {
         if (empty($context['sidebar_args_hmac'])) {
             return false;
         }
         $context['sidebar_args'] = $this->ksort_recursive($context['sidebar_args']);
         if (!hash_equals($this->hash_sidebar_args($context['sidebar_args']), $context['sidebar_args_hmac'])) {
             return false;
         }
         $sidebar_args = $context['sidebar_args'];
     }
     /*
      * Note that when a widget is first added to a sidebar, it only has a sidebar_id as context.
      * For existing widgets, and subsequent updates to the newly-added widget, the sidebar_args
      * will be available because they will be included in the partial's rendered response here.
      */
     if (!empty($context['sidebar_id'])) {
         $sidebar_id = $context['sidebar_id'];
     } else {
         if (!empty($sidebar_args['id'])) {
             $sidebar_id = $sidebar_args['id'];
         } else {
             return false;
         }
     }
     if (!is_registered_sidebar($sidebar_id)) {
         return false;
     }
     if (isset($context['sidebar_instance_number'])) {
         $this->context_sidebar_instance_number = $context['sidebar_instance_number'];
     }
     // Filter sidebars_widgets so that only the queried widget is in the sidebar.
     $this->sidebar_args_overrides = $sidebar_args;
     $this->rendering_widget_id = $widget_id;
     $this->rendering_sidebar_id = $sidebar_id;
     $filter_callback = array($this, 'filter_sidebars_widgets_for_rendering_widget');
     add_filter('sidebars_widgets', $filter_callback, 1000);
     // Render the widget.
     ob_start();
     dynamic_sidebar($sidebar_id);
     $container = ob_get_clean();
     // Reset variables for next partial render.
     remove_filter('sidebars_widgets', $filter_callback, 1000);
     $this->context_sidebar_instance_number = null;
     $this->sidebar_args_overrides = array();
     $this->rendering_sidebar_id = null;
     $this->rendering_widget_id = null;
     return $container;
 }
/**
 * Replaces the RIGHT sidebar with the section sidebar, if applicable.
 *
 * @since 1.3.0
 * @access private
 *
 * @param string $sidebar_ID Current sidebar ID.
 */
function jc_section_replace_right_sidebar($sidebar_ID)
{
    if (!($section_ID = jc_site_section())) {
        return $sidebar_ID;
    }
    if (is_registered_sidebar("section-right-sidebar-{$section_ID}")) {
        return "section-right-sidebar-{$section_ID}";
    }
    return $sidebar_ID;
}