Skip to content

Instantly share code, notes, and snippets.

@ericnicolaas
Last active March 16, 2016 07:08
Show Gist options
  • Save ericnicolaas/de776cdd17e3ee333fe5 to your computer and use it in GitHub Desktop.
Save ericnicolaas/de776cdd17e3ee333fe5 to your computer and use it in GitHub Desktop.
Send New Campaign Notification
<?php
/**
* Plugin Name: Charitable - Send New Campaign Notificaiton
* Plugin URI: https://gist.github.com/ericnicolaas/de776cdd17e3ee333fe5/edit
* Description: Correctly send the New Campaign Notification email after a campaign is submitted.
* Version: 0.1
* Author: WP Charitable
* Author URI: https://wpcharitable.com/
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Send new campaign notification after a campaign has been created.
*
* @param int $post_id
* @param WP_Post $post
* @param boolean $update
* @return boolean
*/
function ed_send_new_campaign_email( $post_id, $post, $update ) {
if ( ! charitable_get_helper( 'emails' )->is_enabled_email( Charitable_Ambassadors_Email_New_Campaign::get_email_id() ) ) {
return false;
}
if ( $update || $post->post_type != Charitable::CAMPAIGN_POST_TYPE || $post->post_status != 'publish' ) {
return false;
}
$email = new Charitable_Ambassadors_Email_New_Campaign( array (
'campaign' => new Charitable_Campaign( $post )
) );
$email->send();
return true;
}
add_action( 'wp_insert_post', 'ed_send_new_campaign_email', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment