Strattic Developer Docs

Strattic Publish Event Hooks

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:

false (transient not set)There is no publish currently in progress
‘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 *
*System will be reset shortly so that another publish can happen.

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:

TransientMeaningPossible Values
‘strattic-publish-type’The publish typefull, quick, selective
‘strattic-distribution-type’The environmentlive, preview
‘requesting-time-started’Timestamp of the publish startingTimestamp

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( '', $subject, $body );