From 6505332707873aac0792be65f00e495ad2950ca5 Mon Sep 17 00:00:00 2001 From: David Stone Date: Thu, 30 Jul 2026 21:14:48 -0600 Subject: [PATCH] fix(setup): initialize newsletter opt-in default --- inc/class-newsletter.php | 8 ++++---- inc/class-settings.php | 1 + tests/WP_Ultimo/Settings_Test.php | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/inc/class-newsletter.php b/inc/class-newsletter.php index 846882b49..eae344f81 100644 --- a/inc/class-newsletter.php +++ b/inc/class-newsletter.php @@ -45,10 +45,10 @@ public function add_settings(): void { 'general', self::SETTING_FIELD_SLUG, [ - 'title' => __('Signup for Ultimate Multisite Newsletter', 'ultimate-multisite'), - 'desc' => __('Be informed of new releases and all things related to running a WaaS Network.', 'ultimate-multisite'), - 'type' => 'toggle', - 'value' => '1', + 'title' => __('Signup for Ultimate Multisite Newsletter', 'ultimate-multisite'), + 'desc' => __('Be informed of new releases and all things related to running a WaaS Network.', 'ultimate-multisite'), + 'type' => 'toggle', + 'default' => '1', ], 45 ); diff --git a/inc/class-settings.php b/inc/class-settings.php index 601b877fe..07caa53b0 100644 --- a/inc/class-settings.php +++ b/inc/class-settings.php @@ -2149,6 +2149,7 @@ public static function get_setting_defaults(): array { 'thousand_separator' => ',', 'precision' => '2', 'enable_beta_updates' => 0, + 'newsletter_optin' => '1', // Login & Registration 'enable_registration' => 1, diff --git a/tests/WP_Ultimo/Settings_Test.php b/tests/WP_Ultimo/Settings_Test.php index c062711d1..aec02f0e6 100644 --- a/tests/WP_Ultimo/Settings_Test.php +++ b/tests/WP_Ultimo/Settings_Test.php @@ -517,6 +517,22 @@ public function test_get_all_with_defaults_includes_default_role_when_db_is_empt $this->assertEquals('administrator', $all['default_role']); } + public function test_get_all_with_defaults_includes_newsletter_optin_when_db_is_empty() { + // Simulate a fresh install with no saved settings. + wu_save_option(Settings::KEY, []); + + $ref = new \ReflectionProperty(Settings::class, 'settings'); + if (PHP_VERSION_ID < 80100) { + $ref->setAccessible(true); + } + $ref->setValue($this->settings, null); + + $all = $this->settings->get_all_with_defaults(); + + $this->assertArrayHasKey('newsletter_optin', $all); + $this->assertSame('1', $all['newsletter_optin']); + } + public function test_get_all_with_defaults_preserves_saved_values() { // When a value IS saved in the DB it must be preserved. $this->settings->save_setting('default_role', 'editor');