Guest User

Untitled

a guest
Jul 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <?php
  2. const UTILITY_SEARCH_POST_TYPE = "utility-search";
  3.  
  4. add_action("save_post_" . UTILITY_SEARCH_POST_TYPE, function ($post_ID, $post, $update) {
  5.  
  6. if (wp_is_post_autosave($post_ID)) {
  7. return;
  8. }
  9.  
  10. if (!$update) { // if new object
  11. return;
  12. }
  13.  
  14.  
  15. // Global Message Variables
  16. $siteurl = get_option('siteurl');
  17. $post_url = '' . $siteurl . '/wp-admin/post.php?post=' . $post_id . '&action=edit';
  18.  
  19. // Get user object from user who updated the post
  20. $user = wp_get_current_user();
  21.  
  22. // Check if User is an admin or not
  23. if( current_user_can('administrator') ) {
  24.  
  25. //$new_search_email = get_option( 'new_search_email' );
  26. $to = '[email]';
  27. $admin_name = '[Admin Name]';
  28. $site_reference = get_field('site_ref_1', $post_id);
  29. $utility_search_customer = '';
  30. $subject = 'A utility search has been updated by the user: '.$user->user_firstname;
  31.  
  32. // Message Contents
  33. $message = "Dear ".$admin_name."\n\nSite Search ".$site_reference." has been updated. \n\nThe updated search can be seen here: ".$post_url."";
  34.  
  35. } else {
  36.  
  37. //$new_search_email = get_option( 'new_search_email' );
  38. $to = '[email]';
  39. $user_name = get_the_author_meta( 'display_name' );
  40. $site_reference = get_field('site_ref_1', $post_id);
  41. $utility_search_customer = '';
  42. $subject = 'A utility search has been updated by the user: '.$user->user_firstname;
  43.  
  44. // Message Contents
  45. $message = "Dear ".$user_name."\n\nSite Search ".$site_reference." has been updated. \n\nThe updated search can be seen here: ".$post_url."";
  46.  
  47. }
  48. // Send Email
  49. wp_mail($to, $subject, $message);
  50.  
  51.  
  52.  
  53. }, 10, 3);
Add Comment
Please, Sign In to add comment