Skip to content

Commit

Permalink
fix(plugins): issue error about saving array values at correct location
Browse files Browse the repository at this point in the history
Saving plugin (user)settings with array values causes an error. This
error is now issued at a better location, which allowed plugins to
repair the error before it occurs. Using the 'usersetting/setting'
'plugin' hook.

fixes Elgg#10974
  • Loading branch information
jeabakker committed Jun 16, 2017
1 parent 6ca9948 commit ef753eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 2 additions & 6 deletions actions/plugins/settings/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@
action("$plugin_id/settings/save");
} else {
foreach ($params as $k => $v) {
if (is_array($v)) {
elgg_log('Plugin settings cannot store arrays.', 'ERROR');
$result = false;
} else {
$result = $plugin->setSetting($k, $v);
}

$result = $plugin->setSetting($k, $v);
if (!$result) {
register_error(elgg_echo('plugins:settings:save:fail', array($plugin_name)));
forward(REFERER);
Expand Down
8 changes: 2 additions & 6 deletions actions/plugins/usersettings/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@
action("$plugin_id/usersettings/save");
} else {
foreach ($params as $k => $v) {
if (is_array($v)) {
elgg_log('Plugin user settings cannot store arrays.', 'ERROR');
$result = false;
} else {
$result = $plugin->setUserSetting($k, $v, $user->guid);
}

$result = $plugin->setUserSetting($k, $v, $user->guid);
if (!$result) {
register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name)));
forward(REFERER);
Expand Down
12 changes: 11 additions & 1 deletion engine/classes/ElggPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ public function setSetting($name, $value) {
'value' => $value,
), $value);

if (is_array($value)) {
elgg_log('Plugin settings cannot store arrays.', 'ERROR');
return false;
}

return $this->setPrivateSetting($name, $value);
}

Expand Down Expand Up @@ -535,7 +540,12 @@ public function setUserSetting($name, $value, $user_guid = 0) {
'name' => $name,
'value' => $value
), $value);


if (is_array($value)) {
elgg_log('Plugin user settings cannot store arrays.', 'ERROR');
$result = false;
}

// set the namespaced name.
$name = _elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());

Expand Down

0 comments on commit ef753eb

Please sign in to comment.