Created
December 19, 2023 10:06
-
-
Save nextab/afe7033367253fec0ee0c402ad844c13 to your computer and use it in GitHub Desktop.
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
// goes into constructor: | |
register_activation_hook(__FILE__, array($this, 'schedule_cache_update')); | |
register_deactivation_hook(__FILE__, array($this, 'clear_scheduled_event')); | |
add_action('proven_expert_update_cache_event', array($this, 'my_callback_function')); | |
// register / unregister hook on activation / deactivation of plugin | |
// -> proven_expert_update_cache_event wird als neue action im System registriert UND an einen cronjob gehängt! | |
public function schedule_cache_update() { | |
if (!wp_next_scheduled('proven_expert_update_cache_event')) { | |
wp_schedule_event(time(), 'hourly', 'proven_expert_update_cache_event'); | |
} | |
} | |
public function clear_scheduled_event() { | |
$timestamp = wp_next_scheduled('proven_expert_update_cache_event'); | |
wp_unschedule_event($timestamp, 'proven_expert_update_cache_event'); | |
} | |
// last step: implement my_callback_function that will run whenever cron job gets called | |
function my_callback_function() { | |
echo 'ABC'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment