$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Send email to author of the post when the custom post status changes to published|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Send email to author of the post when the custom post status changes to published

matteradmin8PV0评论

I have this answer in reference :

It sends to all users.

I want to notify the author of the post only when author's custom post type gets published.

Please help thanks

I have this answer in reference :

https://wordpress.stackexchange/a/100657/145078

It sends to all users.

I want to notify the author of the post only when author's custom post type gets published.

Please help thanks

Share Improve this question asked Nov 7, 2018 at 15:53 user145078user145078
Add a comment  | 

1 Answer 1

Reset to default 0

This should work — make sure to change my_custom_type to the correct CPT slug:

add_action( 'transition_post_status', 'notify_author_on_publish', 10, 3 );
function notify_author_on_publish( $new_status, $old_status, $post ) {
    if ( 'publish' !== $new_status ||
        $new_status === $old_status ||
        'my_custom_type' !== get_post_type( $post ) ) {
        return;
    }

    // Get the post author data.
    if ( ! $user = get_userdata( $post->post_author ) ) {
        return;
    }

    // Compose the email message.
    $body = sprintf( 'Hey %s, your awesome post has been published!
    See <%s>',
        esc_html( $user->display_name ),
        get_permalink( $post )
    );

    // Now send to the post author.
    wp_mail( $user->user_email, 'Your post published!', $body );
}
Post a comment

comment list (0)

  1. No comments so far