WPIntell

Source evidence

Notification email when posts are updated/changed

Digest Notifications · support · 2015-11-12T23:06:00+00:00

complaintsentiment
mediumseverity
0.93relevance
4replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

3 / 22 rows with source links

13.6% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

19 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
mafsdisseny unresolved
Hi, I have more or less developed a function, based on: add_action( 'save_post', 'send_notification_function' ); that emails to a determined recipient, when changes on a post are made (post status, post content, post meta, published, send to review, etc…). I want to add this as an extra event to the queue of your plugin, can you guide me in how to achieve this? Thanks! https://wordpress.org/plugins/digest/ Hi there Glad you’re interested in leveraging the plugin! Currently, you need to do add your custom event to the queue as follows: WP_Digest_Queue::add( 'test@example.com', 'your_notification_type', $post_id ); . After that, you’d filter the message sent in the email using the digest_event_message filter. However , I’m in the middle of rewriting the plugin to make this easier, so stay tuned! OK, so if I declare my custom function in my child theme functions.php, and I attach it to the filter “digest_event_message”, it should work… More or less: function updated_send_email( $post_id ) { // If this is just a revision, don't send the email. if ( wp_is_post_revision( $post_id ) ) return; $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 .= $post_title . ": " . $post_url; return $message; //before i was sending a mail: //wp_mail( 'example@mail.com', $subject, $message ); //Now you suggest: //I guess that I need to declare the 'updated_post' item before add_filter( 'digest_event_message', $message, 'updated_post' ); } add_action( 'save_post', 'updated_send_email' ); Thanks for your guidance! More precisely you should do something like that (untested!): function updated_send_email( $post_id ) { // If this is just a revision, don't send the email. if ( wp_is_post_revision( $post_id ) ) { return; } // Add to queue. WP_Digest_Queue::add( 'test@example.com', 'your_notification_type', $post_id ); } add_action( 'save_post', 'updated_send_email' ); /** * Filter the digest message for our own notifications. * * @param string $message The message. * @param array $item The event item. * @return string The filtered message. */ function updated_digest_message( $message, $item ) { if ( 'your_notification_type' !== $item[1] ) { return; } $time_the_event_was_queued = $item[0]; $post_id = $item[2]; $message = "A post has been updated on your website..."; return $message; } add_filter( 'digest_event_message', 'updated_digest_message', 10, 2 ); Again, this will most likely change in the future. We will make it way easier to do such things, so keep an eye on the plugin updates. There will also be some detailed documentation on how to do this. Hi Pascal, thanks for your help. I’m trying to do some tests with the plugin configuration and the notification messages, but I don’t know how to test it “immediately”. Is there any way to debug it? And see if the data is being processed correctly? And, another question: What kind of notifications is sending the plugin by default? Have you considered allowing to control these parameters through the options panel? I think that it will be helpful for users in order to configure it, don’t you think? Again, thank you very much for your help Pascal!

Comments

4 shown
Pascal Birchler 2015-11-13T08:57:00+00:00

Hi there Glad you’re interested in leveraging the plugin! Currently, you need to do add your custom event to the queue as follows: WP_Digest_Queue::add( 'test@example.com', 'your_notification_type', $post_id ); . After that, you’d filter the message sent in the email using the digest_event_message filter. However , I’m in the middle of rewriting the plugin to make this easier, so stay tuned!

mafsdisseny 2015-11-13T09:12:00+00:00

OK, so if I declare my custom function in my child theme functions.php, and I attach it to the filter “digest_event_message”, it should work… More or less: function updated_send_email( $post_id ) { // If this is just a revision, don't send the email. if ( wp_is_post_revision( $post_id ) ) return; $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 .= $post_title . ": " . $post_url; return $message; //before i was sending a mail: //wp_mail( 'example@mail.com', $subject, $message ); //Now you suggest: //I guess that I need to declare the 'updated_post' item before add_filter( 'digest_event_message', $message, 'updated_post' ); } add_action( 'save_post', 'updated_send_email' ); Thanks for your guidance!

Pascal Birchler 2015-11-13T10:09:00+00:00

More precisely you should do something like that (untested!): function updated_send_email( $post_id ) { // If this is just a revision, don't send the email. if ( wp_is_post_revision( $post_id ) ) { return; } // Add to queue. WP_Digest_Queue::add( 'test@example.com', 'your_notification_type', $post_id ); } add_action( 'save_post', 'updated_send_email' ); /** * Filter the digest message for our own notifications. * * @param string $message The message. * @param array $item The event item. * @return string The filtered message. */ function updated_digest_message( $message, $item ) { if ( 'your_notification_type' !== $item[1] ) { return; } $time_the_event_was_queued = $item[0]; $post_id = $item[2]; $message = "A post has been updated on your website..."; return $message; } add_filter( 'digest_event_message', 'updated_digest_message', 10, 2 ); Again, this will most likely change in the future. We will make it way easier to do such things, so keep an eye on the plugin updates. There will also be some detailed documentation on how to do this.

mafsdisseny 2015-11-16T10:46:00+00:00

Hi Pascal, thanks for your help. I’m trying to do some tests with the plugin configuration and the notification messages, but I don’t know how to test it “immediately”. Is there any way to debug it? And see if the data is being processed correctly? And, another question: What kind of notifications is sending the plugin by default? Have you considered allowing to control these parameters through the options panel? I think that it will be helpful for users in order to configure it, don’t you think? Again, thank you very much for your help Pascal!