hey, why don’t you reply me?
You can use the API like this:
rua_get_user($user_id)->remove_level($level_id)
In your snippet, the levels will always be removed since $date_to_compare will always be higher than $current_date. I hope this helps!
RUA is developed in my spare time, and I try my best to answer support questions in a timely manner. Unfortunately I cannot help with specific customizations, but I can give general answers about API usage.
I wrote it in foreach loop but does not work
Can you show me a bigger snippet of what your code looks like? Especially what is $user_levels and what is $user?
I made it this is my function. If you want, you can add to your plugin but this function have to work with cron.
function my_cronjob_action () {
$current_date = date("Y-m-d");
$users = get_users();
foreach( $users as $user){
$date_to_compare = get_the_author_meta( 'year_of_birth', $user->ID );
if (strtotime($current_date) > strtotime($date_to_compare) ) {
$user_levels = rua_get_user($user)->get_level_ids(false, false, true);
foreach ($user_levels as $level) {
rua_get_user($user)->remove_level($level);
}
}
echo $date_to_compare;
}
} add_action('my_cronjob_action', 'my_cronjob_action');
you will give a date to a user, then the date which you give to user bigger than today, the levels will remove from user
-
This reply was modified 5 years, 9 months ago by
freedom667.
-
This reply was modified 5 years, 9 months ago by
freedom667.
-
This reply was modified 5 years, 9 months ago by
freedom667.