WordPress: auto add new users to post notification

There is nice plugin for WordPress called "Post Notification" which allows your WP users to be informed about new posts. But those users should subscribe manually using subscribe page (or another plugin, for example: "WordPress Notification Bar"). You can also add new users manually as WP admin, but this is annoying especially if you got loads of new users.

But there's an easy way to automatically add new users to Post Notification and automatically delete then from PN when they wipe their WP accounts (or when admin delete those accounts). You just have to create four small triggers (two for add and two for delete) in your WordPress database.

Below is the code.
To add new users:

delimiter #
create trigger add_post_notification after insert on wp_users
for each row
begin
insert into wp_post_notification_emails (email_addr, gets_mail, date_subscribed) values (new.user_email, '1', CURRENT_TIMESTAMP);
end#

delimiter #
create trigger add_post_cats after insert on wp_post_notification_emails
for each row
begin
insert into wp_post_notification_cats (id, cat_id) values (new.id, '0');
end#

To delete from PN erased users:

delimiter #
create trigger erase_post_notification before delete on wp_users
for each row
begin
delete from wp_post_notification_emails where email_addr=OLD.user_email;
end#

delimiter #
create trigger erase_post_cats before delete on wp_post_notification_emails
for each row
begin
delete from wp_post_notification_cats where id=OLD.id;
end#

Nothing spectacular, but I couldn't find this info anywhere over the internet, so here it is :).

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Main menu

Article | by Dr. Radut