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_sent_notification_campaign', array( $post_id, $campaign_id ) );

		// Create normal campaign.
		$campaign = get_post( $campaign_id );
		$post     = array(
			'post_status'   => 'publish',
			'post_type'     => 'noptin-campaign',
			'post_date'     => current_time( 'mysql' ),
			'post_date_gmt' => current_time( 'mysql', true ),
			'edit_date'     => true,
			'post_title'    => sanitize_text_field( stripslashes_deep( get_post_meta( $campaign_id, 'subject', true ) ) ),
			'post_content'  => wp_kses_post( stripslashes_deep( $campaign->post_content ) ),
			'meta_input'    => array(
				'campaign_type'         => 'newsletter',
				'preview_text'          => sanitize_text_field( stripslashes_deep( get_post_meta( $campaign_id, 'preview_text', true ) ) ),
				'new_post_notification' => $key,
				'custom_merge_tags'     => $this->get_post_merge_tags( get_post( $post_id ) ),
				'campaign_id'           => $campaign_id,
				'associated_post'       => $post_id,
				'subscribers_query'     => array(),
				'custom_title'          => sprintf( __( 'New post notification for "%s"', 'newsletter-optin-box' ), sanitize_text_field( get_the_title( $post_id ) ) ),
			),
		);

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

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

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

		$post['post_title']                 = add_noptin_merge_tags( $post['post_title'], $post['meta_input']['custom_merge_tags'], false, false );
		$post['post_content']               = add_noptin_merge_tags( $post['post_content'], $post['meta_input']['custom_merge_tags'], false, false );
		$post['meta_input']['preview_text'] = add_noptin_merge_tags( $post['meta_input']['preview_text'], $post['meta_input']['custom_merge_tags'], false, false );
		$post = apply_filters( 'noptin_mailer_new_post_automation_campaign_details', $post );

		// Send normal campaign.
		if ( apply_filters( 'noptin_should_send_new_post_notification', true, $post ) ) {
			wp_insert_post( $post );
		}

	}


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