I'm just starting out with making plugins and I'm trying to make a simple one that will mail a notification to subscribers whenever I publish a new post.
My code so far:
add_action( 'publish_post', 'vb_esa_update_email' );
function vb_esa_update_email( $post_id ) {
//verify post is not a revision
if ( !wp_is_post_revision( $post_id ) ) {
//gets subscirbers to send email to
// WP_User_Query arguments
$args = array (
'role' => 'Subscriber',
);
// The User Query
$user_query = new WP_User_Query( $args );
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';
$message = "A post has been updated on your website:\n\n";
$message .= "<a href='". $post_url. "'>" .$post_title. "</a>\n\n";
//send email to
foreach($args as $email_address)
{
wp_mail($email_address, $subject, $message );
}
}
}
How do I go about filling up an array with the list of subscribers to send the notifications to?