Jump to content

[Dokumentacja IPS4] Working with members

Recommended Posts

If you are developing for 4.0 you will almost certainly need to interact with member accounts at some point.  Thankfully, doing so is easy in 4.0.

The primary member class in 4.0 is \IPS\Member.

/* Get the currently logged in member */
$member = \IPS\Member::loggedIn();

/* Load a specific member by ID */
$member = \IPS\Member::load( 1 );

/* Load a specific member by email address */
$member = \IPS\Member::load( 'john@doe.com', 'email' );

/* Get a guest object, or create a new member */
$member = new \IPS\Member;


Once you have an instance of \IPS\Member to work with, you can adjust values for that member account by simply setting properties on the object that correspond to the columns in the core_members database table.  For instance, to change a member's language selection you can do the following


/* Get the member reference */
$member = \IPS\Member::load( 1 );
$member->language = 2;


You need to call the save() method after changing a value in order for it to be saved to the database, otherwise the change will only persist throughout the current page view (or until save() is called at some later point, especially if working with \IPS\Member::loggedIn()).  If you are working with a guest object and you call save() against the object, a new member record will be stored to the database (i.e. this is how you create a new member).

There are some getters and setters defined in this class to facilitate actions that need to occur.  For instance, when setting the member's name, the member's seo name is automatically updated and the display name change log is automatically accounted for.

Some special properties made available via getters:

  • $member->group: This is a special getter (this is a property, not a method) that will return the member's group data.  This method will automatically merge permissions from the primary group and one or more secondary groups, giving the member the best possible permissions based on their group memberships.
  • $member->groupName: This will return the user's group name, formatted based on the ACP group configuration.
  • $member->groups: This will return an array of all group IDs the member belongs to
  • $member->real_name: This will return the member's name or an empty string for a guest, instead of returning the language string for 'guest' if the user is actually a guest.
  • $member->birthday: This will return the member's localized birthday, taking into account the fact that providing a birth year is optional.
  • $member->photo: This property returns the member's photo as an \IPS\Url object (which can be cast to a string to get the URL to the photo).  The photo is made safe for viewing in the ACP as necessary.
  • $member->rank: This method returns an array representing the title and image for the member's current 'rank' based on the ACP ranks configuration, taking into account the fact that both an uploaded image and "pip" images are supported.


