Sync user meta fields using Wp cron job

If you want to remove the functionality of the original plugin, try adding this to your theme’s functions.php file

function add_thirty_day_cron($schedules) {
  $schedules['thirtydays'] = array( 'interval' => 30 * DAY_IN_SECONDS, 'display' => __( 'Every 30 days') );
  return $schedules;
}
add_filter('cron_schedules','add_thirty_day_cron');//adds 30 day interval
add_action('do_meta_sync', 'my_meta_sync');//hook for cron
function my_meta_sync() {
  if (function_exists('msf_action_callback')) msf_action_callback();
}
function modify_syncfields_sync() {
  remove_action('edit_user_profile_update', 'msf_action_callback');
  remove_action('profile_update', 'msf_action_callback');
}
add_action('plugins_loaded','modify_syncfields_sync');//removes plugin actions
add_action('wp_loaded','add_my_sync_cron');//schedules cron
function add_my_sync_cron() {
  if (!wp_next_scheduled('do_meta_sync')) wp_schedule_event(time(), 'thirtydays', 'do_meta_sync');
}

If you don’t want to use the plugin anymore, here are two options. The first will run every thirty days starting on the first day of next month.

function my_meta_sync() {
    $users = get_users();
    foreach ($users as $user) {
        $meta = get_user_meta( $user->ID );
        if ($meta['firstname'][0] != $meta['billing_firstname'][0]) update_user_meta( $user->ID, $meta['billing_firstname'][0], $meta['firstname'][0] );
    }
}
//use this code for 30 day intervals
add_filter('cron_schedules','add_thirty_day_cron');//adds 30 day interval
function add_thirty_day_cron($schedules) {
  $schedules['thirtydays'] = array( 'interval' => 30 * DAY_IN_SECONDS, 'display' => __( 'Every 30 days') );
  return $schedules;
}
add_action('do_thirty_day_meta_sync', 'my_meta_sync');//hook for cron
add_action('wp_loaded','add_my_thirty_day_sync_cron');//schedules cron
function add_my_thirty_day_sync_cron() {
  if (!wp_next_scheduled('do_thirty_day_meta_sync')) {
      $timestamp = date_create('first day of next month')->format('U');
      wp_schedule_event($timestamp, 'thirtydays', 'do_thirty_day_meta_sync');

  }
}
//end

To run the sync on the first day of the month, you’ll need to schedule a daily cron.

function my_meta_sync() {
    $users = get_users();
    foreach ($users as $user) {
        $meta = get_user_meta( $user->ID );
        if ($meta['firstname'][0] != $meta['billing_firstname'][0]) update_user_meta( $user->ID, $meta['billing_firstname'][0], $meta['firstname'][0] );
    }
}
function my_monthly_meta_sync() {
    if (date('d') == '01') my_meta_sync();
}
function add_daily_tasks() {
    if (!wp_next_scheduled('my_daily_cron')) wp_schedule_event(time(), 'daily', 'my_daily_cron');
}
add_action('wp_loaded','add_daily_tasks');//schedules cron
function my_daily_tasks(){
    my_monthly_meta_sync();
}
add_action('my_daily_cron','my_daily_tasks');
//end

I created a generic daily cron task because once you get used to running cron style tasks, especially daily ones, you’ll want to do more. Going forward, all you have to do is call your new functions inside the my_daily_tasks() and you won’t have to create more cron hooks as long as they are independent of time of day.

I would also recommend installing a cron plugin (I use WP Crontrol) to see what’s going on in your cron jobs. You can also create/delete crons using the plugin rather than using wp_schedule_event() like I did in the hard code.