Skip to content

Instantly share code, notes, and snippets.

@bahiirwa
Last active August 22, 2018 12:22
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 bahiirwa/0e89df57c65da14c08d60c5cdb84e045 to your computer and use it in GitHub Desktop.
Save bahiirwa/0e89df57c65da14c08d60c5cdb84e045 to your computer and use it in GitHub Desktop.
push notification to external URL
<?php
function wp_plugin_event_handler () {
global $post;
$url = 'https://us-central1-smackapp-7eab7.cloudfunctions.net/sendNotification';
if( get_post_type( $post->ID ) == 'post' ) {
//$myPost = get_post($post_id);
if( $post->post_modified_gmt == $post->post_date_gmt ){
// New Post
$post_data= array(
'title' => $post->post_title,
'data' => $post->post_content,
'topic' => 'news'
);
return wp_remote_post( $url, array( 'body' => $post_data ) );
}
}
}
add_action("save_post", "wp_plugin_event_handler");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment