Working with members > Invisionize.eu - IP.Board (IPB) News
Kanał Rss Kanał Rss
Kanał Atom Kanał Atom

Working with members

wersja drukowalna wersja Microsoft Word wersja HTML

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 IPSMember.

/* Get the currently logged in member */
$member = IPSMember::loggedIn();

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

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

/* Get a guest object, or create a new member */
$member = new IPSMember;

 

Once you have an instance of IPSMember 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 = IPSMember::load( 1 );
$member->language = 2;
$member->save();

 

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 IPSMember::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:

 

There are some methods in the IPSMember class you should be familiar with.

 

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

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

czw, 01 wrzesień 2016