Skip to content

Instantly share code, notes, and snippets.

@patrickposner
Last active April 3, 2024 14:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickposner/f0e0ada5c90a6ee67a4b45eb358bb04e to your computer and use it in GitHub Desktop.
Save patrickposner/f0e0ada5c90a6ee67a4b45eb358bb04e to your computer and use it in GitHub Desktop.
Simply Static: Set up a build to run daily with cron.
<?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