Skip to content

Instantly share code, notes, and snippets.

@bahiirwa
Last active Aug 22, 2018
Embed
What would you like to do?
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