There are some methods in the \IPS\Member class you should be familiar with.

  • $member->delete( $setAuthorToGuest=TRUE ): Call this method to delete a member.  The only accepted parameter indicates whether or not to set any content authored by the member to a guest account if TRUE, or to delete that content if FALSE.  Be aware that if you use any external login handlers that support deleting a member, the member will be deleted in those external databases as well.
  • $member->flagAsSpammer(): This method will flag the user account as a spammer, removing or hiding their content based upon the administrator's configuration, and report the spammer to the IPS Spam Service (if configured to do so).
  • $member->unflagAsSpammer(): This method will unflag the user account as a spammer, reporting the change in status to the IPS Spam Service if configured to do so.
  • $member->age( $date=NULL ): Return the member's age.  If an \IPS\DateTime object is supplied as the only parameter to the method, the age is calculated based on the supplied date.
  • $member->location(): Return the member's current location on the site, if they are online.
  • $member->isAdmin(): Return whether the member is an administrator or not.
  • $member->isOnline(): Return whether the member is currently online or not.
  • $member->isBanned(): Return whether the member is banned or not, including temporary bans.
  • $member->inGroup( $group, $permissionArray=FALSE ): Check whether the member belongs to a group or set of groups.  $group can be a group ID (integer), an instance of \IPS\Member\Group, or an array of group IDs or instances of \IPS\Member\Group.  If the user is a member of ANY group in the array, the method returns TRUE.  If $permissionArray is passed as TRUE, the member is checked against the member's permission array instead of the group IDs.
  • $member->language(): Returns an instance of \IPS\Lang for the member based on their preference, or based upon automatic detection/default language setting if the member has not chosen a language.  This is used to retrieve language strings, e.g. \IPS\Member::loggedIn()->language()->addToStack( 'language_string' );
  • $member->url(): Return the URL to the member's profile as an instance of \IPS\Http\Url.
  • $member->acpUrl(): Return the URL to the edit member page in the ACP as an instance of \IPS\Http\Url.
  • $member->link( $warningRef=NULL, $groupFormatting=FALSE ): Return an HTML link to the member's profile.  If $warningRef is passed as a string, this will represent the reference key for warning the member (if the user is warned).  $groupFormatting indicates whether or not to format the name displayed using the member's group formatting options set up by the administrator.
  • $member->profileFields(): Return the custom profile fields for the member as an array of profile field objects.
  • $member->contentProfileFields(): This is similar to profileFields() but instead only returns profile fields designed to display next to the user's content (e.g. in the left sidebar next to a post)
  • $member->ipAddresses(): Return the IP addresses used by the member
  • $member->markAllAsRead(): Mark the entire site as read for the member.
  • $member->markersItems( $app, $key ): Fetch the item markers for the member for the given application and key.
  • $member->markersResetTimes( $app ): Fetch the item marker reset times for the member for the given application.
  • $member->warnings( $limit, $acknowledged=NULL, $type=NULL ): Retrieve the member's warnings. Limit can be passed as an integer to limit how many are returned. If $acknowledged is NULL, all warnings are returned, or TRUE or FALSE can be passed to limit the warnings to only acknowledged or unacknowledged warnings.  If $type is passed as a string, will only pull warnings of that type.
  • $member->reputation(): This method returns the member's reputation as a language string.
  • $member->reputationImage(): This method returns the member's reputation image.
  • $member->encryptedPassword( $password ): Encrypt a plain text password for the member using the member's salt (you may wish to update the salt before calling this for a new password).
  • $member->generateSalt(): Generate a new salt for the member.
  • $member->notificationsConfiguration(): Return the member's notifications configuration.
  • $member->following( $app, $area, $id ): Determine if the member is following a specific app, area and ID combination (all values must be passed)
  • $member->acpRestrictions(): Return the member's ACP restrictions to determine which areas of the ACP the member can access.
  • $member->modPermissions(): Return the member's moderator permissions, if any.
  • $member->reportCount(): Get the number of reported content items that the member can view in the report center.
  • $member->isIgnoring( \IPS\Member $member, $type ): Determine if the member is ignoring another member.  $type must be passed and should be one of 'signatures', 'topics' or 'messages'.
  • $member->createMenu(): Fetch the member's create menu.  This is cached (and cleared automatically when needed).
  • $member->moderateNewContent(): Determine if new content created by the member should be moderated.
  • $member->coverPhoto(): Return the member's cover photo, if any.
  • $member->hasAcpRestriction( $app, $module=NULL, $key=NULL ): Determine if the member has an ACP restriction set for a given $app, $module and $key combination (only $app is required).  If the member does have the restriction set, it means they can access the given area.
  • $member->modPermission( $key=NULL ): Determine if the member has a given moderator permission available for their account (pass NULL to determine if the member has any moderator permissions available).
  • $member->canWarn( \IPS\Member $member ): Determine if the current member can warn another member.
  • $member->checkLoginKey(): Check that the member has a login key set and it is not expired.
  • $member->recountNotifications(): Recount the member's unread notifications.
  • $member->recountContent(): Recount the member's content item contributions.
  • $member->recountReputation(): Recount the member's reputation count.
  • $member->canAccessModule( $module ): $module should be an instance of \IPS\Application\Module and the method returns whether the member can access the module or not.
  • $member->merge( \IPS\Member $otherMember ): Merge the current member with another member account (note that content merging occurs in the background and may not happen immediately; additionally, the member account that will be removed will not be deleted until all content is merged, this is queued).
  • $member->checkPostsPerDay(): Check the posts per day restrictions to see if the member can visit.
  • $member->checkGroupPromotion(): Check whether the member should be promoted to another group, and do so if so.  Note that save() still needs to be called manually afterwards.
  • $member->clearCreateMenu(): Clear the cached create menu for the member.


Note that applications can define MemberSync extensions to perform specific actions at the following points:

  • onDelete: This method in a MemberSync extension is called when a member is deleted (be aware that their content may still exist in the database and be queued for deletion)
  • onCreateAccount: This is called when a new account is created.
  • onProfileUpdate: This is called when an existing account is updated

Extensions are created in the Developer Center of an application in the Admin Control Panel.

Wyświetl pełny artykuł

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Dołącz do pierwszego newslettera Invision Community

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...

Important Information

W celu świadczenie usług przez nasz Serwis na najwyższym poziomie, w ramach Serwisu wykorzystujemy pliki Cookies (tzw. ciasteczka). Korzystając ze stron Serwisu IPSBEYOND.PL bez zmiany ustawień przeglądarki będą one zapisane w pamięci urządzenia. Jeżeli nie dokonacie Państwo zmiany ustawień przeglądarki internetowej to wyrażacie zgodę na zapisywanie plików Cookies.