Guest User

Untitled

a guest
Aug 18th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. function cta_send_notification( $new_status, $old_status, $post ) {
  2. $sxss=get_post_type();
  3. if(
  4. 'publish' === $new_status &&
  5. 'publish' !== $old_status &&
  6. $sxss == 'cta'
  7. ) {
  8. function postToDiscord($message)
  9. {
  10. $data = array(
  11. "content" => $message,
  12. "username" => "CTA PING BOT",
  13. );
  14. $curl = curl_init("https://discordapp.com/api/webhooks/idchannel/key");
  15. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
  16. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
  17. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  18. return curl_exec($curl);
  19. curl_close($curl);
  20. }
  21.  
  22.  
  23. $postid =get_the_ID();
  24. $taste=get_the_title($postid);
  25. global $post;
  26. // get post meta
  27. $pstmt1=get_post_meta( $postid, 'wpcf-fleetformat', true );
  28.  
  29.  
  30.  
  31.  
  32. $message="**";
  33. $message.=$taste;
  34. $message.=' **
  35. ```
  36. --------------------------------------------------------------
  37. Location: UALX-3
  38. Datetime: 10.08.18 20:00 ET
  39. FleetFormat: '.$pstmt1.'
  40. FC: TBD
  41. --------------------------------------------------------------
  42. ```';
  43.  
  44.  
  45. postToDiscord($message);
  46. }
  47. }
  48. add_action( 'transition_post_status', 'cta_send_notification', 10, 3 );
Add Comment
Please, Sign In to add comment