Skip to content

Instantly share code, notes, and snippets.

@lewayotte
Created March 14, 2016 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewayotte/809cb637c93dd29e1db0 to your computer and use it in GitHub Desktop.
Save lewayotte/809cb637c93dd29e1db0 to your computer and use it in GitHub Desktop.
Example Plugin to Send Data to SAAS Backend from WordPress
<?php
function wcatl2016_transition_post_status( $new_status, $old_status, $post ) {
$api_url = 'https://lewayotte.com/?wcatl=1';
if ( 'publish' === $new_status && 'publish' !== $old_status ) {
$args = array(
'headers' => array( 'content-type' => 'application/json' ),
'body' => json_encode( array( 'post-id' => $post->ID ) ),
);
$response = wp_remote_post( $api_url, $args );
if ( !empty( $response ) && is_wp_error( $response ) ) {
error_log( sprintf( __( 'Error: %s', 'wcatl2016-api' ), $response->get_error_message() ) );
}
}
}
add_action( 'transition_post_status', 'wcatl2016_transition_post_status', 100, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment