Run a hook when a static export completes
Simply Static Action Hook: ss_completed
Overview
The ss_completed action hook is fired when a Simply Static export job finishes, regardless of whether it completed successfully, encountered an error, or threw an exception. This hook allows developers to execute custom code after the static site generation process concludes.
Hook Signature
do_action( 'ss_completed', $status, $message = null );
Parameters
$status (string)
The completion status of the export job. Possible values:
'success'- The export completed successfully without errors'error'- The export failed due to a WordPress error (WP_Error object)'exception'- The export failed due to a PHP exception
$message (string | null)
An optional error message that provides additional context when the status is 'error' or 'exception' . This parameter is null when the status is 'success' .
Usage Examples
Basic Usage - Success Only
/**
* Send a notification when export completes successfully
*/
function my_export_success_handler( $status ) {
if ( $status === 'success' ) {
// Your custom code here
error_log( 'Simply Static export completed successfully!' );
}
}
add_action( 'ss_completed', 'my_export_success_handler', 10, 1 );
Advanced Usage - Handle All Statuses
/**
* Handle all export completion scenarios
*/
function my_comprehensive_export_handler( $status, $message = null ) {
switch ( $status ) {
case 'success':
// Export completed successfully
error_log( 'Simply Static export completed successfully!' );
break;
case 'error':
// Export failed with WP_Error
error_log( 'Simply Static export failed with error: ' . $message );
send_failure_notification( $message );
break;
case 'exception':
// Export failed with PHP exception
error_log( 'Simply Static export failed with exception: ' . $message );
break;
}
}
add_action( 'ss_completed', 'my_comprehensive_export_handler', 10, 2 );
Webhook Integration Example
/**
* Send webhook notification after export completion
*/
function send_export_webhook( $status, $message = null ) {
$webhook_url = 'YOUR_WEBHOOK_URL_HERE';
if ( empty( $webhook_url ) ) {
return;
}
$payload = array(
'event' => 'simply_static_export_completed',
'status' => $status,
'timestamp' => current_time( 'c' ), // ISO 8601 format
'site_url' => get_site_url(),
'site_name' => get_bloginfo( 'name' )
);
// Include error message if present
if ( $message ) {
$payload['error_message'] = $message;
}
// Add export details for successful exports
if ( $status === 'success' ) {
$options = \Simply_Static\Options::instance();
$payload['export_details'] = array(
'start_time' => $options->get( 'archive_start_time' ),
'end_time' => $options->get( 'archive_end_time' ),
'destination_url_type' => $options->get( 'destination_url_type' ),
'delivery_method' => $options->get( 'delivery_method' )
);
}
wp_remote_post( $webhook_url, array(
'body' => wp_json_encode( $payload ),
'headers' => array(
'Content-Type' => 'application/json',
'User-Agent' => 'Simply Static Webhook'
),
'timeout' => 30,
'blocking' => false // Don't wait for response
));
}
add_action( 'ss_completed', 'send_export_webhook', 10, 2 );
Available Context
When the hook fires, you have access to:
- Simply Static Options: Get export settings via
\Simply_Static\Options::instance() - WordPress Functions: All standard WordPress functions and data
- Export Timing: Start and end times are stored in options
- Current User: The user who initiated the export (if applicable)
Accessing Export Details
function get_export_details() {
$options = \Simply_Static\Options::instance();
return array(
'start_time' => $options->get( 'archive_start_time' ),
'end_time' => $options->get( 'archive_end_time' ),
'destination_url_type' => $options->get( 'destination_url_type' ),
'delivery_method' => $options->get( 'delivery_method' ),
'static_url' => $options->get( 'static_url' ),
'temp_files_dir' => $options->get( 'temp_files_dir' )
);
}