WordPress publishes a new article Email to notify registered users, wordpressemail
Many WordPress blogs provide the user registration function. Users can participate in the construction of Blog content, that is, a blog is written by multiple users. How can other users receive Email notifications after a user publishes an article? The implementation method is as follows:
Add the following php code to pluggable. php under the WordPress topic directory:
Function newpostpolicy ($ post_ID) {if (wp_is_post_revision ($ post_ID) return; global $ wpdb; $ get_post_info = get_post ($ post_ID ); if ($ get_post_info-> post_status = 'Publish '& $ _ POST ['original _ post_status']! = 'Publish ') {// read the database and obtain all users' email $ wp_user_email = $ wpdb-> get_col ("select distinct user_email FROM $ wpdb-> users "); // email title $ subject = 'xx blog has a new file'; // email content $ message = 'Article title :'. get_the_title ($ post_ID ). '<br/>'; $ message. = 'Article URL: <a href = "'. get_permalink ($ post_ID ). '"> '. get_permalink ($ post_ID ). '</a> <br/>'; // email $ message_headers = "Content-Type: text/html; charset = \" UTF-8 \ "\ n "; wp_mail ($ wp_user_email, $ subject, $ message, $ message_headers) ;}// hook, execute the newpostpolicy function add_action ('Publish _ Post', 'newpostpolicy') once a new WordPress article is published or modified ');
The Code has been added with comments, which is relatively easy to understand. Every time a new article is published, it will automatically send an Email notification to all registered users without any intervention. If your blog cannot send emails, it may be a host issue. Ask your host customer service if it supports the PHP mail () function. If you have hundreds of registered users, you also need to send so many emails. You can expect that you will have to wait until these emails are sent when publishing an article, of course, this means that your email may be identified as spam or rejected by some email servers.
I personally do not agree with this practice, and there is a suspicion of harassment. After all, not every registered user wants to receive similar emails.