The only way that I know of to perform an action daily (or on another regular interval) is to schedule a cron event. A sustainable way to do that is to write a little plugin that schedules/clear_schedules the cron when activated/deactivated. Here's a plugin that you could use - I tested to ensure that it was installable and registered the cron event correctly. You will need to either place this in a file (such as custom_cron_event.php) and FTP it to your /plugins folder, or place it in a file and compress (ZIP) the file to upload it to your website through the /wp-admin interface.
Sadly, you can't rely on a function that fires when user profiles are updated to retrieve user data anymore, because no profiles are being updated. Instead you'll need to get the users your self and detect if a change is required.
<?php
/*
Plugin Name: Custom Plugin
Plugin URI:
Description: Adds function on cron
Author:
Version: 1.0
*/
/*
* When this plugin is activated, schedule/clear_schedule cron
*/
register_activation_hook(__FILE__, 'activate_custom_cron');
register_deactivation_hook(__FILE__, 'deactivate_custom_cron');
function activate_custom_cron(){
wp_schedule_event( time(), 'daily', 'do_custom_cron_event');
}
function deactivate_custom_cron(){
wp_clear_scheduled_hook('do_custom_cron_event');
}
add_action( 'do_custom_cron_event', 'custom_cron_event' );
function custom_cron_event() {
/*
* This is where your function goes
*/
$current_date = date("Y-m-d");
$users = get_users();
foreach( $users as $user){
$date_to_compare = get_user_meta($user->id, 'year_of_birth');
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);
}
}
}
}
?>