Skip to content

Commit ff7564a

Browse files
committed
Customize: Ensure WP_Customize_Setting::update() and subclass overrides return consistent types.
This addresses PHPStan type check issues. Developed in #10952 Props westonruter, peterwilsoncc, justlevine. See #64238, #61175. git-svn-id: https://develop.svn.wordpress.org/trunk@61670 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a22ff54 commit ff7564a

6 files changed

Lines changed: 28 additions & 12 deletions

src/wp-includes/class-wp-customize-setting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ protected function update( $value ) {
708708
*/
709709
do_action( "customize_update_{$this->type}", $value, $this );
710710

711-
return has_action( "customize_update_{$this->type}" );
711+
return (bool) has_action( "customize_update_{$this->type}" );
712712
}
713713
}
714714

src/wp-includes/customize/class-wp-customize-background-image-setting.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ final class WP_Customize_Background_Image_Setting extends WP_Customize_Setting {
2626

2727
/**
2828
* @since 3.4.0
29+
* @since 7.0.0 Return type updated from void to true for compatibility with base class.
2930
*
3031
* @param mixed $value The value to update. Not used.
32+
* @return true Always returns true.
3133
*/
3234
public function update( $value ) {
3335
remove_theme_mod( 'background_image_thumb' );
36+
return true;
3437
}
3538
}

src/wp-includes/customize/class-wp-customize-filter-setting.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ class WP_Customize_Filter_Setting extends WP_Customize_Setting {
2222
* Saves the value of the setting, using the related API.
2323
*
2424
* @since 3.4.0
25+
* @since 7.0.0 Return type updated from void to true for compatibility with base class.
2526
*
2627
* @param mixed $value The value to update.
28+
* @return true Always returns true.
2729
*/
28-
public function update( $value ) {}
30+
public function update( $value ) {
31+
return true;
32+
}
2933
}

src/wp-includes/customize/class-wp-customize-header-image-setting.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ final class WP_Customize_Header_Image_Setting extends WP_Customize_Setting {
2828

2929
/**
3030
* @since 3.4.0
31+
* @since 7.0.0 Return type updated from void to true for compatibility with base class.
3132
*
3233
* @global Custom_Image_Header $custom_image_header
3334
*
3435
* @param mixed $value The value to update.
36+
* @return true Always returns true.
3537
*/
3638
public function update( $value ) {
3739
global $custom_image_header;
@@ -58,5 +60,6 @@ public function update( $value ) {
5860
} else {
5961
$custom_image_header->set_header_image( $value );
6062
}
63+
return true;
6164
}
6265
}

src/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -759,17 +759,18 @@ public function sanitize( $value ) {
759759
* To delete a menu, the client can send false as the value.
760760
*
761761
* @since 4.3.0
762+
* @since 7.0.0 Return type updated from null|void to bool for compatibility with base class.
762763
*
763764
* @see wp_update_nav_menu_item()
764765
*
765766
* @param array|false $value The menu item array to update. If false, then the menu item will be deleted
766767
* entirely. See WP_Customize_Nav_Menu_Item_Setting::$default for what the value
767768
* should consist of.
768-
* @return null|void
769+
* @return bool Whether updated.
769770
*/
770771
protected function update( $value ) {
771772
if ( $this->is_updated ) {
772-
return;
773+
return ( 'error' !== $this->update_status );
773774
}
774775

775776
$this->is_updated = true;
@@ -806,19 +807,19 @@ protected function update( $value ) {
806807
if ( ! $nav_menu_setting || ! ( $nav_menu_setting instanceof WP_Customize_Nav_Menu_Setting ) ) {
807808
$this->update_status = 'error';
808809
$this->update_error = new WP_Error( 'unexpected_nav_menu_setting' );
809-
return;
810+
return false;
810811
}
811812

812813
if ( false === $nav_menu_setting->save() ) {
813814
$this->update_status = 'error';
814815
$this->update_error = new WP_Error( 'nav_menu_setting_failure' );
815-
return;
816+
return false;
816817
}
817818

818819
if ( (int) $value['nav_menu_term_id'] !== $nav_menu_setting->previous_term_id ) {
819820
$this->update_status = 'error';
820821
$this->update_error = new WP_Error( 'unexpected_previous_term_id' );
821-
return;
822+
return false;
822823
}
823824

824825
$value['nav_menu_term_id'] = $nav_menu_setting->term_id;
@@ -832,19 +833,19 @@ protected function update( $value ) {
832833
if ( ! $parent_nav_menu_item_setting || ! ( $parent_nav_menu_item_setting instanceof WP_Customize_Nav_Menu_Item_Setting ) ) {
833834
$this->update_status = 'error';
834835
$this->update_error = new WP_Error( 'unexpected_nav_menu_item_setting' );
835-
return;
836+
return false;
836837
}
837838

838839
if ( false === $parent_nav_menu_item_setting->save() ) {
839840
$this->update_status = 'error';
840841
$this->update_error = new WP_Error( 'nav_menu_item_setting_failure' );
841-
return;
842+
return false;
842843
}
843844

844845
if ( (int) $value['menu_item_parent'] !== $parent_nav_menu_item_setting->previous_post_id ) {
845846
$this->update_status = 'error';
846847
$this->update_error = new WP_Error( 'unexpected_previous_post_id' );
847-
return;
848+
return false;
848849
}
849850

850851
$value['menu_item_parent'] = $parent_nav_menu_item_setting->post_id;
@@ -886,6 +887,8 @@ protected function update( $value ) {
886887
}
887888
}
888889
}
890+
891+
return ( 'error' !== $this->update_status );
889892
}
890893

891894
/**

src/wp-includes/customize/class-wp-customize-nav-menu-setting.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ public function sanitize( $value ) {
466466
* To delete a menu, the client can send false as the value.
467467
*
468468
* @since 4.3.0
469+
* @since 7.0.0 Return type updated from null|void to bool for compatibility with base class.
469470
*
470471
* @see wp_update_nav_menu_object()
471472
*
@@ -478,11 +479,11 @@ public function sanitize( $value ) {
478479
* @type int $parent The id of the parent term. Default 0.
479480
* @type bool $auto_add Whether pages will auto_add to this menu. Default false.
480481
* }
481-
* @return null|void
482+
* @return bool Whether updated.
482483
*/
483484
protected function update( $value ) {
484485
if ( $this->is_updated ) {
485-
return;
486+
return ( 'error' !== $this->update_status );
486487
}
487488

488489
$this->is_updated = true;
@@ -582,6 +583,8 @@ protected function update( $value ) {
582583
$this->_widget_nav_menu_updates[ $nav_menu_widget_setting->id ] = $updated_widget_instance;
583584
}
584585
}
586+
587+
return ( 'error' !== $this->update_status );
585588
}
586589

587590
/**

0 commit comments

Comments
 (0)