Skip to content

Instantly share code, notes, and snippets.

@BHWD
Created July 19, 2018 19:30
Show Gist options
  • Save BHWD/4f1d02007f33ffef5f09c2527f1b7a18 to your computer and use it in GitHub Desktop.
Save BHWD/4f1d02007f33ffef5f09c2527f1b7a18 to your computer and use it in GitHub Desktop.
<?php
const UTILITY_SEARCH_POST_TYPE = "utility-search";
add_action("save_post_" . UTILITY_SEARCH_POST_TYPE, function ($post_ID, $post, $update) {
if (wp_is_post_autosave($post_ID)) {
return;
}
if (!$update) { // if new object
return;
}
// Global Message Variables
$siteurl = get_option('siteurl');
$post_url = '' . $siteurl . '/wp-admin/post.php?post=' . $post_id . '&action=edit';
// Get user object from user who updated the post
$user = wp_get_current_user();
// Check if User is an admin or not
if( current_user_can('administrator') ) {
//$new_search_email = get_option( 'new_search_email' );
$to = '[email]';
$admin_name = '[Admin Name]';
$site_reference = get_field('site_ref_1', $post_id);
$utility_search_customer = '';
$subject = 'A utility search has been updated by the user: '.$user->user_firstname;
// Message Contents
$message = "Dear ".$admin_name."\n\nSite Search ".$site_reference." has been updated. \n\nThe updated search can be seen here: ".$post_url."";
} else {
//$new_search_email = get_option( 'new_search_email' );
$to = '[email]';
$user_name = get_the_author_meta( 'display_name' );
$site_reference = get_field('site_ref_1', $post_id);
$utility_search_customer = '';
$subject = 'A utility search has been updated by the user: '.$user->user_firstname;
// Message Contents
$message = "Dear ".$user_name."\n\nSite Search ".$site_reference." has been updated. \n\nThe updated search can be seen here: ".$post_url."";
}
// Send Email
wp_mail($to, $subject, $message);
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment