From ffbde71040fdace58ef60dfbb9377c16a315a6ac Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 19 Oct 2020 22:43:21 +0000 Subject: [PATCH] Themes: Add a return value to `set_theme_mod()` to allow for error handling. Props latifi, hareesh-pillai. Fixes #51296. git-svn-id: https://develop.svn.wordpress.org/trunk@49214 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/theme.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index a6ecad3ffe..8e8a5779d4 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -1038,9 +1038,11 @@ function get_theme_mod( $name, $default = false ) { * Updates theme modification value for the current theme. * * @since 2.1.0 + * @since 5.6.0 A return value was added. * * @param string $name Theme modification name. * @param mixed $value Theme modification value. + * @return bool True if the value was updated, false otherwise. */ function set_theme_mod( $name, $value ) { $mods = get_theme_mods(); @@ -1061,7 +1063,8 @@ function set_theme_mod( $name, $value ) { $mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value ); $theme = get_option( 'stylesheet' ); - update_option( "theme_mods_$theme", $mods ); + + return update_option( "theme_mods_$theme", $mods ); } /** @@ -1087,7 +1090,9 @@ function remove_theme_mod( $name ) { remove_theme_mods(); return; } + $theme = get_option( 'stylesheet' ); + update_option( "theme_mods_$theme", $mods ); } @@ -1104,6 +1109,7 @@ function remove_theme_mods() { if ( false === $theme_name ) { $theme_name = wp_get_theme()->get( 'Name' ); } + delete_option( 'mods_' . $theme_name ); }