latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

hook into automatic user role change

Home Forums Community Forum hook into automatic user role change

This topic contains 4 replies, has 3 voices. Last updated by  Luca Calcinai 4 years, 6 months ago.

Topic Author Topic
Posted: Monday Jun 25th, 2012 at 8:36 am #17363
Luca Calcinai
Username: Luke

Hi,
I’m writing a plugin than sync WP users with the ones of a SMF forum, 1-way only: WP -> SMF.
I’ve written all the functions needed except for the fact that s2members automatically degrades a user’s role when his paid subscription expires or give a user a higher role when he pays the subscription fee.
Is this role change done via a call to the profile_update WP action, or does s2members implement an action of its own? In this second case, is it possible to hook into this customised function so I can just write my function and add an add_action() call at the end to run my code after s2members is done updating the user role?

thanks.

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Monday Jun 25th, 2012 at 5:44 pm #17420

Hi Luca.

I emailed Jason asking him this.

Great to see someone integrating with SMF! Love it. :) http://www.simplemachines.org/community/index.php?action=profile;u=76

Posted: Tuesday Jun 26th, 2012 at 10:30 am #17543
Luca Calcinai
Username: Luke

Thanks! I’ll wait.

Posted: Wednesday Jun 27th, 2012 at 4:46 pm #17696
Staff Member

Thanks for the heads up on this request for support.

The core WordPress framework hook: set_user_role.
Anytime a Role changes, that hook will fire; and you’ll have the user’s ID.

/wp-includes/capabilities.php

function set_role( $role ) {
	foreach ( (array) $this->roles as $oldrole )
		unset( $this->caps[$oldrole] );

	if ( 1 == count( $this->roles ) && $role == $this->roles[0] )
		return;

	if ( !empty( $role ) ) {
		$this->caps[$role] = true;
		$this->roles = array( $role => true );
	} else {
		$this->roles = false;
	}
	update_user_meta( $this->ID, $this->cap_key, $this->caps );
	$this->get_role_caps();
	$this->update_user_level_from_caps();
	do_action( 'set_user_role', $this->ID, $role );
}
Posted: Thursday Jun 28th, 2012 at 6:50 am #17741
Luca Calcinai
Username: Luke

Thank you! This is exactly what I was looking for.

Viewing 4 replies - 1 through 4 (of 4 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.