label/default subject/default body/available tags. */ public static function get_defaults() { return array( 'verification' => array( 'label' => __( 'Email Verification', 'aims-infosoft-lms' ), 'subject' => __( 'Verify Your Email', 'aims-infosoft-lms' ), 'body' => "

Hi {user_name},

\n

Thanks for signing up! Please confirm your email address to activate your account.

\n

Verify Email Address

\n

Or copy and paste this link into your browser:
{verify_link}

\n

If you did not create an account, you can safely ignore this email.

", 'tags' => array( 'user_name', 'user_email', 'verify_link', 'site_name' ), ), 'password_reset' => array( 'label' => __( 'Password Reset', 'aims-infosoft-lms' ), 'subject' => __( 'Password Reset Request', 'aims-infosoft-lms' ), 'body' => "

Hi {user_name},

\n

We received a request to reset your password. Click the button below to choose a new one:

\n

Reset Password

\n

Or copy and paste this link into your browser:
{reset_link}

\n

This link will expire in 1 hour. If you did not request this, you can safely ignore this email.

", 'tags' => array( 'user_name', 'user_email', 'reset_link', 'site_name' ), ), 'payment_success' => array( 'label' => __( 'Payment Successful', 'aims-infosoft-lms' ), 'subject' => __( 'Payment Successful - {course_name}', 'aims-infosoft-lms' ), 'body' => "

Hi {user_name},

\n

Your payment was successful and you're enrolled! Here are your order details:

\n\n\n\n\n\n\n
Course{course_name}
Amount{amount}
Payment Gateway{gateway}
Payment Method{method}
Transaction ID{txn_id}
\n

Thank you for your purchase!

", 'tags' => array( 'user_name', 'user_email', 'course_name', 'amount', 'gateway', 'method', 'txn_id', 'site_name' ), ), ); } /** * Get a single template's config (defaults merged with label/tags, which * are never stored in options - only subject/body are customizable). * * @param string $type Template type key. * @return array|null Template config, or null if $type is unknown. */ public static function get_template_config( $type ) { $defaults = self::get_defaults(); return $defaults[ $type ] ?? null; } /** * Get the option name a template type's subject is stored under. * * @param string $type Template type key. * @return string Option name. */ private static function subject_option_key( $type ) { return 'aimslms_email_' . $type . '_subject'; } /** * Get the option name a template type's body is stored under. * * @param string $type Template type key. * @return string Option name. */ private static function body_option_key( $type ) { return 'aimslms_email_' . $type . '_body'; } /** * Get the currently configured subject/body for a template (falls back * to the built-in default when the admin hasn't customized it). * * @param string $type Template type key. * @return array{subject: string, body: string} Subject/body pair. */ public static function get_template( $type ) { $config = self::get_template_config( $type ); if ( ! $config ) { return array( 'subject' => '', 'body' => '', ); } return array( 'subject' => get_option( self::subject_option_key( $type ), $config['subject'] ), 'body' => get_option( self::body_option_key( $type ), $config['body'] ), ); } /** * Shared header/footer branding settings for the HTML email wrapper. */ public static function get_layout_settings() { return array( 'header_type' => get_option( 'aimslms_email_header_type', 'text' ), 'header_logo' => get_option( 'aimslms_email_header_logo', '' ), 'header_text' => get_option( 'aimslms_email_header_text', get_bloginfo( 'name' ) ), 'accent_color' => get_option( 'aimslms_email_accent_color', '#1f4d3a' ), 'footer_text' => get_option( 'aimslms_email_footer_text', __( '© {year} {site_name}. All rights reserved.', 'aims-infosoft-lms' ) ), ); } /** * Replace {tag} placeholders in a subject/body pair. * * @param string $type Template type key. * @param array $tags Associative array of tag => replacement value. * @return array{subject: string, body: string} */ public static function render( $type, array $tags ) { $template = self::get_template( $type ); $layout = self::get_layout_settings(); $tags['accent_color'] = $tags['accent_color'] ?? $layout['accent_color']; $subject = $template['subject']; $body = $template['body']; foreach ( $tags as $tag => $value ) { $subject = str_replace( '{' . $tag . '}', $value, $subject ); $body = str_replace( '{' . $tag . '}', $value, $body ); } return array( 'subject' => $subject, 'body' => $body, ); } /** * Wrap rendered body HTML in the shared branded layout: header * (logo or site name on an accent-colored bar), the email content, * and a footer with a copyright line. * * @param string $body_html Already-rendered (tag-substituted, wpautop'd) body HTML. * @return string Full HTML document ready to hand to wp_mail(). */ public static function wrap_html( $body_html ) { $layout = self::get_layout_settings(); if ( 'logo' === $layout['header_type'] && $layout['header_logo'] ) { $header_html = '' . esc_attr( get_bloginfo( 'name' ) ) . ''; } else { $header_html = '' . esc_html( $layout['header_text'] ) . ''; } $footer_text = str_replace( array( '{year}', '{site_name}' ), array( gmdate( 'Y' ), get_bloginfo( 'name' ) ), $layout['footer_text'] ); $accent = sanitize_hex_color( $layout['accent_color'] ); $accent = $accent ? $accent : '#1f4d3a'; ob_start(); ?> <?php echo esc_html( get_bloginfo( 'name' ) ); ?>
s // without disturbing content that's already valid HTML. $html_body = self::wrap_html( wpautop( $rendered['body'] ) ); add_filter( 'wp_mail_content_type', array( __CLASS__, 'set_html_content_type' ) ); $sent = wp_mail( $to, $rendered['subject'], $html_body, $headers ); remove_filter( 'wp_mail_content_type', array( __CLASS__, 'set_html_content_type' ) ); return $sent; } }