Last active
August 29, 2015 14:03
-
-
Save pippinsplugins/c4c2142e9b3bd2db997c to your computer and use it in GitHub Desktop.
Set a member's role in Restrict Content Pro anytime their status changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pw_rcp_update_role_status_change( $new_status, $user_id ) { | |
$role = false; | |
switch( $new_status ) { | |
case 'expired' : | |
case 'pending' : | |
case 'free' : | |
case 'cancelled' : | |
$role = 'subscriber'; | |
break; | |
case 'active' : | |
// if you want, set a role here | |
break; | |
} | |
if( ! empty( $role ) ) { | |
$user = new WP_User( $user_id ); | |
$user->set_role( $role ); | |
} | |
} | |
add_action( 'rcp_set_status', 'pw_rcp_update_role_status_change', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't that switch statement be on the var
$new_status
instead of$status
?