Strattic Developers by Elementor

Send publish alerts to Slack

You may have read about how Strattic’s publishing system makes use of several transients somewhere else on this site.

Well, if you’re looking for a way to use those transients to send publish alerts to your Slack channels, then you’ve come to the right place!

You may want to create your own Slack app for your workspace, and that route would be well outside the scope of our documentation. However, you can add an alert quickly using a Slack workflow.

Here is a code example for how you could send the alerts to a Slack webhook.

 * Send alerts for Strattic status changes to Slack.
 * @param $value The Strattic status value
add_action( 'set_transient_strattic-status', 'strattic_status_change' );
function strattic_status_change( $value ) {
	if ( $value === 'first-stage-publishing' ) {
		$dist_type = get_transient( 'strattic-distribution-type' );
		$type      = get_transient( 'strattic-publish-type' );

		// Now rename and assign vars.
		$slack_array = array(
		   'publish_type' => ucwords( $type ),
		   'distribution' => ucwords( $dist_type )

		// Build JSON for Slack.
		$slack_array = json_encode($slack_array);

		// get my Slack URL.
		$slack_hook_url = '';

		// Curl my data into the zap.
		$ch = curl_init( $slack_hook_url );
		curl_setopt( $ch, CURLOPT_POST, 1 );
		curl_setopt( $ch, CURLOPT_POSTFIELDS, $slack_array );
		curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
		curl_setopt( $ch, CURLOPT_HEADER, 0 );
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

		$response = curl_exec( $ch );