LLMS_Emails

LLMS_Emails


Source Source

File: includes/class.llms.emails.php

 */
class LLMS_Emails {

	use LLMS_Trait_Singleton;

	/**
	 * Singleton instance.
	 *
	 * @deprecated 5.3.0 Use {@see LLMS_Trait_Singleton::instance()}.
	 *
	 * @var LLMS_Emails
	 */
	protected static $_instance = null;

	/**
	 * Class names of all emails
	 *
	 * @var string[]
	 */
	public $emails;

	/**
	 * Constructor
	 *
	 * Initializes class.
	 * Adds actions to trigger emails off of events.
	 *
	 * @since 1.0.0
	 * @since 3.8.0 Unknown.
	 *
	 * @return void
	 */
	private function __construct() {

		// Template functions.
		LLMS()->include_template_functions();

		// Email base class.
		require_once 'emails/class.llms.email.php';
		$this->emails['generic'] = 'LLMS_Email';

		// Include email child classes.
		require_once 'emails/class.llms.email.engagement.php';
		$this->emails['engagement'] = 'LLMS_Email_Engagement';

		require_once 'emails/class.llms.email.reset.password.php';
		$this->emails['reset_password'] = 'LLMS_Email_Reset_Password';

		$this->emails = apply_filters( 'lifterlms_email_classes', $this->emails );

	}

	/**
	 * Get a string of inline CSS to add to an email button
	 *
	 * Use {button_style} merge code to output in HTML emails.
	 *
	 * @since 3.8.0
	 *
	 * @return string
	 */
	public function get_button_style() {
		/**
		 * Filters the default email button CSS rules
		 *
		 * @since 3.8.0
		 *
		 * @param array $email_button_css Associative array of the type css-property => definition.
		 */
		$rules  = apply_filters(
			'llms_email_button_css',
			array(
				'background-color' => $this->get_css( 'button-background-color', false ),
				'color'            => $this->get_css( 'button-font-color', false ),
				'display'          => 'inline-block',
				'padding'          => '10px 15px',
				'text-decoration'  => 'none',
			)
		);
		$styles = '';
		foreach ( $rules as $rule => $style ) {
			$styles .= sprintf( '%1$s:%2$s !important;', $rule, $style );
		}
		return $styles;
	}

	/**
	 * Get css rules specific to the the email templates
	 *
	 * @since 3.8.0
	 * @since 5.2.0 Early bail if no rule is provided.
	 *
	 * @param string  $rule Optional. Name of the css rule. Default is empty string.
	 *                      If not provided an empty string will be returned/echoed.
	 * @param boolean $echo Optional. If true, echo the definition. Default is `true`.
	 * @return string
	 */
	public function get_css( $rule = '', $echo = true ) {

		if ( empty( $rule ) ) {
			return '';
		}

		/**
		 * Filters the default email CSS rules
		 *
		 * @since 3.8.0
		 *
		 * @param array $email_css Associative array of the type css-property => definition.
		 */
		$css = apply_filters(
			'llms_email_css',
			array(
				'background-color'         => '#f6f6f6',
				'border-radius'            => '3px',
				'button-background-color'  => '#2295ff',
				'button-font-color'        => '#ffffff',
				'divider-color'            => '#cecece',
				'font-color'               => '#222222',
				'font-family'              => 'sans-serif',
				'font-size'                => '15px',
				'font-size-small'          => '13px',
				'heading-background-color' => '#2295ff',
				'heading-font-color'       => '#ffffff',
				'main-color'               => '#2295ff',
				'max-width'                => '580px',
			)
		);

		if ( isset( $css[ $rule ] ) ) {

			if ( $echo ) {
				echo $css[ $rule ];
			}

			return $css[ $rule ];

		}

	}

	/**
	 * Get an HTML divider for use in HTML emails
	 *
	 * Can use shortcode {divider} to output in any email.
	 *
	 * @since 3.8.0
	 *
	 * @return string
	 */
	public function get_divider_html() {
		return '<div style="height:1px;width:100%;margin:15px auto;background-color:' . $this->get_css( 'divider-color', false ) . '"></div>';
	}

	/**
	 * Retrieve a new instance of an email
	 *
	 * @since 3.8.0
	 *
	 * @param string $id   Email id.
	 * @param array  $args Optional arguments to pass to the email.
	 * @return LLMS_Email
	 */
	public function get_email( $id, $args = array() ) {

		$emails = $this->get_emails();

		// If we have an email matching the ID, return an instance of that email class.
		if ( isset( $emails[ $id ] ) ) {
			return new $emails[ $id ]( $args );
		}

		// Otherwise return a generic email and set the ID to be the requested ID.
		/** @var LLMS_Email $generic */
		$generic = new $emails['generic']( $args );
		$generic->set_id( $id );
		return $generic;

	}

	/**
	 * Get all email objects
	 *
	 * @since 1.0.0
	 *
	 * @return string[] Array of all email class names.
	 */
	public function get_emails() {
		return $this->emails;
	}

	/**

Top ↑

Methods Methods

  • __construct — Constructor Initializes class Adds actions to trigger emails off of events
  • get_button_style — Get a string of inline CSS to add to an email button Use {button_style} merge code to output in HTML emails
  • get_css — Get css rules specific to the the email templates
  • get_divider_html — Get an HTML divider for use in HTML emails Can use shortcode {divider} to output in any email
  • get_email — Retrieve a new instance of an email
  • get_emails — Get all email objects
  • get_header_image_src — Retrieve the source url of the header image as defined in LifterLMS settings
  • instance — Create instance of class

Top ↑

Changelog Changelog

Changelog
Version Description
3.8.0 Unknown.
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.