Noptin_Mailer::build_email( array $data )

Given merge tags, this method builds an email.


Parameters Parameters

$data

(array) (Required) The email data.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/class-noptin-mailer.php

	public function build_email( $data ) {

		// Filters email data before the email is generated.
		$data = apply_filters( 'noptin_mailer_email_data', $data, $this );

		// If no template is provided, use the user set template.
		if ( empty( $data['template'] ) ) {
			$data['template'] = $this->get_template( $data );
		}

		$template = $data['template'];

		// Whether or not we should disable template plugins.
		$this->disable_template_plugins = 'empty' !== $template && 'default' !== $template;

		// If we are using an empty template, return the content as is.
		if ( 'empty' === $template ) {
			return $this->post_process( $data['email_body'], $data );
		}

		ob_start();

		// If this is a full path to the template...
		if ( file_exists( $template ) ) {
			include $template;
			return $this->post_process( ob_get_clean(), $data );
		}

		// We are using a template stored in the templates directory.
		$sections = array(
			'header',
			'preview-text',
			'logo',
			'body',
			'footer'
		);

		foreach ( apply_filters( 'noptin_mailer_email_sections', $sections, $data, $template, $this ) as $section ) {

			$section = sanitize_text_field( $section );

			// Fires before the section is printed.
			do_action( "noptin_mailer_before_{$section}_section", $data, $this );

			// Load the section.
			get_noptin_template( "email-templates/$template/$section.php", $data );

			// Fires after the section is printed.
			do_action( "noptin_mailer_after_{$section}_section", $data, $this );

		}

		$email_content = ob_get_clean();

		// Filters email content before it is pre-processed.
		$email_content = apply_filters( 'noptin_mailer_pre_processed_email_content', $email_content, $data, $this );

		if ( empty( $email_content ) ) {
			$email_content = $data['email_body'];
		}

		return $this->post_process( $email_content, $data );
	}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.2.8Introduced.

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