Hey @wintear,
sure you can do that.
You can simply get the instance within your function and start the export like so:
$simply_static = Simply_Static\Plugin::instance();
$simply_static->run_static_export();
There is also a more advanced example, but that does require the pro version.
You may still find it useful: https://patrickposner.dev/docs/simply-static/code-snippets#Single-Static-Export-after-publishing-a-post
Hey @patrickposner,
Oh thanks, great help and good to know we are calling the wrong function (create_zip()) so the function is call run_static_export().
So in our function.php do we need to include the files?
e.g `require_once WP_PLUGIN_DIR . “file.php”;
use samepledata;
use \Modules\Settings;`
could please share with us so that we can straight call the function without undefined or erros.
Hey @wintear,
you shouldn’t need to include any files to run this.
As long as Simply Static is activated, you can use the code as is to start a static export.
Just make sure you use it within some WP hook that isn’t loaded before plugins are ready (not “init” for example).
Here is an example that works fine within the functions.php of your theme:
add_action( 'after_setup_theme', function () {
// You want to set an option/transient after a publish action was fired and do the check within this function.
$was_published = false;
if ( $was_published ) {
$simply_static = Simply_Static\Plugin::instance();
$simply_static->run_static_export();
}
} );
So instead of firing the export immediately after a publish action, you use an option to toggle the process. The action here is listening, and once the option is set, the static export is scheduled.
Hey @patrickposner,
Great we can try it out.
Yes, in our function.php we did a trigger upon a hook as below.
add_action(‘owf_workflow_complete’, ‘run_static_export’);
hope this works too.
Thank you so much.
Hi @patrickposner,
We tried out the function you provided.
We integrate it with OasisWorkflow plugin hook, upon completing a flow action we will trigger the run_static_export but looks like it doesn’t work. (theme function.php) and there is no error.
add_action( 'owf_workflow_complete','complete_workflow_export');
function complete_workflow_export () {
// You want to set an option/transient after a publish action was fired and do the check within this function.
$was_published = false;
if ( $was_published ) {
$simply_static = Simply_Static\Plugin::instance();
$simply_static->run_static_export();
}
}
Are you able to provide some guidance?
Thanks
Sorry we get it to work already please ignore previous message