Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rafiahmedd/997d7c9d002de0f5a728a2e93cdc3d64 to your computer and use it in GitHub Desktop.
Save rafiahmedd/997d7c9d002de0f5a728a2e93cdc3d64 to your computer and use it in GitHub Desktop.
Delete wp_fluentform_form_analytics data automatically in each month
/**
* Use this code only inside the functions.php file
* this method will register event to WordPress init
*/
add_action( 'init', 'registerCronForAutoDeleteDbTable');
function registerCronForAutoDeleteDbTable(){
if( !wp_next_scheduled( 'delete_data_after_month' ) ) {
// schedule an event
wp_schedule_event( time(), 'monthly', 'delete_data_after_month' );
}
}
add_action( 'delete_data_after_month', 'deleteFFAnalyticsData' );
/**
* this method will call when cron executes
*/
function deleteFFAnalyticsData() {
wpFluent()->table('fluentform_form_analytics')
->delete();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment