--- a/wp/wp-includes/widgets.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/widgets.php Mon Oct 14 18:28:13 2019 +0200
@@ -28,7 +28,7 @@
/**
* Stores the sidebars, since many themes can have more than one.
*
- * @global array $wp_registered_sidebars
+ * @global array $wp_registered_sidebars Registered sidebars.
* @since 2.2.0
*/
$wp_registered_sidebars = array();
@@ -87,7 +87,7 @@
'wp_widget_rss',
'wp_widget_rss_control',
'wp_widget_recent_comments',
- 'wp_widget_recent_comments_control'
+ 'wp_widget_recent_comments_control',
);
//
@@ -148,7 +148,7 @@
*
* @see register_sidebar() The second parameter is documented by register_sidebar() and is the same here.
*
- * @global array $wp_registered_sidebars
+ * @global array $wp_registered_sidebars The new sidebars are stored in this array by sidebar ID.
*
* @param int $number Optional. Number of sidebars to create. Default 1.
* @param array|string $args {
@@ -167,22 +167,24 @@
global $wp_registered_sidebars;
$number = (int) $number;
- if ( is_string($args) )
- parse_str($args, $args);
+ 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');
+ 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']) ) {
+ if ( isset( $args['id'] ) ) {
$_args['id'] = $args['id'];
- $n = 2; // Start at -2 for conflicting custom ID's
+ $n = 2; // Start at -2 for conflicting custom ID's
while ( is_registered_sidebar( $_args['id'] ) ) {
$_args['id'] = $args['id'] . '-' . $n++;
}
@@ -192,7 +194,7 @@
$_args['id'] = 'sidebar-' . ++$n;
} while ( is_registered_sidebar( $_args['id'] ) );
}
- register_sidebar($_args);
+ register_sidebar( $_args );
}
}
@@ -237,22 +239,22 @@
* }
* @return string Sidebar ID added to $wp_registered_sidebars global.
*/
-function register_sidebar($args = array()) {
+function register_sidebar( $args = array() ) {
global $wp_registered_sidebars;
- $i = count($wp_registered_sidebars) + 1;
+ $i = count( $wp_registered_sidebars ) + 1;
$id_is_empty = empty( $args['id'] );
$defaults = array(
- 'name' => sprintf(__('Sidebar %d'), $i ),
- 'id' => "sidebar-$i",
- 'description' => '',
- 'class' => '',
+ 'name' => sprintf( __( 'Sidebar %d' ), $i ),
+ 'id' => "sidebar-$i",
+ 'description' => '',
+ 'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
- 'after_widget' => "</li>\n",
- 'before_title' => '<h2 class="widgettitle">',
- 'after_title' => "</h2>\n",
+ 'after_widget' => "</li>\n",
+ 'before_title' => '<h2 class="widgettitle">',
+ 'after_title' => "</h2>\n",
);
$sidebar = wp_parse_args( $args, $defaults );
@@ -262,9 +264,9 @@
_doing_it_wrong( __FUNCTION__, sprintf( __( 'No %1$s was set in the arguments array for the "%2$s" sidebar. Defaulting to "%3$s". Manually set the %1$s to "%3$s" to silence this notice and keep existing sidebar content.' ), '<code>id</code>', $sidebar['name'], $sidebar['id'] ), '4.2.0' );
}
- $wp_registered_sidebars[$sidebar['id']] = $sidebar;
+ $wp_registered_sidebars[ $sidebar['id'] ] = $sidebar;
- add_theme_support('widgets');
+ add_theme_support( 'widgets' );
/**
* Fires once a sidebar has been registered.
@@ -283,7 +285,7 @@
*
* @since 2.2.0
*
- * @global array $wp_registered_sidebars Stores the new sidebar in this array by sidebar ID.
+ * @global array $wp_registered_sidebars Removes the sidebar from this array by sidebar ID.
*
* @param string|int $sidebar_id The ID of the sidebar when it was registered.
*/
@@ -339,31 +341,31 @@
function wp_register_sidebar_widget( $id, $name, $output_callback, $options = array() ) {
global $wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks;
- $id = strtolower($id);
+ $id = strtolower( $id );
- if ( empty($output_callback) ) {
- unset($wp_registered_widgets[$id]);
+ if ( empty( $output_callback ) ) {
+ unset( $wp_registered_widgets[ $id ] );
return;
}
- $id_base = _get_widget_id_base($id);
- if ( in_array($output_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($output_callback) ) {
+ $id_base = _get_widget_id_base( $id );
+ if ( in_array( $output_callback, $_wp_deprecated_widgets_callbacks, true ) && ! is_callable( $output_callback ) ) {
unset( $wp_registered_widget_controls[ $id ] );
unset( $wp_registered_widget_updates[ $id_base ] );
return;
}
- $defaults = array('classname' => $output_callback);
- $options = wp_parse_args($options, $defaults);
- $widget = array(
- 'name' => $name,
- 'id' => $id,
+ $defaults = array( 'classname' => $output_callback );
+ $options = wp_parse_args( $options, $defaults );
+ $widget = array(
+ 'name' => $name,
+ 'id' => $id,
'callback' => $output_callback,
- 'params' => array_slice(func_get_args(), 4)
+ 'params' => array_slice( func_get_args(), 4 ),
);
- $widget = array_merge($widget, $options);
+ $widget = array_merge( $widget, $options );
- if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || did_action( 'widgets_init' ) ) ) {
+ if ( is_callable( $output_callback ) && ( ! isset( $wp_registered_widgets[ $id ] ) || did_action( 'widgets_init' ) ) ) {
/**
* Fires once for each registered widget.
@@ -373,7 +375,7 @@
* @param array $widget An array of default widget arguments.
*/
do_action( 'wp_register_sidebar_widget', $widget );
- $wp_registered_widgets[$id] = $widget;
+ $wp_registered_widgets[ $id ] = $widget;
}
}
@@ -392,13 +394,15 @@
* @return string|void Widget description, if available.
*/
function wp_widget_description( $id ) {
- if ( !is_scalar($id) )
+ if ( ! is_scalar( $id ) ) {
return;
+ }
global $wp_registered_widgets;
- if ( isset($wp_registered_widgets[$id]['description']) )
- return esc_html( $wp_registered_widgets[$id]['description'] );
+ if ( isset( $wp_registered_widgets[ $id ]['description'] ) ) {
+ return esc_html( $wp_registered_widgets[ $id ]['description'] );
+ }
}
/**
@@ -409,14 +413,15 @@
*
* @since 2.9.0
*
- * @global array $wp_registered_sidebars
+ * @global array $wp_registered_sidebars Registered sidebars.
*
* @param string $id sidebar ID.
* @return string|void Sidebar description, if available.
*/
function wp_sidebar_description( $id ) {
- if ( !is_scalar($id) )
+ if ( ! is_scalar( $id ) ) {
return;
+ }
global $wp_registered_sidebars;
@@ -432,7 +437,7 @@
*
* @param int|string $id Widget ID.
*/
-function wp_unregister_sidebar_widget($id) {
+function wp_unregister_sidebar_widget( $id ) {
/**
* Fires just before a widget is removed from a sidebar.
@@ -443,8 +448,8 @@
*/
do_action( 'wp_unregister_sidebar_widget', $id );
- wp_register_sidebar_widget($id, '', '');
- wp_unregister_widget_control($id);
+ wp_register_sidebar_widget( $id, '', '' );
+ wp_unregister_widget_control( $id );
}
/**
@@ -475,46 +480,52 @@
function wp_register_widget_control( $id, $name, $control_callback, $options = array() ) {
global $wp_registered_widget_controls, $wp_registered_widget_updates, $wp_registered_widgets, $_wp_deprecated_widgets_callbacks;
- $id = strtolower($id);
- $id_base = _get_widget_id_base($id);
+ $id = strtolower( $id );
+ $id_base = _get_widget_id_base( $id );
- if ( empty($control_callback) ) {
- unset($wp_registered_widget_controls[$id]);
- unset($wp_registered_widget_updates[$id_base]);
+ if ( empty( $control_callback ) ) {
+ unset( $wp_registered_widget_controls[ $id ] );
+ unset( $wp_registered_widget_updates[ $id_base ] );
return;
}
- if ( in_array($control_callback, $_wp_deprecated_widgets_callbacks, true) && !is_callable($control_callback) ) {
+ if ( in_array( $control_callback, $_wp_deprecated_widgets_callbacks, true ) && ! is_callable( $control_callback ) ) {
unset( $wp_registered_widgets[ $id ] );
return;
}
- if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) )
+ if ( isset( $wp_registered_widget_controls[ $id ] ) && ! did_action( 'widgets_init' ) ) {
return;
+ }
- $defaults = array('width' => 250, 'height' => 200 ); // height is never used
- $options = wp_parse_args($options, $defaults);
- $options['width'] = (int) $options['width'];
+ $defaults = array(
+ 'width' => 250,
+ 'height' => 200,
+ ); // height is never used
+ $options = wp_parse_args( $options, $defaults );
+ $options['width'] = (int) $options['width'];
$options['height'] = (int) $options['height'];
$widget = array(
- 'name' => $name,
- 'id' => $id,
+ 'name' => $name,
+ 'id' => $id,
'callback' => $control_callback,
- 'params' => array_slice(func_get_args(), 4)
+ 'params' => array_slice( func_get_args(), 4 ),
);
- $widget = array_merge($widget, $options);
+ $widget = array_merge( $widget, $options );
- $wp_registered_widget_controls[$id] = $widget;
+ $wp_registered_widget_controls[ $id ] = $widget;
- if ( isset($wp_registered_widget_updates[$id_base]) )
+ if ( isset( $wp_registered_widget_updates[ $id_base ] ) ) {
return;
+ }
- if ( isset($widget['params'][0]['number']) )
+ if ( isset( $widget['params'][0]['number'] ) ) {
$widget['params'][0]['number'] = -1;
+ }
- unset($widget['width'], $widget['height'], $widget['name'], $widget['id']);
- $wp_registered_widget_updates[$id_base] = $widget;
+ unset( $widget['width'], $widget['height'], $widget['name'], $widget['id'] );
+ $wp_registered_widget_updates[ $id_base ] = $widget;
}
/**
@@ -532,19 +543,20 @@
function _register_widget_update_callback( $id_base, $update_callback, $options = array() ) {
global $wp_registered_widget_updates;
- if ( isset($wp_registered_widget_updates[$id_base]) ) {
- if ( empty($update_callback) )
- unset($wp_registered_widget_updates[$id_base]);
+ if ( isset( $wp_registered_widget_updates[ $id_base ] ) ) {
+ if ( empty( $update_callback ) ) {
+ unset( $wp_registered_widget_updates[ $id_base ] );
+ }
return;
}
$widget = array(
'callback' => $update_callback,
- 'params' => array_slice(func_get_args(), 3)
+ 'params' => array_slice( func_get_args(), 3 ),
);
- $widget = array_merge($widget, $options);
- $wp_registered_widget_updates[$id_base] = $widget;
+ $widget = array_merge( $widget, $options );
+ $wp_registered_widget_updates[ $id_base ] = $widget;
}
/**
@@ -560,33 +572,37 @@
* @param array $options Optional. Widget control options. See wp_register_widget_control().
* Default empty array.
*/
-function _register_widget_form_callback($id, $name, $form_callback, $options = array()) {
+function _register_widget_form_callback( $id, $name, $form_callback, $options = array() ) {
global $wp_registered_widget_controls;
- $id = strtolower($id);
+ $id = strtolower( $id );
- if ( empty($form_callback) ) {
- unset($wp_registered_widget_controls[$id]);
+ if ( empty( $form_callback ) ) {
+ unset( $wp_registered_widget_controls[ $id ] );
+ return;
+ }
+
+ if ( isset( $wp_registered_widget_controls[ $id ] ) && ! did_action( 'widgets_init' ) ) {
return;
}
- if ( isset($wp_registered_widget_controls[$id]) && !did_action( 'widgets_init' ) )
- return;
-
- $defaults = array('width' => 250, 'height' => 200 );
- $options = wp_parse_args($options, $defaults);
- $options['width'] = (int) $options['width'];
+ $defaults = array(
+ 'width' => 250,
+ 'height' => 200,
+ );
+ $options = wp_parse_args( $options, $defaults );
+ $options['width'] = (int) $options['width'];
$options['height'] = (int) $options['height'];
$widget = array(
- 'name' => $name,
- 'id' => $id,
+ 'name' => $name,
+ 'id' => $id,
'callback' => $form_callback,
- 'params' => array_slice(func_get_args(), 4)
+ 'params' => array_slice( func_get_args(), 4 ),
);
- $widget = array_merge($widget, $options);
+ $widget = array_merge( $widget, $options );
- $wp_registered_widget_controls[$id] = $widget;
+ $wp_registered_widget_controls[ $id ] = $widget;
}
/**
@@ -596,7 +612,7 @@
*
* @param int|string $id Widget ID.
*/
-function wp_unregister_widget_control($id) {
+function wp_unregister_widget_control( $id ) {
wp_register_widget_control( $id, '', '' );
}
@@ -609,7 +625,7 @@
*
* @since 2.2.0
*
- * @global array $wp_registered_sidebars
+ * @global array $wp_registered_sidebars Registered sidebars.
* @global array $wp_registered_widgets
*
* @param int|string $index Optional, default is 1. Index, name or ID of dynamic sidebar.
@@ -635,7 +651,7 @@
/** This action is documented in wp-includes/widget.php */
do_action( 'dynamic_sidebar_before', $index, false );
/** This action is documented in wp-includes/widget.php */
- do_action( 'dynamic_sidebar_after', $index, false );
+ do_action( 'dynamic_sidebar_after', $index, false );
/** This filter is documented in wp-includes/widget.php */
return apply_filters( 'dynamic_sidebar_has_widgets', false, $index );
}
@@ -653,28 +669,39 @@
* Default true.
*/
do_action( 'dynamic_sidebar_before', $index, true );
- $sidebar = $wp_registered_sidebars[$index];
+ $sidebar = $wp_registered_sidebars[ $index ];
$did_one = false;
- foreach ( (array) $sidebars_widgets[$index] as $id ) {
+ 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']
+ 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) )
+ foreach ( (array) $wp_registered_widgets[ $id ]['classname'] as $cn ) {
+ if ( is_string( $cn ) ) {
$classname_ .= '_' . $cn;
- elseif ( is_object($cn) )
- $classname_ .= '_' . get_class($cn);
+ } elseif ( is_object( $cn ) ) {
+ $classname_ .= '_' . get_class( $cn );
+ }
}
- $classname_ = ltrim($classname_, '_');
- $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
+ $classname_ = ltrim( $classname_, '_' );
+ $params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $id, $classname_ );
/**
* Filters the parameters passed to a widget's display callback.
@@ -710,7 +737,7 @@
*/
$params = apply_filters( 'dynamic_sidebar_params', $params );
- $callback = $wp_registered_widgets[$id]['callback'];
+ $callback = $wp_registered_widgets[ $id ]['callback'];
/**
* Fires before a widget's display callback is called.
@@ -739,8 +766,8 @@
*/
do_action( 'dynamic_sidebar', $wp_registered_widgets[ $id ] );
- if ( is_callable($callback) ) {
- call_user_func_array($callback, $params);
+ if ( is_callable( $callback ) ) {
+ call_user_func_array( $callback, $params );
$did_one = true;
}
}
@@ -775,7 +802,7 @@
}
/**
- * Whether widget is displayed on the front end.
+ * Determines whether a given widget is displayed on the front end.
*
* Either $callback or $id_base can be used
* $id_base is the first argument when extending WP_Widget class
@@ -787,6 +814,10 @@
* NOTE: $widget_id and $id_base are the same for single widgets. To be effective
* this function has to run after widgets have initialized, at action {@see 'init'} or later.
*
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
+ *
* @since 2.2.0
*
* @global array $wp_registered_widgets
@@ -802,17 +833,18 @@
$sidebars_widgets = wp_get_sidebars_widgets();
- if ( is_array($sidebars_widgets) ) {
+ if ( is_array( $sidebars_widgets ) ) {
foreach ( $sidebars_widgets as $sidebar => $widgets ) {
if ( $skip_inactive && ( 'wp_inactive_widgets' === $sidebar || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) ) {
continue;
}
- if ( is_array($widgets) ) {
+ if ( is_array( $widgets ) ) {
foreach ( $widgets as $widget ) {
- if ( ( $callback && isset($wp_registered_widgets[$widget]['callback']) && $wp_registered_widgets[$widget]['callback'] == $callback ) || ( $id_base && _get_widget_id_base($widget) == $id_base ) ) {
- if ( !$widget_id || $widget_id == $wp_registered_widgets[$widget]['id'] )
+ if ( ( $callback && isset( $wp_registered_widgets[ $widget ]['callback'] ) && $wp_registered_widgets[ $widget ]['callback'] == $callback ) || ( $id_base && _get_widget_id_base( $widget ) == $id_base ) ) {
+ if ( ! $widget_id || $widget_id == $wp_registered_widgets[ $widget ]['id'] ) {
return $sidebar;
+ }
}
}
}
@@ -822,30 +854,40 @@
}
/**
- * Whether the dynamic sidebar is enabled and used by theme.
+ * Determines whether the dynamic sidebar is enabled and used by the theme.
+ *
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
*
* @since 2.2.0
*
* @global array $wp_registered_widgets
- * @global array $wp_registered_sidebars
+ * @global array $wp_registered_sidebars Registered sidebars.
*
* @return bool True, if using widgets. False, if not using widgets.
*/
function is_dynamic_sidebar() {
global $wp_registered_widgets, $wp_registered_sidebars;
- $sidebars_widgets = get_option('sidebars_widgets');
+ $sidebars_widgets = get_option( 'sidebars_widgets' );
foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
if ( ! empty( $sidebars_widgets[ $index ] ) ) {
- foreach ( (array) $sidebars_widgets[$index] as $widget )
- if ( array_key_exists($widget, $wp_registered_widgets) )
+ foreach ( (array) $sidebars_widgets[ $index ] as $widget ) {
+ if ( array_key_exists( $widget, $wp_registered_widgets ) ) {
return true;
+ }
+ }
}
}
return false;
}
/**
- * Whether a sidebar is in use.
+ * Determines whether a sidebar is in use.
+ *
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
*
* @since 2.8.0
*
@@ -853,9 +895,9 @@
* @return bool true if the sidebar is in use, false otherwise.
*/
function is_active_sidebar( $index ) {
- $index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index);
- $sidebars_widgets = wp_get_sidebars_widgets();
- $is_active_sidebar = ! empty( $sidebars_widgets[$index] );
+ $index = ( is_int( $index ) ) ? "sidebar-$index" : sanitize_title( $index );
+ $sidebars_widgets = wp_get_sidebars_widgets();
+ $is_active_sidebar = ! empty( $sidebars_widgets[ $index ] );
/**
* Filters whether a dynamic sidebar is considered "active".
@@ -889,24 +931,27 @@
* @return array Upgraded list of widgets to version 3 array format when called from the admin.
*/
function wp_get_sidebars_widgets( $deprecated = true ) {
- if ( $deprecated !== true )
+ if ( $deprecated !== true ) {
_deprecated_argument( __FUNCTION__, '2.8.1' );
+ }
global $_wp_sidebars_widgets, $sidebars_widgets;
// If loading from front page, consult $_wp_sidebars_widgets rather than options
// to see if wp_convert_widget_settings() has made manipulations in memory.
- if ( !is_admin() ) {
- if ( empty($_wp_sidebars_widgets) )
- $_wp_sidebars_widgets = get_option('sidebars_widgets', array());
+ if ( ! is_admin() ) {
+ if ( empty( $_wp_sidebars_widgets ) ) {
+ $_wp_sidebars_widgets = get_option( 'sidebars_widgets', array() );
+ }
$sidebars_widgets = $_wp_sidebars_widgets;
} else {
- $sidebars_widgets = get_option('sidebars_widgets', array());
+ $sidebars_widgets = get_option( 'sidebars_widgets', array() );
}
- if ( is_array( $sidebars_widgets ) && isset($sidebars_widgets['array_version']) )
- unset($sidebars_widgets['array_version']);
+ if ( is_array( $sidebars_widgets ) && isset( $sidebars_widgets['array_version'] ) ) {
+ unset( $sidebars_widgets['array_version'] );
+ }
/**
* Filters the list of sidebars and their widgets.
@@ -946,7 +991,7 @@
* @since 2.2.0
* @access private
*
- * @global array $wp_registered_sidebars
+ * @global array $wp_registered_sidebars Registered sidebars.
*
* @return array
*/
@@ -955,8 +1000,9 @@
$defaults = array();
- foreach ( (array) $wp_registered_sidebars as $index => $sidebar )
- $defaults[$index] = array();
+ foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
+ $defaults[ $index ] = array();
+ }
return $defaults;
}
@@ -973,16 +1019,17 @@
* @param array $settings
* @return array
*/
-function wp_convert_widget_settings($base_name, $option_name, $settings) {
+function wp_convert_widget_settings( $base_name, $option_name, $settings ) {
// This test may need expanding.
$single = $changed = false;
- if ( empty($settings) ) {
+ if ( empty( $settings ) ) {
$single = true;
} else {
- foreach ( array_keys($settings) as $number ) {
- if ( 'number' == $number )
+ foreach ( array_keys( $settings ) as $number ) {
+ if ( 'number' == $number ) {
continue;
- if ( !is_numeric($number) ) {
+ }
+ if ( ! is_numeric( $number ) ) {
$single = true;
break;
}
@@ -994,32 +1041,35 @@
// If loading from the front page, update sidebar in memory but don't save to options
if ( is_admin() ) {
- $sidebars_widgets = get_option('sidebars_widgets');
+ $sidebars_widgets = get_option( 'sidebars_widgets' );
} else {
- if ( empty($GLOBALS['_wp_sidebars_widgets']) )
- $GLOBALS['_wp_sidebars_widgets'] = get_option('sidebars_widgets', array());
+ if ( empty( $GLOBALS['_wp_sidebars_widgets'] ) ) {
+ $GLOBALS['_wp_sidebars_widgets'] = get_option( 'sidebars_widgets', array() );
+ }
$sidebars_widgets = &$GLOBALS['_wp_sidebars_widgets'];
}
foreach ( (array) $sidebars_widgets as $index => $sidebar ) {
- if ( is_array($sidebar) ) {
+ if ( is_array( $sidebar ) ) {
foreach ( $sidebar as $i => $name ) {
if ( $base_name == $name ) {
- $sidebars_widgets[$index][$i] = "$name-2";
- $changed = true;
+ $sidebars_widgets[ $index ][ $i ] = "$name-2";
+ $changed = true;
break 2;
}
}
}
}
- if ( is_admin() && $changed )
- update_option('sidebars_widgets', $sidebars_widgets);
+ if ( is_admin() && $changed ) {
+ update_option( 'sidebars_widgets', $sidebars_widgets );
+ }
}
$settings['_multiwidget'] = 1;
- if ( is_admin() )
+ if ( is_admin() ) {
update_option( $option_name, $settings );
+ }
return $settings;
}
@@ -1055,21 +1105,21 @@
return;
}
- $widget_obj = $wp_widget_factory->widgets[$widget];
+ $widget_obj = $wp_widget_factory->widgets[ $widget ];
if ( ! ( $widget_obj instanceof WP_Widget ) ) {
return;
}
- $default_args = array(
+ $default_args = array(
'before_widget' => '<div class="widget %s">',
- 'after_widget' => "</div>",
+ 'after_widget' => '</div>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
);
- $args = wp_parse_args( $args, $default_args );
+ $args = wp_parse_args( $args, $default_args );
$args['before_widget'] = sprintf( $args['before_widget'], $widget_obj->widget_options['classname'] );
- $instance = wp_parse_args($instance);
+ $instance = wp_parse_args( $instance );
/**
* Fires before rendering the requested widget.
@@ -1082,8 +1132,8 @@
*/
do_action( 'the_widget', $widget, $instance, $args );
- $widget_obj->_set(-1);
- $widget_obj->widget($args, $instance);
+ $widget_obj->_set( -1 );
+ $widget_obj->widget( $args, $instance );
}
/**
@@ -1109,10 +1159,11 @@
function _wp_sidebars_changed() {
global $sidebars_widgets;
- if ( ! is_array( $sidebars_widgets ) )
+ if ( ! is_array( $sidebars_widgets ) ) {
$sidebars_widgets = wp_get_sidebars_widgets();
+ }
- retrieve_widgets(true);
+ retrieve_widgets( true );
}
/**
@@ -1120,7 +1171,7 @@
*
* @since 2.8.0
*
- * @global array $wp_registered_sidebars
+ * @global array $wp_registered_sidebars Registered sidebars.
* @global array $sidebars_widgets
* @global array $wp_registered_widgets
*
@@ -1134,7 +1185,7 @@
$registered_sidebars_keys = array_keys( $wp_registered_sidebars );
$registered_widgets_ids = array_keys( $wp_registered_widgets );
- if ( ! is_array( get_theme_mod( 'sidebars_widgets' ) ) ) {
+ if ( ! is_array( get_theme_mod( 'sidebars_widgets' ) ) ) {
if ( empty( $sidebars_widgets ) ) {
return array();
}
@@ -1219,7 +1270,7 @@
if ( in_array( $sidebar, $existing_sidebars, true ) ) {
$new_sidebars_widgets[ $sidebar ] = $existing_sidebars_widgets[ $sidebar ];
unset( $existing_sidebars_widgets[ $sidebar ] );
- } else if ( ! array_key_exists( $sidebar, $new_sidebars_widgets ) ) {
+ } elseif ( ! array_key_exists( $sidebar, $new_sidebars_widgets ) ) {
$new_sidebars_widgets[ $sidebar ] = array();
}
}
@@ -1345,7 +1396,6 @@
} // endforeach ( $old_sidebars_widgets as $old_sidebar => $old_widgets )
} // endif ( ! empty( $old_sidebars_widgets ) )
-
// Restore widget settings from when theme was previously active.
$new_sidebars_widgets = array_merge( $new_sidebars_widgets, $old_sidebars_widgets );
}
@@ -1386,34 +1436,41 @@
*/
function wp_widget_rss_output( $rss, $args = array() ) {
if ( is_string( $rss ) ) {
- $rss = fetch_feed($rss);
- } elseif ( is_array($rss) && isset($rss['url']) ) {
+ $rss = fetch_feed( $rss );
+ } elseif ( is_array( $rss ) && isset( $rss['url'] ) ) {
$args = $rss;
- $rss = fetch_feed($rss['url']);
- } elseif ( !is_object($rss) ) {
+ $rss = fetch_feed( $rss['url'] );
+ } elseif ( ! is_object( $rss ) ) {
return;
}
- if ( is_wp_error($rss) ) {
- if ( is_admin() || current_user_can('manage_options') )
+ if ( is_wp_error( $rss ) ) {
+ if ( is_admin() || current_user_can( 'manage_options' ) ) {
echo '<p><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</p>';
+ }
return;
}
- $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );
- $args = wp_parse_args( $args, $default_args );
+ $default_args = array(
+ 'show_author' => 0,
+ 'show_date' => 0,
+ 'show_summary' => 0,
+ 'items' => 0,
+ );
+ $args = wp_parse_args( $args, $default_args );
$items = (int) $args['items'];
- if ( $items < 1 || 20 < $items )
+ if ( $items < 1 || 20 < $items ) {
$items = 10;
- $show_summary = (int) $args['show_summary'];
- $show_author = (int) $args['show_author'];
- $show_date = (int) $args['show_date'];
+ }
+ $show_summary = (int) $args['show_summary'];
+ $show_author = (int) $args['show_author'];
+ $show_date = (int) $args['show_date'];
- if ( !$rss->get_item_quantity() ) {
+ if ( ! $rss->get_item_quantity() ) {
echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
$rss->__destruct();
- unset($rss);
+ unset( $rss );
return;
}
@@ -1457,7 +1514,7 @@
$author = '';
if ( $show_author ) {
$author = $item->get_author();
- if ( is_object($author) ) {
+ if ( is_object( $author ) ) {
$author = $author->get_name();
$author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
}
@@ -1473,7 +1530,7 @@
}
echo '</ul>';
$rss->__destruct();
- unset($rss);
+ unset( $rss );
}
/**
@@ -1489,20 +1546,27 @@
* @param array $inputs Override default display options.
*/
function wp_widget_rss_form( $args, $inputs = null ) {
- $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
- $inputs = wp_parse_args( $inputs, $default_inputs );
+ $default_inputs = array(
+ 'url' => true,
+ 'title' => true,
+ 'items' => true,
+ 'show_summary' => true,
+ 'show_author' => true,
+ 'show_date' => true,
+ );
+ $inputs = wp_parse_args( $inputs, $default_inputs );
$args['title'] = isset( $args['title'] ) ? $args['title'] : '';
- $args['url'] = isset( $args['url'] ) ? $args['url'] : '';
+ $args['url'] = isset( $args['url'] ) ? $args['url'] : '';
$args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0;
if ( $args['items'] < 1 || 20 < $args['items'] ) {
$args['items'] = 10;
}
- $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
- $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
- $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
+ $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
+ $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
+ $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
if ( ! empty( $args['error'] ) ) {
echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>';
@@ -1510,7 +1574,7 @@
$esc_number = esc_attr( $args['number'] );
if ( $inputs['url'] ) :
-?>
+ ?>
<p><label for="rss-url-<?php echo $esc_number; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label>
<input class="widefat" id="rss-url-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][url]" type="text" value="<?php echo esc_url( $args['url'] ); ?>" /></p>
<?php endif; if ( $inputs['title'] ) : ?>
@@ -1534,15 +1598,15 @@
<?php endif; if ( $inputs['show_date'] ) : ?>
<p><input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/>
<label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p>
-<?php
+ <?php
endif;
- foreach ( array_keys($default_inputs) as $input ) :
- if ( 'hidden' === $inputs[$input] ) :
- $id = str_replace( '_', '-', $input );
-?>
- <input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" />
-<?php
- endif;
+foreach ( array_keys( $default_inputs ) as $input ) :
+ if ( 'hidden' === $inputs[ $input ] ) :
+ $id = str_replace( '_', '-', $input );
+ ?>
+<input type="hidden" id="rss-<?php echo esc_attr( $id ); ?>-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][<?php echo esc_attr( $input ); ?>]" value="<?php echo esc_attr( $args[ $input ] ); ?>" />
+ <?php
+ endif;
endforeach;
}
@@ -1564,27 +1628,29 @@
*/
function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
$items = (int) $widget_rss['items'];
- if ( $items < 1 || 20 < $items )
+ if ( $items < 1 || 20 < $items ) {
$items = 10;
- $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );
- $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
- $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
- $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0;
- $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
+ }
+ $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );
+ $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
+ $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
+ $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0;
+ $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
if ( $check_feed ) {
- $rss = fetch_feed($url);
+ $rss = fetch_feed( $url );
$error = false;
- $link = '';
- if ( is_wp_error($rss) ) {
+ $link = '';
+ if ( is_wp_error( $rss ) ) {
$error = $rss->get_error_message();
} else {
- $link = esc_url(strip_tags($rss->get_permalink()));
- while ( stristr($link, 'http') != $link )
- $link = substr($link, 1);
+ $link = esc_url( strip_tags( $rss->get_permalink() ) );
+ while ( stristr( $link, 'http' ) != $link ) {
+ $link = substr( $link, 1 );
+ }
$rss->__destruct();
- unset($rss);
+ unset( $rss );
}
}