| @@ -41,12 +41,12 @@ | ||
| 41 | 41 | * 'title' => 'hello world' |
| 42 | 42 | * ) |
| 43 | 43 | * ) |
| 44 | 44 | * |
| 45 | - * @param string|integer $position The position of the widget in its sidebar. | |
| 46 | - * @param string $widget_id The widget's id (eg: 'text-3'). | |
| 47 | - * @param string $sidebar The widget's sidebar id (eg: 'sidebar-1'). | |
| 48 | - * @param array (Optional) $settings The settings for the widget. | |
| 45 | + * @param string|integer $position The position of the widget in its sidebar. | |
| 46 | + * @param string $widget_id The widget's id (eg: 'text-3'). | |
| 47 | + * @param string $sidebar The widget's sidebar id (eg: 'sidebar-1'). | |
| 48 | + * @param array|null $settings The settings for the widget. | |
| 49 | 49 | * |
| 50 | 50 | * @return array A normalized array representing this widget. |
| 51 | 51 | */ |
| 52 | 52 | public static function format_widget( $position, $widget_id, $sidebar, $settings = null ) { |
| @@ -361,9 +361,9 @@ | ||
| 361 | 361 | } |
| 362 | 362 | $last_position = 0; |
| 363 | 363 | foreach ( $widgets as $widget_id ) { |
| 364 | 364 | $widget = self::get_widget_by_id( $widget_id ); |
| 365 | - if ( (int) $widget['position'] > (int) $last_position ) { | |
| 365 | + if ( (int) $widget['position'] > $last_position ) { | |
| 366 | 366 | $last_position = (int) $widget['position']; |
| 367 | 367 | } |
| 368 | 368 | } |
| 369 | 369 | return $last_position; |
| @@ -382,9 +382,9 @@ | ||
| 382 | 382 | public static function set_widget_settings( $widget_id, $settings ) { |
| 383 | 383 | $widget_option_name = self::get_widget_option_name( $widget_id ); |
| 384 | 384 | $widget_settings = get_option( $widget_option_name ); |
| 385 | 385 | $instance_key = self::get_widget_instance_key( $widget_id ); |
| 386 | - $old_settings = $widget_settings[ $instance_key ]; | |
| 386 | + $old_settings = $widget_settings[ $instance_key ] ?? array(); | |
| 387 | 387 | $settings = self::sanitize_widget_settings( $widget_id, $settings, $old_settings ); |
| 388 | 388 | |
| 389 | 389 | if ( ! $settings ) { |
| 390 | 390 | return new WP_Error( 'invalid_data', 'Update failed.', 500 ); |
| @@ -575,9 +575,9 @@ | ||
| 575 | 575 | wp_get_current_user(), |
| 576 | 576 | 'wpcom_widgets_activate_widget', |
| 577 | 577 | array( |
| 578 | 578 | 'widget' => $id_base, |
| 579 | - 'settings' => wp_json_encode( $settings ), | |
| 579 | + 'settings' => wp_json_encode( $settings, JSON_UNESCAPED_SLASHES ), | |
| 580 | 580 | ) |
| 581 | 581 | ); |
| 582 | 582 | } |
| 583 | 583 | |
| @@ -642,15 +642,9 @@ | ||
| 642 | 642 | */ |
| 643 | 643 | public static function sort_widgets( $a, $b ) { |
| 644 | 644 | $a_val = (int) self::get_widget_instance_key( $a['id'] ); |
| 645 | 645 | $b_val = (int) self::get_widget_instance_key( $b['id'] ); |
| 646 | - if ( $a_val > $b_val ) { | |
| 647 | - return 1; | |
| 648 | - } | |
| 649 | - if ( $a_val < $b_val ) { | |
| 650 | - return -1; | |
| 651 | - } | |
| 652 | - return 0; | |
| 646 | + return $a_val <=> $b_val; | |
| 653 | 647 | } |
| 654 | 648 | |
| 655 | 649 | /** |
| 656 | 650 | * Retrieve a given widget object instance by ID base (eg. 'text' or 'archives'). |
| @@ -748,9 +742,9 @@ | ||
| 748 | 742 | |
| 749 | 743 | // Retrieve index of first widget instance in that sidebar. |
| 750 | 744 | $widget_key = false; |
| 751 | 745 | foreach ( $sidebars_widgets[ $sidebar ] as $widget ) { |
| 752 | - if ( strpos( $widget, $widget_id ) !== false ) { | |
| 746 | + if ( str_contains( $widget, $widget_id ) ) { | |
| 753 | 747 | $widget_key = absint( str_replace( $widget_id . '-', '', $widget ) ); |
| 754 | 748 | break; |
| 755 | 749 | } |
| 756 | 750 | } |