Skip to content

Instantly share code, notes, and snippets.

@NigelRodgers
Last active February 4, 2023 21:54
Show Gist options
  • Save NigelRodgers/7dc9a8ef7c3e16eec65b2f65a93bab35 to your computer and use it in GitHub Desktop.
Save NigelRodgers/7dc9a8ef7c3e16eec65b2f65a93bab35 to your computer and use it in GitHub Desktop.
Reschedule Data Fetch From 7 days to 3 days
function reschedule_analytics_fetch_nr() {
if ( true === as_has_scheduled_action( 'rank_math/analytics/data_fetch' ) ) {
$data_fetch = as_get_scheduled_actions( ['hook' => 'rank_math/analytics/data_fetch', 'status' => 'pending'] );
if(259200 !== $data_fetch->interval_in_seconds){
as_unschedule_action( 'rank_math/analytics/data_fetch' );
}
as_schedule_recurring_action( strtotime( 'tomorrow' ), 3*DAY_IN_SECONDS, 'rank_math/analytics/data_fetch', array(), "rank-math" );
}
}
add_action( 'init', 'reschedule_analytics_fetch_nr' );
@NigelRodgers
Copy link
Author

Instructions:

  1. Verify that the site has PRO installed
  2. Open pending scheduled actions and check is schedule is for every 7 days
  3. Add the snippet above to theme functions.php and save
  4. Refresh pending scheduled actions page, data fetch should now be every 3 days.
  5. Delete the snippet from functions.php

@NigelRodgers
Copy link
Author

NigelRodgers commented Jan 27, 2023

//If data fetch function is missing create a new one
function reschedule_analytics_fetch_nr() { if( ! get_option('run_create_vip_order_once') ) { as_schedule_recurring_action( strtotime( 'tomorrow' ), 3*DAY_IN_SECONDS, 'rank_math/analytics/data_fetch', array(), "rank-math" ); update_option( 'run_create_vip_order_once', true ); } } add_action( 'init', 'reschedule_analytics_fetch_nr' );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment