Elgg  Version 4.3
save.php
Go to the documentation of this file.
1 <?php
13 $params = get_input('params');
14 $plugin_id = get_input('plugin_id');
16 if (empty($plugin_id) || empty($user_guid)) {
17  return elgg_error_response(elgg_echo('error:missing_data'));
18 }
19 
22 if (!$plugin || !$user || !$user->canEdit()) {
23  return elgg_error_response(elgg_echo('plugins:usersettings:save:fail', [$plugin_id]));
24 }
25 
26 $plugin_name = $plugin->getDisplayName();
27 
28 $result = false;
29 
30 foreach ($params as $name => $value) {
31  $result = $user->setPluginSetting($plugin->getID(), $name, $value);
32  if (!$result) {
33  return elgg_error_response(elgg_echo('plugins:usersettings:save:fail', [$plugin_name]));
34  }
35 }
36 
37 return elgg_ok_response('', elgg_echo('plugins:usersettings:save:ok', [$plugin_name]));
$params
Saves global plugin settings.
Definition: save.php:13
get_user($guid)
Get a user object from a GUID.
Definition: users.php:20
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
elgg_get_plugin_from_id(string $plugin_id)
Elgg plugins library Contains functions for managing plugins.
Definition: plugins.php:15
if(!empty($_SERVER['HTTP_REFERER'])) $result
Definition: save.php:87
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
$value
Definition: generic.php:51
if(empty($plugin_id)) $plugin
Definition: save.php:20
get_input($variable, $default=null, $filter_result=true)
Parameter input functions.
Definition: input.php:20
$plugin_id
Definition: save.php:15
$user
Definition: save.php:21
elgg_error_response($message= '', $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
elgg_ok_response($content= '', $message= '', $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
if(!$plugin) $plugin_name
Definition: save.php:25
$user_guid
Definition: save.php:15
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:34