Skip to content

Instantly share code, notes, and snippets.

@aidnurs
Created June 1, 2020 11:07
Show Gist options
  • Save aidnurs/6e0e00da0fbed640426795a85e6eedde to your computer and use it in GitHub Desktop.
Save aidnurs/6e0e00da0fbed640426795a85e6eedde to your computer and use it in GitHub Desktop.
Wordpress custom hook to change user role after expiration date
function change_expired_users_role()
{
$args = array(
'role' => 'member_trial',
);
$users = get_users($args);
if (empty($users))
return;
$expiration = 60 * 60 * 24 * 14;
foreach ($users as $user) {
if (time() > (strtotime($user->user_registered) + $expiration)) {
$user->remove_role('member_trial');
$user->add_role('subscriber');
}
}
}
add_action('custom_hook', 'change_expired_users_role');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment