Advertisement
drkskwlkr

Send new post content via webhook

Apr 4th, 2024 (edited)
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | Source Code | 0 0
  1. add_action('publish_post', function( $ID, $post ) {
  2.     if ($post->post_type == 'post') {
  3.         $webhook_url = 'https://example.com/webhook-endpoint';
  4.  
  5.         $response = wp_remote_post(
  6.             $webhook_url,
  7.             array(
  8.                 'method' => 'POST',
  9.                 'body'   => json_encode( $post ),
  10.                 'headers' => array('Content-Type' => 'application/json')
  11.             )
  12.         );
  13.     }
  14. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement