diff --git a/readme.txt b/readme.txt index 8c5bb5a..fe56b84 100644 --- a/readme.txt +++ b/readme.txt @@ -68,7 +68,7 @@ its dependencies are managed by Composer. You can install the plugin by running the following command in the root directory of your WordPress project: -```txt +``` composer require rollbar/rollbar-php-wordpress:^3.0 ``` @@ -85,7 +85,7 @@ collisions if other plugins or your project use different versions of the same d To install the plugin from wpackagist.org run the following steps command in the root directory of your WordPress project: -```txt +``` composer require wpackagist-plugin/rollbar ``` @@ -150,7 +150,10 @@ using composer. == Changelog == -= Version 3.0.0 (pending) += Version 3.1.0 (?) = +* Fixed settings values not being saved correctly when they match the default. + += Version 3.0.0 (October 17 2025) = * Fixed CSRF vulnerability. * Removed support for PHP 8.0 and below. * Updated and improved the settings page. @@ -168,10 +171,10 @@ using composer. * Added `rollbar_telemetry_custom_handlers` filter to allow custom control over what is logged in telemetry messages. * Added 'framework' details with the WordPress version to the item payload. -= Version 2.7.1 (September 13 2023) += Version 2.7.1 (September 13 2023) = * Fix issue that could lead to fatal error with some settings (https://github.com/rollbar/rollbar-php-wordpress/pull/120) -= Version 2.7.0 (September 11 2023) += Version 2.7.0 (September 11 2023) = * Updated PHP Dependencies including loading seperate dependencies for PHP7 and PHP8. (https://github.com/rollbar/rollbar-php-wordpress/pull/114) * Updated node development dependencies (https://github.com/rollbar/rollbar-php-wordpress/pull/115) diff --git a/src/Setting.php b/src/Setting.php index 8b921b0..8bf7259 100644 --- a/src/Setting.php +++ b/src/Setting.php @@ -45,6 +45,7 @@ public function __construct( readonly public array $options = [], readonly public string $section = 'rollbar_wp_advanced', readonly public array $inputArgs = [], + readonly public bool $alwaysSave = false, ) { $this->input = $this->createInput(); } diff --git a/src/Settings.php b/src/Settings.php index ef5e955..1b03f69 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -80,24 +80,28 @@ public static function settings(): array type: SettingType::Boolean, default: false, section: 'rollbar_wp_general', + alwaysSave: true, ), 'server_side_access_token' => new Setting( id: 'server_side_access_token', type: SettingType::Text, default: '', section: 'rollbar_wp_general', + alwaysSave: true, ), 'js_logging_enabled' => new Setting( id: 'js_logging_enabled', type: SettingType::Boolean, default: false, section: 'rollbar_wp_general', + alwaysSave: true, ), 'client_side_access_token' => new Setting( id: 'client_side_access_token', type: SettingType::Text, default: '', section: 'rollbar_wp_general', + alwaysSave: true, ), 'environment' => new Setting( id: 'environment', @@ -108,6 +112,7 @@ public static function settings(): array 'precendence over the default value.

', default: 'production', section: 'rollbar_wp_general', + alwaysSave: true, ), 'included_errno' => new Setting( id: 'included_errno', @@ -127,6 +132,7 @@ public static function settings(): array E_ALL => 'Absolutely everything (E_ALL)', ], section: 'rollbar_wp_general', + alwaysSave: true, ), 'agent_log_location' => new Setting( id: 'agent_log_location', @@ -450,6 +456,11 @@ public static function preUpdate(array $settings): array // Don't store default values in the database, so future updates to default values in the SDK get propagated. foreach ($settings as $setting_name => $setting_value) { + // Always save settings that are marked as alwaysSave. + $settingConfig = self::settings()[$setting_name] ?? null; + if (null !== $settingConfig && $settingConfig->alwaysSave) { + continue; + } // Loose comparison to allow for boolean values to be set to 0 or 1 and integers to be strings, which is how // they are posted via HTTP. if ($setting_value == Plugin::getInstance()->settingsInstance()->getDefaultOption($setting_name)) { @@ -501,7 +512,7 @@ public function set(string $name, mixed $value): void */ public function saveSettings(array $settings): void { - $option = get_option('rollbar_wp'); + $option = get_option(self::OPTIONS_KEY); $option = array_merge($option, $settings); @@ -509,7 +520,7 @@ public function saveSettings(array $settings): void $this->settings[$setting] = $value; } - update_option('rollbar_wp', $option); + update_option(self::OPTIONS_KEY, $option); } /** @@ -678,8 +689,8 @@ public static function normalizeSettings(array $options): array $options = array_intersect_key($options, array_flip(self::listOptions())); foreach (self::settings() as $key => $setting) { - // 'access_token' and 'enabled' are different in WordPress plugin - // look for 'server_side_access_token' and 'php_logging_enabled' above + // 'access_token' and 'enabled' are different in the WordPress plugin look for 'server_side_access_token' + // and 'php_logging_enabled' above. if (in_array($key, ['access_token', 'enabled'])) { continue; } diff --git a/tests/SettingTest.php b/tests/SettingTest.php index ca16abf..b756c44 100644 --- a/tests/SettingTest.php +++ b/tests/SettingTest.php @@ -22,6 +22,7 @@ public function testConstruct() self::assertSame('Foo', $setting->label); self::assertSame('Foo help text', $setting->helpText); self::assertSame(1, $setting->default); + self::assertSame(false, $setting->alwaysSave); } public function testGetTitle(): void diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index 2215fa7..c55ea1e 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -196,7 +196,10 @@ public static function preUpdateProvider(): array { return [ [ - 'expected' => [], + 'expected' => [ + 'php_logging_enabled' => false, + 'js_logging_enabled' => false, + ], 'data' => [ 'allow_exec' => true, 'capture_error_stacktraces' => true, @@ -210,6 +213,7 @@ public static function preUpdateProvider(): array [ 'expected' => [ 'php_logging_enabled' => true, + 'js_logging_enabled' => false, 'enabled' => true, ], 'data' => [ @@ -226,6 +230,8 @@ public static function preUpdateProvider(): array [ 'expected' => [ 'allow_exec' => false, + 'php_logging_enabled' => false, + 'js_logging_enabled' => false, ], 'data' => [ 'allow_exec' => false, @@ -240,6 +246,8 @@ public static function preUpdateProvider(): array [ 'expected' => [ 'use_error_reporting' => true, + 'php_logging_enabled' => false, + 'js_logging_enabled' => false, ], 'data' => [ 'use_error_reporting' => true,