If you use the Post Notification plugin in your hosted WordPress (WP) blog you will notice that it maintains a separate MySQL table called post_notification_emails for users who subscribe for email alerts about new blog posts.
But unfortunately there is no easy, configurable way to automatically subscribe a user for post notifications when he or she registers a new account in the blog.
Remember, when a new user registers he has to provide his email address which is stored in the core WP users table which has no link with the post_notification_emails table.
A simple solution for this is to create a MySQL trigger in your WP database like so;
DELIMITER $$ CREATE TRIGGER `subscribe_user_for_notifications` AFTER INSERT ON `users` FOR EACH ROW BEGIN INSERT INTO post_notification_emails (email_addr, last_modified, date_subscribed, gets_mail) VALUES (NEW.user_email, now(),now(),1 ); INSERT INTO post_notification_cats (id,cat_id) VALUES (NEW.id, 0); END $$ DELIMITER ;
- I used the phpMyAdmin tool to execute commands on the MySQL database. This comes with the WAMP installation which is used to host the blog.
- The table names mentioned above may have table prefixes if you provided them during the WP setup. (e.g. travelblog_post_notification_mails)
Although I’m sure there are other ways of doing this like hacking the PHP code in the Post Notification plugin (which by the way is no longer maintained) to query the users database for emails in additions to the post_notification_emails for now I prefer this backend DB solution 🙂