Noptin_New_Post_Notify::notify( $post_id,  $campaign_id,  $key )

Send out a new post notification


Source Source

File: includes/class-noptin-new-post-notify.php

	protected function notify( $post_id, $campaign_id, $key ) {

		// Ensure that both the campaign and post are published.
		if ( 'publish' !== get_post_status( $post_id ) || 'publish' !== get_post_status( $campaign_id ) ) {
			return;
		}

		update_post_meta( $post_id, 'noptin_associated_new_post_notification_campaign', $campaign_id );

		$noptin   = noptin();
		$campaign = get_post( $campaign_id );

		$item = array(
			'campaign_id'       => $campaign_id,
			'associated_post'   => $post_id,
			'subscribers_query' => array(),
			'key'               => $key,
			'automation_type'   => 'post_notifications',
			'campaign_type'     => 'automation',
			'campaign_data'     => array(
				'email_body'    => wp_kses_post( stripslashes_deep( $campaign->post_content ) ),
				'email_subject' => sanitize_text_field( stripslashes_deep( get_post_meta( $campaign_id, 'subject', true ) ) ),
				'preview_text'  => sanitize_text_field( stripslashes_deep( get_post_meta( $campaign_id, 'preview_text', true ) ) ),
				'merge_tags'    => $this->get_post_merge_tags( get_post( $post_id ) ),
			),
		);

		$content  = get_post_meta( $post_id, 'noptin_post_notify_content', true );
		if ( ! empty( $content ) ) {
			$item['campaign_data']['email_body'] = wp_kses_post( stripslashes_deep( $content ) );
		}

		$subject = get_post_meta( $post_id, 'noptin_post_notify_subject', true );
		if ( ! empty( $subject ) ) {
			$item['campaign_data']['email_subject'] = sanitize_text_field( stripslashes_deep( $subject ) );
		}

		$preview = get_post_meta( $post_id, 'noptin_post_notify_preview_text', true );
		if ( ! empty( $preview ) ) {
			$item['campaign_data']['preview_text'] = sanitize_text_field( stripslashes_deep( $preview ) );
		}

		$item = apply_filters( 'noptin_mailer_new_post_automation_details', $item, $post_id, $campaign_id );

		if ( apply_filters( 'noptin_should_send_new_post_notification', true, $item ) ) {
			$noptin->bg_mailer->push_to_queue( $item );
			$noptin->bg_mailer->save()->dispatch();
		}

	}


Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation