I use this code below to send email after post send to draft. But after this I need also send emails for subscribers. I have tried to use newsletter plugin to get subscribers via REST API. But is there any solution to get those subscribers and send new email if new post published?
/**
* Send an email notification to the administrator when a post is published.
*
* @param string $new_status
* @param string $old_status
* @param object $post
*/
function wpse_19040_notify_admin_on_publish( $new_status, $old_status, $post ) {
if ( $new_status !== 'draft' || $old_status === 'draft' )
return;
if ( ! $post_type = get_post_type_object( $post->post_type ) )
return;
// Recipient, in this case the administrator email
$emailto = get_option( 'admin_email' );
// Email subject, "New {post_type_label}"
$subject = 'New ' . $post_type->labels->singular_name;
// Email body
$message = 'View it: ' . get_permalink( $post->ID ) . "\nEdit it: " . get_edit_post_link( $post->ID );
wp_mail( $emailto, $subject, $message );
}
add_action( 'transition_post_status', 'wpse_19040_notify_admin_on_publish', 10, 3 );
It does not need to use newsletter API, but then what opportunities I have to get subscribers via REST api and then use this code to send everyone email if new post published.
It should work as:
1. Page visitors can add email through input field (REST api)
2. Email added to list
3. When new post published, each list email will be emailed.
One solution I think can be something like making list of email-s (But is there any good plugin for making just a list where can delete and so on) and then go through this list and send emails.
It should use REST api because I have frontend ReactJS and I use wp as backend.
Thanks.