• Hey everyone

    could someone please help me with this,

    I have a custom post type for weddings on my site,
    basically they are submitted from the front end and need to be approved by admin first before appearing on the site,
    when i approve them and email must be sent out to the user saying it has been approved.

    This is the code i am using in my functions file. i found this in the support forum

    add_action( 'save_post', 'send_email' );
    function send_email( $post_id ) {
    
    	global $post, $edd_options, $wp_locale;
    	$campaign = atcf_get_campaign( $post_id );
    
    // lets check if post is not revision
    	if ( !wp_is_post_revision( $post_id ) ) {
    		$post_url = get_permalink( $post_id );
    		$subject = "Your Wedding Profile has been approved";
    
    		$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    
    		$message = sprintf(__('Thank you for submitting a profile on %s - Your Profile has been approved'), $blogname) . "\r\n\r\n";
    		$message .= sprintf(__('You can now view you live profile here: %s'), $campaign->active_url()) . "\r\n\r\n";
    		$message .= sprintf(__('You may give the following search code to your friends and family to help them find your profile on the site: %s'), $campaign->search_code()) . "\r\n\r\n";
    
    		$message .= "We wish you the best of luck in funding your dream getaway\n\n";
    		$message .= "Best Regards\n";
    		$message .= "The HGR team\n";
    
    		$email = $campaign->contact_email();
    		//sends email
    		wp_mail($email, $subject, $message );
    	}
    }

    However when i delete the profile, it sends this mail out also..

    Does anyone have any idea how i could make it only send when a profile is published and not deleted..

    Thanks so much if anyone can offer any advice

    Best
    MIke

  • The topic ‘How to stop this code from sending an email when a post is deleted’ is closed to new replies.