Strattic’s publishing system makes use of several transients. You can use these to perform actions at different parts of the publish process, such as sending a message with relevant information when the publish has completed.
In order to detect a change in state of the publish process, hook into the change of the transient ‘strattic-status’.
The following are possible values for this transient:
Value | Meaning |
false (transient not set) | There is no publish currently in progress |
‘first-stage-requesting’, ‘first-stage-publishing’, ‘first-stage-completed’, ‘syncing-images’ | Publish is in progress and continuing as expected (these are stages of publish) |
‘publishing-completed’ | Publish has just finished * |
‘aborted’ | Publish was aborted in the middle * |
‘first-stage-failed’ | Publish encountered an error starting * |
Changes to this transient can be hooked into in order to trigger actions you would like to happen at a stage of publish, such as sending an email to alert your users of the publish’s completion.
There are several other transients which contain information about the publish which can also be used at the point at which the ‘strattic-status’ transient changes:
Transient | Meaning | Possible Values |
‘strattic-publish-type’ | The publish type | full, quick, selective |
‘strattic-distribution-type’ | The environment | live, preview |
‘requesting-time-started’ | Timestamp of the publish starting | Timestamp |
Code example:
add_action( 'set_transient_strattic-status', 'strattic_status_change' );
function strattic_status_change( $value ) {
if ( $value === 'publishing-completed' ) {
$dist_type = get_transient( 'strattic-distribution-type' );
$type = get_transient( 'strattic-publish-type' );
$start_time = new DateTime();
$start_time->setTimestamp( get_transient( 'strattic-requesting-time-started' ) );
$current_time = new DateTime();
$current_time->setTimestamp( time() );
$duration = $start_time->diff($current_time, true);
$subject = 'Publish Completed';
$body = ucwords( $type ) . ' publish to ' . $dist_type . ' completed. Duration: ' . $duration->format('%H:%I:%S');
mail( 'admin@yoursite.com', $subject, $body );
}
}