-
-
Save kenkaigu/1eec1c046cb433b5e01541efc7d5da60 to your computer and use it in GitHub Desktop.
Send an email notification to the Wordpress administrator when a new post is published.
This file contains hidden or 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
| <?php | |
| /** | |
| Plugin Name: Alert Admin on new Post | |
| Plugin URI: http://wordpress.stackexchange.com/questions/19040/alert-email-when-any-post-or-page-is-changed | |
| Description: Send an email notification to the administrator when a new post is published. | |
| Author: TheDeadMedic, transfered by Viktor Dite | |
| Version: 1.0 | |
| Copyright CC share alike | |
| * @param string $new_status | |
| * @param string $old_status | |
| * @param object $post | |
| */ | |
| function wpse_19040_notify_admin_on_publish( $new_status, $old_status, $post ) { | |
| if ( $new_status !== 'publish' || $old_status === 'publish' ) | |
| return; | |
| if ( ! $post_type = get_post_type_object( $post->post_type ) ) | |
| return; | |
| // Recipient, in this case the administrator email | |
| $emailto = get_option( 'admin_email' ); | |
| // Email subject, "New {post_type_label}" | |
| $subject = 'New Post at ' . $post_type->labels->singular_name; | |
| // Email body | |
| $message = 'View it: ' . get_permalink( $post->ID ) . "\nEdit it: " . get_edit_post_link( $post->ID ); | |
| wp_mail( $emailto, $subject, $message ); | |
| } | |
| add_action( 'transition_post_status', 'wpse_19040_notify_admin_on_publish', 10, 3 ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment