Last active
May 16, 2022 19:04
-
-
Save patrickposner/7c32d9986854208d4b8194fdf3642831 to your computer and use it in GitHub Desktop.
Run Simply Static Pro with WP-Cron
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
<?php | |
register_activation_hook( __FILE__, 'ssp_setup_static_export_cron' ); | |
/** | |
* Setup a cron job to run daily. | |
* | |
* @return void | |
*/ | |
function ssp_setup_static_export_cron() { | |
if ( ! wp_next_scheduled( 'ssp_static_export_cron' ) ) { | |
wp_schedule_event( time(), 'daily', 'ssp_static_export_cron' ); | |
} | |
} | |
add_action( 'ssp_static_export_cron', 'ssp_run_static_export_cron' ); | |
/** | |
* Run different types of exports via Cron event. | |
* | |
* @return void | |
*/ | |
function ssp_run_static_export_cron() { | |
// Full static export | |
$simply_static = Simply_Static\Plugin::instance(); | |
$simply_static->run_static_export(); | |
// Exporting a build with Pro | |
update_option( 'simply-static-use-build', $build_id ); | |
$simply_static = Simply_Static\Plugin::instance(); | |
$simply_static->run_static_export(); | |
// Exporting a single post/page with Pro | |
update_option( 'simply-static-use-single', $post_id ); | |
$simply_static = Simply_Static\Plugin::instance(); | |
$simply_static->run_static_export(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment