5 use Elgg\Traits\Entity\Friends;
6 use Elgg\Traits\Entity\PluginSettings;
40 parent::initializeAttributes();
42 $this->attributes[
'type'] =
'user';
43 $this->attributes[
'subtype'] =
'user';
46 $this->attributes[
'owner_guid'] = 0;
47 $this->attributes[
'container_guid'] = 0;
53 $this->prev_last_action = 0;
54 $this->last_login = 0;
55 $this->prev_last_login = 0;
66 public function getLanguage(
string $fallback =
null): string {
67 if (!empty($this->language)) {
71 if ($fallback !==
null) {
87 _elgg_services()->logger->error(
"User entities no longer contain {$name}");
90 _elgg_services()->logger->error(
'password_hash is a readonly attribute.');
96 throw new ElggInvalidArgumentException($ex->getMessage(), $ex->getCode(), $ex);
103 throw new ElggInvalidArgumentException($ex->getMessage(), $ex->getCode(), $ex);
108 throw new ElggInvalidArgumentException(
"{$name} is supposed to be unique for ElggUser");
112 throw new ElggInvalidArgumentException(
_elgg_services()->translator->translate(
'ElggUser:Error:SetAdmin', [
'makeAdmin() / removeAdmin()']));
114 throw new ElggInvalidArgumentException(
_elgg_services()->translator->translate(
'ElggUser:Error:SetBanned', [
'ban() / unban()']));
127 public function ban(
string $reason =
''): bool {
129 if (!$this->canEdit()) {
137 $this->ban_reason = $reason;
140 $this->invalidateCache();
152 if (!$this->canEdit()) {
160 unset($this->ban_reason);
163 $this->invalidateCache();
174 return $this->banned ===
'yes';
183 return $this->admin ===
'yes';
193 if ($this->isAdmin()) {
197 if (!
_elgg_services()->events->trigger(
'make_admin',
'user', $this)) {
203 $this->invalidateCache();
215 if (!$this->isAdmin()) {
219 if (!
_elgg_services()->events->trigger(
'remove_admin',
'user', $this)) {
225 $this->invalidateCache();
236 $time = $this->getCurrentTime()->getTimestamp();
238 if ($this->last_login ==
$time) {
246 $this->last_login =
$time;
257 $time = $this->getCurrentTime()->getTimestamp();
259 if ($this->last_action ==
$time) {
280 if (!isset($this->validated)) {
284 return (
bool) $this->validated;
296 if ($status === $this->isValidated()) {
301 $this->validated = $status;
304 $this->validated_method = $method;
305 $this->validated_ts = time();
308 if (!$this->isEnabled()) {
313 _elgg_services()->events->triggerAfter(
'validate',
'user', $this);
316 unset($this->validated_ts);
317 unset($this->validated_method);
318 _elgg_services()->events->triggerAfter(
'invalidate',
'user', $this);
331 $options[
'relationship'] =
'member';
368 $object->name = $this->getDisplayName();
404 throw new ElggInvalidArgumentException(__METHOD__ .
' requires $purpose to be set to a non-empty string');
407 $this->{
"notification:{$purpose}:{$method}"} = (int) $enabled;
408 return $this->save();
427 throw new ElggInvalidArgumentException(__METHOD__ .
' requires $purpose to be set to a non-empty string');
434 if (
$purpose !==
'default' && !isset($this->{
"notification:{$purpose}:{$method}"})) {
436 $settings[$method] = (bool) $this->{
"notification:default:{$method}"};
438 $settings[$method] = (bool) $this->{
"notification:{$purpose}:{$method}"};
449 $result = parent::persistentDelete($recursive);
452 _elgg_services()->users_remember_me_cookies_table->deleteAllHashes($this);
475 $static_defaults = (array)
$plugin->getStaticConfig(
'user_settings', []);
$guid
Reset an ElggUpgrade.
if(! $user instanceof \ElggUser) if($user->email===$email) $existing_user
if(! $user||! $user->canDelete()) $name
$plugin_id
Remove all user and plugin settings from the give plugin ID.
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
if(! $annotation instanceof ElggAnnotation) $time
Plugin class containing helper functions for plugin activation/deactivation, dependency checking capa...
isAdmin()
Is this user admin?
removeAdmin()
Remove the admin flag for user.
getPluginSetting(string $plugin_id, string $name, $default=null)
Get a plugin setting.
initializeAttributes()
{Initialize the attributes array.This is vital to distinguish between metadata and base parameters....
getObjects(array $options=[])
{}
persistentDelete(bool $recursive=true)
{Permanently delete the entity from the database.If true (default) then all entities which are owned ...
__set($name, $value)
{Set an attribute or metadata value for this entity.Anything that is not an attribute is saved as met...
isValidated()
Gets the validation status of a user.
getOwnerGUID()
Get a user's owner GUID.
setNotificationSetting(string $method, bool $enabled=true, string $purpose='default')
Enable or disable a notification delivery method.
isBanned()
Is this user banned or not?
setPassword(string $password)
Set the necessary metadata to store a hash of the user's password.
makeAdmin()
Make the user an admin.
ban(string $reason='')
Ban this user.
setValidationStatus(bool $status, string $method='')
Set the validation status for a user.
setLastAction()
Sets the last action time of the given user to right now.
prepareObject(\Elgg\Export\Entity $object)
{Prepare an object copy for toObject()Object representation of the entity\Elgg\Export\Entity}
getGroups(array $options=[])
Gets the user's groups.
setLastLogin()
Sets the last logon time of the user to right now.
getNotificationSettings(string $purpose='default')
Returns users's notification settings [ 'email' => true, // enabled 'ajax' => false,...
getLanguage(string $fallback=null)
Get user language or default to site language.
Could not register a new user for whatever reason.
Exception thrown if an argument is not of the expected type.
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
const ELGG_IGNORE_ACCESS
elgg_call() flags
const ELGG_DISABLE_SYSTEM_LOG
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
if($email instanceof \Elgg\Email) $object
_elgg_services()
Get the global service provider.
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_get_user_by_username(string $username, bool $try_email=false)
Get a user by username.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
elgg_register_event_handler(string $event, string $type, callable|string $callback, int $priority=500)
Helper functions for event handling.
setMetadata(string $name, mixed $value, string $value_type='', bool $multiple=false)
Set metadata on this entity.
trait ProfileData
Adds methods to save profile data to an ElggEntity.
if(! $user||! $user->canEdit()) $password
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.