WordPress publishes a new article Email to notify registered users, wordpressemail

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.