Created
June 1, 2020 11:07
-
-
Save aidnurs/6e0e00da0fbed640426795a85e6eedde to your computer and use it in GitHub Desktop.
Wordpress custom hook to change user role after expiration date
This file contains 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
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