/** * Add template sections as email variables * * @param FUE_Email $email */ public function add_template_sections_to_variables($email) { if (empty($email->template)) { return; } $tpl = new FUE_Email_Template($email->template); foreach ($tpl->get_sections() as $section) { ?> <li class="var hideable var_template_section"><strong>{section:<?php echo $section; ?> }...{/section}</strong> <img class="help_tip" title="<?php _e('Email template section', 'follow_up_emails'); ?> " src="<?php echo FUE_TEMPLATES_URL; ?> /images/help.png" width="16" height="16" /></li> <?php } }
/** * Get a list of the installed templates * @return array */ public function get_templates() { $templates = fue_get_installed_templates(); $output = array(); foreach ($templates as $template) { $tpl = new FUE_Email_Template($template); $output[] = array('template' => array('id' => basename($template), 'name' => $tpl->name, 'sections' => $tpl->get_sections())); } return $output; }
/** * Split the $message into sections and apply the sections to the template * * @param string $message If passed, this will be used as the source of the sections * @return string The modified message with all the sections replaced */ public function apply_template($message = null) { if (is_null($message)) { $message = $this->message; } if (empty($this->template)) { // no template set. simply return the message return $message; } $tpl = new FUE_Email_Template($this->template); $sections = $tpl->get_sections(); $contents = $tpl->get_contents(); if (empty($contents)) { // nothing to process return $message; } foreach ($sections as $section) { $section_body = fue_str_search('{section:' . $section . '}', '{/section}', $message); if (!empty($section_body)) { $contents = str_replace('{section:' . $section . '}', $section_body[0], $contents); } } // remove unused sections from $contents foreach ($sections as $section) { $contents = str_replace('{section:' . $section . '}', '', $contents); } return apply_filters('fue_email_apply_template', $contents, $this); }