save.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Saves global plugin settings.
  4. *
  5. * This action can be overriden for a specific plugin by creating the
  6. * <plugin_id>/settings/save action in that plugin.
  7. *
  8. * @uses array $_REQUEST['params'] A set of key/value pairs to save to the ElggPlugin entity
  9. * @uses int $_REQUEST['plugin_id'] The ID of the plugin
  10. *
  11. * @package Elgg.Core
  12. * @subpackage Plugins.Settings
  13. */
  14. $params = get_input('params');
  15. $plugin_id = get_input('plugin_id');
  16. $plugin = elgg_get_plugin_from_id($plugin_id);
  17. if (!($plugin instanceof ElggPlugin)) {
  18. register_error(elgg_echo('plugins:settings:save:fail', array($plugin_id)));
  19. forward(REFERER);
  20. }
  21. $plugin_name = $plugin->getManifest()->getName();
  22. $result = false;
  23. // allow a plugin to override the save action for their settings
  24. if (elgg_action_exists("$plugin_id/settings/save")) {
  25. action("$plugin_id/settings/save");
  26. } else {
  27. foreach ($params as $k => $v) {
  28. $result = $plugin->setSetting($k, $v);
  29. if (!$result) {
  30. register_error(elgg_echo('plugins:settings:save:fail', array($plugin_name)));
  31. forward(REFERER);
  32. exit;
  33. }
  34. }
  35. }
  36. system_message(elgg_echo('plugins:settings:save:ok', array($plugin_name)));
  37. forward(REFERER);