Last active
August 22, 2018 12:22
-
-
Save bahiirwa/0e89df57c65da14c08d60c5cdb84e045 to your computer and use it in GitHub Desktop.
push notification to external URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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