Code Snippet - Run a Build export with WP Cron
This code snippet can be used as part of a WP Cron job to schedule a Simply Static Build export (learn more about the Build export option in Simply Static). For more information on setting up a WP Cron jobs with Simply Static and using code snippets in WordPress I recommend taking a looks at the following resources:
- Code Snippets
- How to schedule Exports with WP Crontrol
- How to use Actions and Filters to customize Simply Static
- How to use Build Exports
Please note: The Simply Static team is not able to provide support for custom code added to your site that modifies the behavior of Simply Static.
function ssp_run_build_export_cron() { // Exporting a build with Pro $build_id = 1234; // Add your build id here. // Update option for using a build. update_option( 'simply-static-use-build', $build_id ); // Clear records before run the export. Simply_Static\Page::query()->delete_all(); // Add URLs. simply_static_pro\Build::add_urls( $build_id ); simply_static_pro\Build::add_files( $build_id ); do_action( 'ssp_before_run_build' ); // Start static export. $ss = Simply_Static\Plugin::instance(); $ss->run_static_export(); } add_action( 'ssp_build_export_cron', 'ssp_run_build_export_cron' );