-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notify Community Team when new post is pending in Central #1058
Open
timiwahalahti
wants to merge
1
commit into
WordPress:production
Choose a base branch
from
timiwahalahti:fix/718
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need a method for clearing this on successful save, in case we switch between statuses such as: draft => pending |
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure of the purpose of the
edit_posts
check here - would that not be covered by edit privileges anyway?