aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggPlugin.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-08 20:30:06 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2011-02-08 20:30:06 +0000
commitcf13bfcc6ca27f5a73de1542e17cdba3e512b615 (patch)
tree902ba1602850a5cc0da8cbbaee51cc8ef6d1aa9b /engine/classes/ElggPlugin.php
parentccb6d625239b59b283b4d3fc00da704ab743d74c (diff)
downloadelgg-cf13bfcc6ca27f5a73de1542e17cdba3e512b615.tar.gz
elgg-cf13bfcc6ca27f5a73de1542e17cdba3e512b615.tar.bz2
Fixes #2869: User settings for plugins work again.
git-svn-id: http://code.elgg.org/elgg/trunk@8080 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/classes/ElggPlugin.php')
-rw-r--r--engine/classes/ElggPlugin.php77
1 files changed, 67 insertions, 10 deletions
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php
index b82e92fba..ec28c8064 100644
--- a/engine/classes/ElggPlugin.php
+++ b/engine/classes/ElggPlugin.php
@@ -323,42 +323,99 @@ class ElggPlugin extends ElggObject {
/**
* Returns a user's setting for this plugin
*
- * @param int $user_guid The user GUID
* @param string $name The setting name
+ * @param int $user_guid The user GUID
*
* @return mixed The setting string value or false
*/
- public function getUserSetting($user_guid, $name) {
+ public function getUserSetting($name, $user_guid = null) {
+ $user_guid = (int)$user_guid;
+
+ if ($user_guid) {
+ $user = get_entity($user_guid);
+ } else {
+ $user = elgg_get_logged_in_user_entity();
+ }
+
+ if (!($user instanceof ElggUser)) {
+ return false;
+ }
+
$name = elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
- return get_private_setting($user_guid, $name);
+ return get_private_setting($user->guid, $name);
}
/**
* Sets a user setting for a plugin
*
- * @param int $user_guid The user GUID
* @param string $name The setting name
* @param string $value The setting value
+ * @param int $user_guid The user GUID
*
* @return mixed The new setting ID or false
*/
- public function setUserSetting($user_guid, $name, $value) {
+ public function setUserSetting($name, $value, $user_guid = null) {
+ $user_guid = (int)$user_guid;
+
+ if ($user_guid) {
+ $user = get_entity($user_guid);
+ } else {
+ $user = elgg_get_logged_in_user_entity();
+ }
+
+ if (!($user instanceof ElggUser)) {
+ return false;
+ }
+
+ // Hook to validate setting
+ // note this doesn't pass the namespaced name!
+ $value = elgg_trigger_plugin_hook('plugin:usersetting', 'user', array(
+ 'user' => $user,
+ 'plugin' => $this->getID(),
+ 'name' => $name,
+ 'value' => $value
+ ), $value);
+
+ // set the namespaced name.
$name = elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
- return set_private_setting($user_guid, $name, $value);
+
+ return set_private_setting($user->guid, $name, $value);
}
/**
* Removes a user setting name and value.
*
- * @param int $user_guid The user GUID
* @param string $name The user setting name
- *
+ * @param int $user_guid The user GUID
* @return bool
*/
- public function removeUserSetting($user_guid, $name) {
+ public function removeUserSetting($name, $user_guid = null) {
+ $user_guid = (int)$user_guid;
+
+ if ($user_guid) {
+ $user = get_entity($user_guid);
+ } else {
+ $user = elgg_get_logged_in_user_entity();
+ }
+
+ if (!($user instanceof ElggUser)) {
+ return false;
+ }
+
+ // Hook to validate setting
+ // note this doesn't pass the namespaced name!
+ $value = elgg_trigger_plugin_hook('plugin:usersetting', 'user', array(
+ 'user' => $user,
+ 'plugin' => $this->getID(),
+ 'name' => $name,
+ 'value' => $value
+ ), $value);
+
+ // set the namespaced name.
$name = elgg_namespace_plugin_private_setting('user_setting', $name, $this->getID());
- return remove_private_setting($user_guid, $name);
+
+ return remove_private_setting($user->guid, $name);
}