diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/class-wp-widget.php --- a/wp/wp-includes/class-wp-widget.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/class-wp-widget.php Mon Oct 14 18:28:13 2019 +0200 @@ -110,7 +110,7 @@ * @param array $instance The settings for the particular instance of the widget. */ public function widget( $args, $instance ) { - die('function WP_Widget::widget() must be over-ridden in a sub-class.'); + die( 'function WP_Widget::widget() must be over-ridden in a sub-class.' ); } /** @@ -140,7 +140,7 @@ * @return string Default return is 'noform'. */ public function form( $instance ) { - echo '

' . __('There are no options for this widget.') . '

'; + echo '

' . __( 'There are no options for this widget.' ) . '

'; return 'noform'; } @@ -160,10 +160,16 @@ * information on accepted arguments. Default empty array. */ public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) { - $this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base); - $this->name = $name; - $this->option_name = 'widget_' . $this->id_base; - $this->widget_options = wp_parse_args( $widget_options, array( 'classname' => $this->option_name, 'customize_selective_refresh' => false ) ); + $this->id_base = empty( $id_base ) ? preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) ) : strtolower( $id_base ); + $this->name = $name; + $this->option_name = 'widget_' . $this->id_base; + $this->widget_options = wp_parse_args( + $widget_options, + array( + 'classname' => $this->option_name, + 'customize_selective_refresh' => false, + ) + ); $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) ); } @@ -199,7 +205,7 @@ * @param string $field_name Field name * @return string Name attribute for $field_name */ - public function get_field_name($field_name) { + public function get_field_name( $field_name ) { if ( false === $pos = strpos( $field_name, '[' ) ) { return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']'; } else { @@ -230,7 +236,7 @@ */ public function _register() { $settings = $this->get_settings(); - $empty = true; + $empty = true; // When $settings is an array-like object, get an intrinsic array for use with array_keys(). if ( $settings instanceof ArrayObject || $settings instanceof ArrayIterator ) { @@ -262,9 +268,9 @@ * @param int $number The unique order number of this widget instance compared to other * instances of the same class. */ - public function _set($number) { + public function _set( $number ) { $this->number = $number; - $this->id = $this->id_base . '-' . $number; + $this->id = $this->id_base . '-' . $number; } /** @@ -275,7 +281,7 @@ * @return callable Display callback. */ public function _get_display_callback() { - return array($this, 'display_callback'); + return array( $this, 'display_callback' ); } /** @@ -286,7 +292,7 @@ * @return callable Update callback. */ public function _get_update_callback() { - return array($this, 'update_callback'); + return array( $this, 'update_callback' ); } /** @@ -297,7 +303,7 @@ * @return callable Form callback. */ public function _get_form_callback() { - return array($this, 'form_callback'); + return array( $this, 'form_callback' ); } /** @@ -316,7 +322,7 @@ */ public function is_preview() { global $wp_customize; - return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ; + return ( isset( $wp_customize ) && $wp_customize->is_preview() ); } /** @@ -392,37 +398,40 @@ $all_instances = $this->get_settings(); // We need to update the data - if ( $this->updated ) + if ( $this->updated ) { return; + } - if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { + if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { // Delete the settings for this instance of the widget - if ( isset($_POST['the-widget-id']) ) + if ( isset( $_POST['the-widget-id'] ) ) { $del_id = $_POST['the-widget-id']; - else + } else { return; + } - if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) { - $number = $wp_registered_widgets[$del_id]['params'][0]['number']; + if ( isset( $wp_registered_widgets[ $del_id ]['params'][0]['number'] ) ) { + $number = $wp_registered_widgets[ $del_id ]['params'][0]['number']; - if ( $this->id_base . '-' . $number == $del_id ) - unset($all_instances[$number]); + if ( $this->id_base . '-' . $number == $del_id ) { + unset( $all_instances[ $number ] ); + } } } else { - if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) { - $settings = $_POST['widget-' . $this->id_base]; - } elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) { - $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number']; + if ( isset( $_POST[ 'widget-' . $this->id_base ] ) && is_array( $_POST[ 'widget-' . $this->id_base ] ) ) { + $settings = $_POST[ 'widget-' . $this->id_base ]; + } elseif ( isset( $_POST['id_base'] ) && $_POST['id_base'] == $this->id_base ) { + $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number']; $settings = array( $num => array() ); } else { return; } foreach ( $settings as $number => $new_instance ) { - $new_instance = stripslashes_deep($new_instance); - $this->_set($number); + $new_instance = stripslashes_deep( $new_instance ); + $this->_set( $number ); - $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array(); + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array(); $was_cache_addition_suspended = wp_suspend_cache_addition(); if ( $this->is_preview() && ! $was_cache_addition_suspended ) { @@ -450,14 +459,14 @@ */ $instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this ); if ( false !== $instance ) { - $all_instances[$number] = $instance; + $all_instances[ $number ] = $instance; } break; // run only once } } - $this->save_settings($all_instances); + $this->save_settings( $all_instances ); $this->updated = true; } @@ -475,18 +484,19 @@ * @return string|null */ public function form_callback( $widget_args = 1 ) { - if ( is_numeric($widget_args) ) + if ( is_numeric( $widget_args ) ) { $widget_args = array( 'number' => $widget_args ); + } - $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); + $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); $all_instances = $this->get_settings(); if ( -1 == $widget_args['number'] ) { // We echo out a form where 'number' can be set later - $this->_set('__i__'); + $this->_set( '__i__' ); $instance = array(); } else { - $this->_set($widget_args['number']); + $this->_set( $widget_args['number'] ); $instance = $all_instances[ $widget_args['number'] ]; } @@ -504,7 +514,7 @@ $return = null; if ( false !== $instance ) { - $return = $this->form($instance); + $return = $this->form( $instance ); /** * Fires at the end of the widget control form. @@ -536,9 +546,9 @@ * compared to other instances of the same class. Default -1. */ public function _register_one( $number = -1 ) { - wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); + wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); - _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); + _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); } /**