Customize: Ensure WP_Customize_Setting::update() and subclass overrides return consistent types.

This addresses PHPStan type check issues.

Developed in https://github.com/WordPress/wordpress-develop/pull/10952

Props westonruter, peterwilsoncc, justlevine.
See #64238, #61175.

Built from https://develop.svn.wordpress.org/trunk@61670


git-svn-id: http://core.svn.wordpress.org/trunk@60978 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter
2026-02-18 04:39:41 +00:00
parent f153b6bea0
commit 4bce2354f6
7 changed files with 29 additions and 13 deletions

View File

@@ -708,7 +708,7 @@ class WP_Customize_Setting {
*/
do_action( "customize_update_{$this->type}", $value, $this );
return has_action( "customize_update_{$this->type}" );
return (bool) has_action( "customize_update_{$this->type}" );
}
}

View File

@@ -26,10 +26,13 @@ final class WP_Customize_Background_Image_Setting extends WP_Customize_Setting {
/**
* @since 3.4.0
* @since 7.0.0 Return type updated from void to true for compatibility with base class.
*
* @param mixed $value The value to update. Not used.
* @return true Always returns true.
*/
public function update( $value ) {
remove_theme_mod( 'background_image_thumb' );
return true;
}
}

View File

@@ -22,8 +22,12 @@ class WP_Customize_Filter_Setting extends WP_Customize_Setting {
* Saves the value of the setting, using the related API.
*
* @since 3.4.0
* @since 7.0.0 Return type updated from void to true for compatibility with base class.
*
* @param mixed $value The value to update.
* @return true Always returns true.
*/
public function update( $value ) {}
public function update( $value ) {
return true;
}
}

View File

@@ -28,10 +28,12 @@ final class WP_Customize_Header_Image_Setting extends WP_Customize_Setting {
/**
* @since 3.4.0
* @since 7.0.0 Return type updated from void to true for compatibility with base class.
*
* @global Custom_Image_Header $custom_image_header
*
* @param mixed $value The value to update.
* @return true Always returns true.
*/
public function update( $value ) {
global $custom_image_header;
@@ -58,5 +60,6 @@ final class WP_Customize_Header_Image_Setting extends WP_Customize_Setting {
} else {
$custom_image_header->set_header_image( $value );
}
return true;
}
}

View File

@@ -759,17 +759,18 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
* To delete a menu, the client can send false as the value.
*
* @since 4.3.0
* @since 7.0.0 Return type updated from null|void to bool for compatibility with base class.
*
* @see wp_update_nav_menu_item()
*
* @param array|false $value The menu item array to update. If false, then the menu item will be deleted
* entirely. See WP_Customize_Nav_Menu_Item_Setting::$default for what the value
* should consist of.
* @return null|void
* @return bool Whether updated.
*/
protected function update( $value ) {
if ( $this->is_updated ) {
return;
return ( 'error' !== $this->update_status );
}
$this->is_updated = true;
@@ -806,19 +807,19 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
if ( ! $nav_menu_setting || ! ( $nav_menu_setting instanceof WP_Customize_Nav_Menu_Setting ) ) {
$this->update_status = 'error';
$this->update_error = new WP_Error( 'unexpected_nav_menu_setting' );
return;
return false;
}
if ( false === $nav_menu_setting->save() ) {
$this->update_status = 'error';
$this->update_error = new WP_Error( 'nav_menu_setting_failure' );
return;
return false;
}
if ( (int) $value['nav_menu_term_id'] !== $nav_menu_setting->previous_term_id ) {
$this->update_status = 'error';
$this->update_error = new WP_Error( 'unexpected_previous_term_id' );
return;
return false;
}
$value['nav_menu_term_id'] = $nav_menu_setting->term_id;
@@ -832,19 +833,19 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
if ( ! $parent_nav_menu_item_setting || ! ( $parent_nav_menu_item_setting instanceof WP_Customize_Nav_Menu_Item_Setting ) ) {
$this->update_status = 'error';
$this->update_error = new WP_Error( 'unexpected_nav_menu_item_setting' );
return;
return false;
}
if ( false === $parent_nav_menu_item_setting->save() ) {
$this->update_status = 'error';
$this->update_error = new WP_Error( 'nav_menu_item_setting_failure' );
return;
return false;
}
if ( (int) $value['menu_item_parent'] !== $parent_nav_menu_item_setting->previous_post_id ) {
$this->update_status = 'error';
$this->update_error = new WP_Error( 'unexpected_previous_post_id' );
return;
return false;
}
$value['menu_item_parent'] = $parent_nav_menu_item_setting->post_id;
@@ -886,6 +887,8 @@ class WP_Customize_Nav_Menu_Item_Setting extends WP_Customize_Setting {
}
}
}
return ( 'error' !== $this->update_status );
}
/**

View File

@@ -466,6 +466,7 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
* To delete a menu, the client can send false as the value.
*
* @since 4.3.0
* @since 7.0.0 Return type updated from null|void to bool for compatibility with base class.
*
* @see wp_update_nav_menu_object()
*
@@ -478,11 +479,11 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
* @type int $parent The id of the parent term. Default 0.
* @type bool $auto_add Whether pages will auto_add to this menu. Default false.
* }
* @return null|void
* @return bool Whether updated.
*/
protected function update( $value ) {
if ( $this->is_updated ) {
return;
return ( 'error' !== $this->update_status );
}
$this->is_updated = true;
@@ -582,6 +583,8 @@ class WP_Customize_Nav_Menu_Setting extends WP_Customize_Setting {
$this->_widget_nav_menu_updates[ $nav_menu_widget_setting->id ] = $updated_widget_instance;
}
}
return ( 'error' !== $this->update_status );
}
/**

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-alpha-61669';
$wp_version = '7.0-alpha-61670';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.