From f443de2bbac011158193c05b13c83c201e4e8acd Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Fri, 16 Oct 2026 12:03:01 +0100 Subject: [PATCH 1/2] Keep site flag defaults and saved state across requests Site\handle() read the option with get_option( $key, true, '' ). get_option() takes two arguments, so the third was ignored and the default was true. With nothing stored, the code then compared true with 'active' and set the flag inactive, which overrode the default of any site flag registered as active. Site\save() passed a PHP bool to update_option(). WordPress stores true as '1', which handle() never matches against 'active', and stores false as '' (or skips the write when no row exists), which handle() treats as unset. The sanitize callback registered in site-metabox.php hid this on admin-ajax.php only, because it runs once admin_init has fired. Code that sets the flag on the front end or in WP-CLI wrote the bare bool and lost the state. Read with '' as the default and write 'active' or 'inactive', as User\save() does, so the round trip no longer depends on the sanitize filter. Co-Authored-By: Claude --- inc/site.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/site.php b/inc/site.php index f57aa87..16a11c1 100644 --- a/inc/site.php +++ b/inc/site.php @@ -40,7 +40,7 @@ function handle( Flag $flag ) { } // Get site preference, if any, to set current status of the flag. - $value = get_option( $flag->get_storage_key(), true, '' ); + $value = get_option( $flag->get_storage_key(), '' ); if ( $value ) { $flag->set( 'active', $value === 'active' ); } @@ -58,5 +58,5 @@ function handle( Flag $flag ) { * @return bool|int */ function save( bool $value, Flag $flag ) { - return update_option( $flag->get_storage_key(), $value ); + return update_option( $flag->get_storage_key(), $value ? 'active' : 'inactive' ); } From 4dff7e48572bcac3dfd58292da0822d514860bbf Mon Sep 17 00:00:00 2001 From: Sander van Dragt Date: Fri, 16 Oct 2026 12:04:05 +0100 Subject: [PATCH 2/2] Show the resolved state of site flags in Settings > General render() read the option with the same get_option( $key, true, '' ) call as Site\handle(), so a site flag that is active by default and has nothing stored showed as unchecked. Saving the General settings page for any reason then stored 'inactive' and switched the flag off. Site\handle() has already applied any stored value to the flag on init, so render the flag's own active state. Co-Authored-By: Claude --- inc/site-metabox.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/site-metabox.php b/inc/site-metabox.php index 38db57c..2b04b7c 100644 --- a/inc/site-metabox.php +++ b/inc/site-metabox.php @@ -58,7 +58,7 @@ function render() { $values = []; foreach ( $flags as $flag ) { /* @var \HumanMade\Flags\Flag $flag */ - $values[ $flag->id ] = get_option( $flag->get_storage_key(), true, '' ) === 'active'; + $values[ $flag->id ] = (bool) $flag->active; } ?>