Created
September 2, 2021 17:45
-
-
Save rafiahmedd/997d7c9d002de0f5a728a2e93cdc3d64 to your computer and use it in GitHub Desktop.
Delete wp_fluentform_form_analytics data automatically in each month
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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