-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add plugin to notify central when there is pending posts
- Loading branch information
1 parent
e4f6df9
commit f495690
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
public_html/wp-content/plugins/notify-central-on-pending-posts.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Notify WordCamp Central on pending posts | ||
* Plugin URI: http://wordcamp.org | ||
* Description: Send email notification to WordCamp Central when post status becomes pending. | ||
* Version: 1.0 | ||
* | ||
* Heavily inspired from Pending Submission Notifications plugin by Razvan Horeanga. | ||
*/ | ||
|
||
namespace Notify_Central_Pending_Posts; | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
die( 'Invalid request.' ); | ||
} | ||
|
||
add_action( 'transition_post_status', __NAMESPACE__ . '\send_notification_email', 10, 3 ); | ||
|
||
/** | ||
* Send the notification email. | ||
* | ||
* @param string $new_status New post status. | ||
* @param string $old_status Old post status. | ||
* @param WP_Post $post Post object. | ||
*/ | ||
function send_notification_email( $new_status, $old_status, $post ) { | ||
if ( 'pending' === $new_status && user_can( $post->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( '[email protected]', $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' ) ); | ||
} | ||
} |