Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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);
Add Comment
Please, Sign In to add comment