-
-
Save laxmariappan/df8803497d29b03ef77e51452111c3c0 to your computer and use it in GitHub Desktop.
Set error message to post meta.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php function set_notification_status( $post_id, $post ) { | |
if ( ! $post ) { | |
return; // Exit if there is no response. | |
} | |
// @see https://developer.wordpress.org/reference/hooks/new_status_post-post_type/#comment-4335 | |
$author = $post->post_author; | |
$name = get_the_author_meta( 'display_name', $author ); | |
$email = get_the_author_meta( 'user_email', $author ); | |
$title = $post->post_title; | |
$permalink = get_permalink( $post_id ); | |
$to[] = sprintf( '%s <%s>', $name, $email ); | |
$subject = sprintf( 'Published: %s', $title ); | |
$message = sprintf( 'Congratulations, %s! Your article "%s" has been published.' . "\n\n", $name, $title ); | |
$message .= sprintf( 'View: %s', $permalink ); | |
$headers[] = ''; | |
$sent = wp_mail( $to, $subject, $message, $headers ); | |
if ( $sent ) { | |
$response = array( | |
'code' => 'success', | |
'message' => 'Email notification(s) sent sucessfully', | |
); | |
} else { | |
$response = array( | |
'code' => 'error', | |
'message' => 'Failed to send email notification(s)', | |
); | |
} | |
update_post_meta( $post_id, 'email_notification', wp_json_encode( $response ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment