Admin notification being sent 3 times
-
I have created a custom post type for projects and the goal is that users can enter a project on the backend wp admin area. When this happens, an email should be sent to the admin, so he can check the post and then publish it. To accomplish this, I have added an action hook on ‘wp_insert_post’. My issue is that the admin notification email is being sent 3 times, instead of 1 time. So I’m wondering, what is wrong with my code?
function wgoe_send_admin_notification( $post_id, $post, $update ) { // If the post type is not a project, don't send the email if (get_post_type($post_id) != 'project') return; // If this is a revision, don't send the email. if ( wp_is_post_revision( $post_id ) ) return; // If post is being published, don't send the email if (get_post_status( $post_id ) == 'publish' ) return; $post_url = get_edit_post_link( $post_id ); $subject = 'A project has been added or updated'; $message = "Howdy Admin! \n\n\n"; $message .= "A user has added or updated a project on your website. Please check the project for publication:\n\n"; $message .= $post->post_title . ": " . $post_url . "\n\n\n"; $message .= "Dive Business For Sale"; // Send email to admin. $adminemail = get_option( 'admin_email' ); wp_mail( $adminemail, $subject, $message ); } add_action( 'wp_insert_post', 'wgoe_send_admin_notification', 10, 3 );
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Admin notification being sent 3 times’ is closed to new replies.