Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@curtismchale curtismchale commented Jul 18, 2014

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

@pippinsplugins

This comment has been minimized.

Copy link
Owner Author

@pippinsplugins pippinsplugins commented Jul 28, 2014

Yep, good catch.

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