Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pippinsplugins/c4c2142e9b3bd2db997c to your computer and use it in GitHub Desktop.
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
<?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 );
@curtismchale
Copy link

Shouldn't that switch statement be on the var $new_status instead of $status?

@pippinsplugins
Copy link
Author

Yep, good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment