Update WP and plugins

This commit is contained in:
Oliver Davies 2019-04-16 20:56:22 +01:00
parent 10a4713229
commit 1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions

View file

@ -28,7 +28,7 @@ global $wp_registered_sidebars, $wp_registered_widgets, $wp_registered_widget_co
/**
* 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 @@ $GLOBALS['_wp_deprecated_widgets_callbacks'] = array(
'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 @@ function unregister_widget( $widget ) {
*
* @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 @@ function register_sidebars( $number = 1, $args = array() ) {
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 @@ function register_sidebars( $number = 1, $args = array() ) {
$_args['id'] = 'sidebar-' . ++$n;
} while ( is_registered_sidebar( $_args['id'] ) );
}
register_sidebar($_args);
register_sidebar( $_args );
}
}
@ -237,22 +239,22 @@ function register_sidebars( $number = 1, $args = array() ) {
* }
* @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 @@ function register_sidebar($args = array()) {
_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 @@ function register_sidebar($args = array()) {
*
* @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 is_registered_sidebar( $sidebar_id ) {
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 @@ function wp_register_sidebar_widget( $id, $name, $output_callback, $options = ar
* @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 @@ function wp_register_sidebar_widget( $id, $name, $output_callback, $options = ar
* @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 @@ function wp_widget_description( $id ) {
*
* @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 @@ function wp_sidebar_description( $id ) {
*
* @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 @@ function wp_unregister_sidebar_widget($id) {
*/
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_unregister_sidebar_widget($id) {
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 wp_register_widget_control( $id, $name, $control_callback, $options = a
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 @@ function _register_widget_update_callback( $id_base, $update_callback, $options
* @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' ) )
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 @@ function _register_widget_form_callback($id, $name, $form_callback, $options = a
*
* @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 @@ function wp_unregister_widget_control($id) {
*
* @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 @@ function dynamic_sidebar( $index = 1 ) {
/** 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 @@ function dynamic_sidebar( $index = 1 ) {
* 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 @@ function dynamic_sidebar( $index = 1 ) {
*/
$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 @@ function dynamic_sidebar( $index = 1 ) {
*/
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;
}
}
@ -786,11 +813,11 @@ function dynamic_sidebar( $index = 1 ) {
*
* 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/
* 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
@ -806,17 +833,18 @@ function is_active_widget( $callback = false, $widget_id = false, $id_base = fal
$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;
}
}
}
}
@ -827,26 +855,28 @@ function is_active_widget( $callback = false, $widget_id = false, $id_base = fal
/**
* 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/
* 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;
@ -854,20 +884,20 @@ function is_dynamic_sidebar() {
/**
* 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/
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
* Conditional Tags} article in the Theme Developer Handbook.
*
*
* @since 2.8.0
*
* @param string|int $index Sidebar name, id or number to check.
* @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".
@ -901,24 +931,27 @@ function is_active_sidebar( $index ) {
* @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.
@ -958,7 +991,7 @@ function wp_set_sidebars_widgets( $sidebars_widgets ) {
* @since 2.2.0
* @access private
*
* @global array $wp_registered_sidebars
* @global array $wp_registered_sidebars Registered sidebars.
*
* @return array
*/
@ -967,8 +1000,9 @@ function wp_get_widget_defaults() {
$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;
}
@ -985,16 +1019,17 @@ function wp_get_widget_defaults() {
* @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;
}
@ -1006,32 +1041,35 @@ function wp_convert_widget_settings($base_name, $option_name, $settings) {
// 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;
}
@ -1067,21 +1105,21 @@ function the_widget( $widget, $instance = array(), $args = array() ) {
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.
@ -1094,8 +1132,8 @@ function the_widget( $widget, $instance = array(), $args = array() ) {
*/
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 );
}
/**
@ -1121,10 +1159,11 @@ function _get_widget_id_base( $id ) {
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 );
}
/**
@ -1132,7 +1171,7 @@ function _wp_sidebars_changed() {
*
* @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
*
@ -1146,7 +1185,7 @@ function retrieve_widgets( $theme_changed = false ) {
$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();
}
@ -1231,7 +1270,7 @@ function wp_map_sidebars_widgets( $existing_sidebars_widgets ) {
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();
}
}
@ -1357,7 +1396,6 @@ function wp_map_sidebars_widgets( $existing_sidebars_widgets ) {
} // 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 );
}
@ -1398,34 +1436,41 @@ function _wp_remove_unregistered_widgets( $sidebars_widgets, $whitelist = array(
*/
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;
}
@ -1469,7 +1514,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
$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>';
}
@ -1485,7 +1530,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
}
echo '</ul>';
$rss->__destruct();
unset($rss);
unset( $rss );
}
/**
@ -1501,20 +1546,27 @@ function wp_widget_rss_output( $rss, $args = array() ) {
* @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>';
@ -1522,7 +1574,7 @@ function wp_widget_rss_form( $args, $inputs = null ) {
$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'] ) : ?>
@ -1546,15 +1598,15 @@ function wp_widget_rss_form( $args, $inputs = null ) {
<?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;
}
@ -1576,27 +1628,29 @@ function wp_widget_rss_form( $args, $inputs = null ) {
*/
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 );
}
}