From 9db6c7f426f3bcd271a00030766a8a3c9ff19b3e Mon Sep 17 00:00:00 2001 From: Timi Wahalahti Date: Thu, 21 Sep 2023 18:38:55 +0300 Subject: [PATCH] add plugin to notify central when there is pending posts --- .../notify-central-on-pending-posts.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 public_html/wp-content/plugins/notify-central-on-pending-posts.php diff --git a/public_html/wp-content/plugins/notify-central-on-pending-posts.php b/public_html/wp-content/plugins/notify-central-on-pending-posts.php new file mode 100644 index 000000000..a3b8811ca --- /dev/null +++ b/public_html/wp-content/plugins/notify-central-on-pending-posts.php @@ -0,0 +1,55 @@ +post_author, 'edit_posts' ) ) { + // Prevent many emails from the same post. + $sent = get_post_meta( $post->ID, '_ncpp_sent', true ); + if ( ! empty( $sent ) ) { + return; + } + + $edit_link = get_edit_post_link( $post->ID, '' ); + $preview_link = get_permalink( $post->ID ) . '&preview=true'; + + $username = get_userdata( $post->post_author ); + $username_last_edit = get_the_modified_author(); + + $subject = __( 'New post on WordCamp Central pending review', 'wordcamporg' ) . ": {$post->post_title}"; + + $message = __( 'Hello team! A new post on WordCamp Central is pending review.', 'wordcamporg' ); + $message .= "\r\n\r\n"; + $message .= __( 'Title' ) . ": {$post->post_title}\r\n"; + $message .= __( 'Author' ) . ": {$username->user_login}\r\n"; + $message .= "\r\n\r\n"; + $message .= __( 'Edit' ) . ": {$edit_link}\r\n"; + $message .= __( 'Preview' ) . ": {$preview_link}"; + + wp_mail( 'support@wordcamp.org', $subject, $message ); + + // Save a pointer that notification has been sent. + update_post_meta( $post->ID, '_ncpp_sent', wp_date( 'Y-m-d H:i:s' ) ); + } +}