Created
August 31, 2022 15:18
-
-
Save patrickposner/f93c6c1cacf8889bad6a6a9593cd9684 to your computer and use it in GitHub Desktop.
Simply Static - Run static exports daily 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_daily_export_cron' ); | |
/** | |
* Setup a cron job to run daily. | |
* | |
* @return void | |
*/ | |
function ssp_setup_static_daily_export_cron() { | |
if ( ! wp_next_scheduled( 'ssp_static_export_daily_cron' ) ) { | |
wp_schedule_event( time(), 'daily', 'ssp_static_export_daily_cron' ); | |
} | |
} | |
add_action( 'ssp_static_export_daily_cron', 'ssp_run_static_export_cron_daily' ); | |
/** | |
* Run different types of exports via Cron event. | |
* | |
* @return void | |
*/ | |
function ssp_run_static_export_cron_daily() { | |
// Full static export | |
$simply_static = Simply_Static\Plugin::instance(); | |
$simply_static->run_static_export(); | |
// Exporting a build with Pro | |
$build_id = 0; // Add your build id here. | |
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 | |
$post_id = 0; // Add your post id here. | |
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