Support » Fixing WordPress » change comment notification email to alert to new posts

  • Whenever a new comment is made, the admin receives an automatic email. What do I change so that these emails are also sent whenever a new post is made? (my site has several admins, so we need this feature)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator t-p

    (@t-p)

    Thread Starter brothma1

    (@brothma1)

    from the description that looks like it will allow me to do what I want to do. But just in case that plugin stops getting updated, how do I do it in my code?

    Moderator t-p

    (@t-p)

    function notifyAdmins( $new_status, $old_status, $post ) {
        if ( ($new_status == 'publish') && ($old_status != 'publish') ) {
    
            $userQueryArgs = array(
                'blog_id'      => $GLOBALS['blog_id'],
                'role'         => 'administrator',
                'meta_key'     => '',
                'meta_value'   => '',
                'meta_compare' => '',
                'meta_query'   => array(),
                'include'      => array(),
                'exclude'      => array(),
                'orderby'      => 'login',
                'order'        => 'ASC',
                'offset'       => '',
                'search'       => '',
                'number'       => '',
                'count_total'  => false,
                'fields'       => 'all',
                'who'          => ''
            );
            $adminstrators = get_users($userQueryArgs);
            $recipients = array();
            foreach ( $adminstrators as $admin ){
                $recipients[] = $admin->data->user_email;
            }
            $message = "New post, ".$post->post_title." has just been published at ".get_permalink( $post->ID );
            wp_mail($recipients, "New Post", $message);
        }
    }
    add_action('transition_post_status', 'notifyAdmins', 10, 3 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘change comment notification email to alert to new posts’ is closed to new replies.