Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: WordPress/WordPress
...
head fork: xwp/WordPress-deprecated
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 21, 2013
Weston Ruter westonruter Add temp hooks for Widgets UI Refresh
Goal is to allow plugins to force a sidebar to appear even if it lacks widgets.
This then will allow plugins to output a drop zone for dragging widgets into
the customizer, for example. Four action hooks are added:

 * temp_before_dynamic_sidebar
 * temp_after_dynamic_sidebar
 * temp_dynamic_sidebar_did_one
 * temp_is_active_sidebar
5db4d40
Showing with 43 additions and 34 deletions.
  1. +43 −34 wp-includes/widgets.php
77 wp-includes/widgets.php
View
@@ -857,49 +857,59 @@ function dynamic_sidebar($index = 1) {
}
}
+ $did_one = false;
$sidebars_widgets = wp_get_sidebars_widgets();
- if ( empty( $sidebars_widgets ) )
- return false;
+ $is_empty_sidebar = (
+ empty( $sidebars_widgets )
+ ||
+ empty( $wp_registered_sidebars[$index] )
+ ||
+ ! array_key_exists( $index, $sidebars_widgets )
+ ||
+ ! is_array( $sidebars_widgets[$index] )
+ ||
+ empty( $sidebars_widgets[$index] )
+ );
- if ( empty($wp_registered_sidebars[$index]) || !array_key_exists($index, $sidebars_widgets) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) )
- return false;
+ do_action( 'temp_before_dynamic_sidebar', $index, $is_empty_sidebar );
+ if ( ! $is_empty_sidebar ) {
+ $sidebar = $wp_registered_sidebars[$index];
- $sidebar = $wp_registered_sidebars[$index];
+ foreach ( (array) $sidebars_widgets[$index] as $id ) {
- $did_one = false;
- foreach ( (array) $sidebars_widgets[$index] as $id ) {
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
- if ( !isset($wp_registered_widgets[$id]) ) continue;
-
- $params = array_merge(
- array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
- (array) $wp_registered_widgets[$id]['params']
- );
+ $params = array_merge(
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
+ (array) $wp_registered_widgets[$id]['params']
+ );
- // Substitute HTML id and class attributes into before_widget
- $classname_ = '';
- foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
- if ( is_string($cn) )
- $classname_ .= '_' . $cn;
- elseif ( is_object($cn) )
- $classname_ .= '_' . get_class($cn);
- }
- $classname_ = ltrim($classname_, '_');
- $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
+ // Substitute HTML id and class attributes into before_widget
+ $classname_ = '';
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
+ if ( is_string($cn) )
+ $classname_ .= '_' . $cn;
+ elseif ( is_object($cn) )
+ $classname_ .= '_' . get_class($cn);
+ }
+ $classname_ = ltrim($classname_, '_');
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
- $params = apply_filters( 'dynamic_sidebar_params', $params );
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
- $callback = $wp_registered_widgets[$id]['callback'];
+ $callback = $wp_registered_widgets[$id]['callback'];
- do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] );
+ do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] );
- if ( is_callable($callback) ) {
- call_user_func_array($callback, $params);
- $did_one = true;
+ if ( is_callable($callback) ) {
+ call_user_func_array($callback, $params);
+ $did_one = true;
+ }
}
}
+ do_action( 'temp_after_dynamic_sidebar', $index, $is_empty_sidebar );
- return $did_one;
+ return apply_filters( 'temp_dynamic_sidebar_did_one', $did_one, $index );
}
/**
@@ -977,10 +987,9 @@ function is_dynamic_sidebar() {
function is_active_sidebar( $index ) {
$index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index);
$sidebars_widgets = wp_get_sidebars_widgets();
- if ( !empty($sidebars_widgets[$index]) )
- return true;
-
- return false;
+ $is_active_sidebar = ! empty( $sidebars_widgets[$index] );
+ $is_active_sidebar = apply_filters( 'temp_is_active_sidebar', $is_active_sidebar, $index );
+ return $is_active_sidebar;
}
/* Internal Functions */

No commit comments for this range

Something went wrong with that request. Please try again.