Last active
March 28, 2024 21:33
-
-
Save vdite/da7dfe7f59f69e34ae34 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 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 ); | |
?> |
how i send mail to user when i publish only new post only
Hi, great script!
Any sugestions to make it to work for woocommerce when a new product is published?
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save this file in the plugin folder ** and activate the new plugin for be informed on each new post
** [WORDPRESS FOLDER]/wp-content/plugins/
More Info (in german) at http://webmaster-fragen.de/wordpress-related/wordpress-plugins/wordpress-benachrichtigung-bei-neuen-beitraegen-20150527.html