public function action_set_user_role($user_id, $role, $old_roles)
{
// Avoid recursing, while we're reverting
if ($this->reverting_role) {
return;
}
$user = new WP_User($user_id);
// Try to make the conditional checks clearer
$becoming_support = WPCOM_VIP_Support_Role::VIP_SUPPORT_ROLE == $role;
$valid_and_verified_email = $this->is_a8c_email($user->user_email) && $this->user_has_verified_email($user_id);
if ($becoming_support && !$valid_and_verified_email) {
$this->reverting_role = true;
// @FIXME This could be expressed more simply, probably :|
if (!is_array($old_roles) || !isset($old_roles[0])) {
if ($this->is_a8c_email($user->user_email)) {
$revert_role_to = WPCOM_VIP_Support_Role::VIP_SUPPORT_INACTIVE_ROLE;
} else {
$revert_role_to = 'subscriber';
}
} else {
$revert_role_to = $old_roles[0];
}
$this->demote_user_from_vip_support_to($user->ID, $revert_role_to);
if ($this->is_a8c_email($user->user_email) && !$this->user_has_verified_email($user_id)) {
$this->message_replace = self::MSG_BLOCK_UPGRADE_VERIFY_EMAIL;
$this->send_verification_email($user_id);
} else {
$this->message_replace = self::MSG_BLOCK_UPGRADE_NON_A11N;
}
$this->reverting_role = false;
}
}