function dddn_process($id) {
// emails anyone on or above this level
$email_user_level = 7;
global $wpdb;
$tp = $wpdb->prefix;
$result = $wpdb->get_row("
SELECT post_status, post_title, user_login, user_nicename, display_name
FROM {$tp}posts, {$tp}users
WHERE {$tp}posts.post_author = {$tp}users.ID
AND {$tp}posts.ID = '$id'
");
if (($result->post_status == "draft") || ($result->post_status == "pending")) {
$message = "";
$message .= "Draft updated on '" . get_bloginfo('name') . "'\n\n";
$message .= "Title: " . $result->post_title . "\n\n";
// *** Choose one of the following options to show the author's name
$message .= "Author: " . $result->display_name . "\n\n";
// $message .= "Author: " . $result->user_nicename . "\n\n";
// $message .= "Author: " . $result->user_login . "\n\n";
$message .= "Link: " . get_permalink($id);
$subject = "Draft updated on '" . get_bloginfo('name') . "'";
$editors = $wpdb->get_results("SELECT user_id FROM {$tp}usermeta WHERE {$tp}usermeta.meta_value >= " . $email_user_level);
$recipient = "";
foreach ($editors as $editor) {
$user_info = get_userdata($editor->user_id);
$recipient .= $user_info->user_email . ',';
}
mail($recipient, $subject, $message);
}
}
add_action('save_post', 'dddn_process');
?>
is an integer (just the post id) and not a post object (the whole post with id,status,title ...)
так глобализируйте add_action('draft_post', 'send_my_mail_on_draft' );
function send_my_mail_on_draft( $post_id,$post){
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';
$message = "A post has been updated on your website:\n\n";
$message .= "" .$post_title. "\n\n";
//send email to admin
wp_mail( '[email protected]', $subject, $message );
}
object and check the status from there eg:
function er_send_email_on_post_draft_save( $post_id ) {
global $post;
//verify post is not a revision
if ( $post->post_status == 'draft' ) {
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = 'A post has been updated';
$message = "A post has been updated on your website:\n\n";
$message .= "" .$post_title. "\n\n";
//send email to admin
wp_mail( '[email protected]', $subject, $message );
}
}
и если хочешь, можешь использовать крючок только когда сообщение сохраняется как черновик
$post
||answer||
Попробуйте с этим:
$post_id
Просто создайте файл Notification.php с описанием плагинов wp, загрузите его в папку плагинов и активируйте как обычный плагин.