Last active
April 3, 2024 14:09
-
-
Save patrickposner/f0e0ada5c90a6ee67a4b45eb358bb04e to your computer and use it in GitHub Desktop.
Simply Static: Set up a build to run daily with cron.
This file contains 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__, 'setup_build_cron' ); | |
/** | |
* Setup a cron job to run daily. | |
* | |
* @return void | |
*/ | |
function setup_build_cron() { | |
if ( ! wp_next_scheduled( 'run_scheduled_build' ) ) { | |
wp_schedule_event( time(), 'daily', 'run_scheduled_build' ); | |
} | |
} | |
add_action( 'run_scheduled_build', 'run_build' ); | |
/** | |
* Executable function to run a build with cron. | |
* | |
* @return void | |
*/ | |
function run_build() { | |
$build_id = 123; // Add the id for your build. | |
update_option( 'simply-static-use-build', $build_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