Skip to content

Commit c5b8be5

Browse files
authored
Merge pull request #138 from rollbar/fixed/issue-137-cannot-save-production-environment
Fixed/issue 137 cannot save production environment
2 parents 6c3afbc + 5ac3b69 commit c5b8be5

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

readme.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ its dependencies are managed by Composer.
6868

6969
You can install the plugin by running the following command in the root directory of your WordPress project:
7070

71-
```txt
71+
```
7272
composer require rollbar/rollbar-php-wordpress:^3.0
7373
```
7474

@@ -85,7 +85,7 @@ collisions if other plugins or your project use different versions of the same d
8585
To install the plugin from wpackagist.org run the following steps command in the root directory of your WordPress
8686
project:
8787

88-
```txt
88+
```
8989
composer require wpackagist-plugin/rollbar
9090
```
9191

@@ -150,7 +150,10 @@ using composer.
150150

151151
== Changelog ==
152152

153-
= Version 3.0.0 (pending)
153+
= Version 3.1.0 (?) =
154+
* Fixed settings values not being saved correctly when they match the default.
155+
156+
= Version 3.0.0 (October 17 2025) =
154157
* Fixed CSRF vulnerability.
155158
* Removed support for PHP 8.0 and below.
156159
* Updated and improved the settings page.
@@ -168,10 +171,10 @@ using composer.
168171
* Added `rollbar_telemetry_custom_handlers` filter to allow custom control over what is logged in telemetry messages.
169172
* Added 'framework' details with the WordPress version to the item payload.
170173

171-
= Version 2.7.1 (September 13 2023)
174+
= Version 2.7.1 (September 13 2023) =
172175
* Fix issue that could lead to fatal error with some settings (https://github.com/rollbar/rollbar-php-wordpress/pull/120)
173176

174-
= Version 2.7.0 (September 11 2023)
177+
= Version 2.7.0 (September 11 2023) =
175178
* Updated PHP Dependencies including loading seperate dependencies for PHP7 and PHP8. (https://github.com/rollbar/rollbar-php-wordpress/pull/114)
176179
* Updated node development dependencies (https://github.com/rollbar/rollbar-php-wordpress/pull/115)
177180

src/Setting.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function __construct(
4545
readonly public array $options = [],
4646
readonly public string $section = 'rollbar_wp_advanced',
4747
readonly public array $inputArgs = [],
48+
readonly public bool $alwaysSave = false,
4849
) {
4950
$this->input = $this->createInput();
5051
}

src/Settings.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,28 @@ public static function settings(): array
8080
type: SettingType::Boolean,
8181
default: false,
8282
section: 'rollbar_wp_general',
83+
alwaysSave: true,
8384
),
8485
'server_side_access_token' => new Setting(
8586
id: 'server_side_access_token',
8687
type: SettingType::Text,
8788
default: '',
8889
section: 'rollbar_wp_general',
90+
alwaysSave: true,
8991
),
9092
'js_logging_enabled' => new Setting(
9193
id: 'js_logging_enabled',
9294
type: SettingType::Boolean,
9395
default: false,
9496
section: 'rollbar_wp_general',
97+
alwaysSave: true,
9598
),
9699
'client_side_access_token' => new Setting(
97100
id: 'client_side_access_token',
98101
type: SettingType::Text,
99102
default: '',
100103
section: 'rollbar_wp_general',
104+
alwaysSave: true,
101105
),
102106
'environment' => new Setting(
103107
id: 'environment',
@@ -108,6 +112,7 @@ public static function settings(): array
108112
'precendence over the default value.</strong></p>',
109113
default: 'production',
110114
section: 'rollbar_wp_general',
115+
alwaysSave: true,
111116
),
112117
'included_errno' => new Setting(
113118
id: 'included_errno',
@@ -127,6 +132,7 @@ public static function settings(): array
127132
E_ALL => 'Absolutely everything (E_ALL)',
128133
],
129134
section: 'rollbar_wp_general',
135+
alwaysSave: true,
130136
),
131137
'agent_log_location' => new Setting(
132138
id: 'agent_log_location',
@@ -450,6 +456,11 @@ public static function preUpdate(array $settings): array
450456

451457
// Don't store default values in the database, so future updates to default values in the SDK get propagated.
452458
foreach ($settings as $setting_name => $setting_value) {
459+
// Always save settings that are marked as alwaysSave.
460+
$settingConfig = self::settings()[$setting_name] ?? null;
461+
if (null !== $settingConfig && $settingConfig->alwaysSave) {
462+
continue;
463+
}
453464
// Loose comparison to allow for boolean values to be set to 0 or 1 and integers to be strings, which is how
454465
// they are posted via HTTP.
455466
if ($setting_value == Plugin::getInstance()->settingsInstance()->getDefaultOption($setting_name)) {
@@ -501,15 +512,15 @@ public function set(string $name, mixed $value): void
501512
*/
502513
public function saveSettings(array $settings): void
503514
{
504-
$option = get_option('rollbar_wp');
515+
$option = get_option(self::OPTIONS_KEY);
505516

506517
$option = array_merge($option, $settings);
507518

508519
foreach ($settings as $setting => $value) {
509520
$this->settings[$setting] = $value;
510521
}
511522

512-
update_option('rollbar_wp', $option);
523+
update_option(self::OPTIONS_KEY, $option);
513524
}
514525

515526
/**
@@ -678,8 +689,8 @@ public static function normalizeSettings(array $options): array
678689
$options = array_intersect_key($options, array_flip(self::listOptions()));
679690

680691
foreach (self::settings() as $key => $setting) {
681-
// 'access_token' and 'enabled' are different in WordPress plugin
682-
// look for 'server_side_access_token' and 'php_logging_enabled' above
692+
// 'access_token' and 'enabled' are different in the WordPress plugin look for 'server_side_access_token'
693+
// and 'php_logging_enabled' above.
683694
if (in_array($key, ['access_token', 'enabled'])) {
684695
continue;
685696
}

tests/SettingTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function testConstruct()
2222
self::assertSame('Foo', $setting->label);
2323
self::assertSame('Foo help text', $setting->helpText);
2424
self::assertSame(1, $setting->default);
25+
self::assertSame(false, $setting->alwaysSave);
2526
}
2627

2728
public function testGetTitle(): void

tests/SettingsTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ public static function preUpdateProvider(): array
196196
{
197197
return [
198198
[
199-
'expected' => [],
199+
'expected' => [
200+
'php_logging_enabled' => false,
201+
'js_logging_enabled' => false,
202+
],
200203
'data' => [
201204
'allow_exec' => true,
202205
'capture_error_stacktraces' => true,
@@ -210,6 +213,7 @@ public static function preUpdateProvider(): array
210213
[
211214
'expected' => [
212215
'php_logging_enabled' => true,
216+
'js_logging_enabled' => false,
213217
'enabled' => true,
214218
],
215219
'data' => [
@@ -226,6 +230,8 @@ public static function preUpdateProvider(): array
226230
[
227231
'expected' => [
228232
'allow_exec' => false,
233+
'php_logging_enabled' => false,
234+
'js_logging_enabled' => false,
229235
],
230236
'data' => [
231237
'allow_exec' => false,
@@ -240,6 +246,8 @@ public static function preUpdateProvider(): array
240246
[
241247
'expected' => [
242248
'use_error_reporting' => true,
249+
'php_logging_enabled' => false,
250+
'js_logging_enabled' => false,
243251
],
244252
'data' => [
245253
'use_error_reporting' => true,

0 commit comments

Comments
 (0)