mailer.php
63 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; // Exit if accessed directly. |
| 4 | } |
| 5 | |
| 6 | |
| 7 | if ( ! class_exists( 'OsMailer' ) ) : |
| 8 | |
| 9 | class OsMailer { |
| 10 | |
| 11 | protected $views_folder = LATEPOINT_VIEWS_MAILERS_ABSPATH, |
| 12 | $vars = array(), |
| 13 | $layout = 'mailer', |
| 14 | $headers = []; |
| 15 | |
| 16 | public static function send_email($to, $subject, $message, $headers){ |
| 17 | if(!OsSettingsHelper::is_email_allowed()) return true; |
| 18 | return wp_mail($to, $subject, $message, $headers); |
| 19 | } |
| 20 | |
| 21 | function get_headers(){ |
| 22 | return $this->headers; |
| 23 | } |
| 24 | |
| 25 | function get_view_uri($view_name){ |
| 26 | return $this->views_folder.$view_name.'.php'; |
| 27 | } |
| 28 | |
| 29 | function __construct(){ |
| 30 | $this->headers[] = 'Content-Type: text/html; charset=UTF-8'; |
| 31 | $this->headers[] = 'From: '.OsNotificationsHelper::get_email_headers_from(); |
| 32 | } |
| 33 | |
| 34 | function set_layout($layout = 'mailer'){ |
| 35 | if(isset($this->params['layout'])){ |
| 36 | $this->layout = $this->params['layout']; |
| 37 | }else{ |
| 38 | $this->layout = $layout; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | function get_layout(){ |
| 43 | return $this->layout; |
| 44 | } |
| 45 | |
| 46 | function render($view, $extra_vars = array()){ |
| 47 | $view = $this->get_view_uri($view); |
| 48 | extract($this->vars); |
| 49 | extract($extra_vars); |
| 50 | ob_start(); |
| 51 | if($this->get_layout() != 'none'){ |
| 52 | // rendering layout, view variable will be passed and used in layout file |
| 53 | include LATEPOINT_VIEWS_LAYOUTS_ABSPATH . OsRouterHelper::add_extension($this->get_layout(), '.php'); |
| 54 | }else{ |
| 55 | include OsRouterHelper::add_extension($view, '.php'); |
| 56 | } |
| 57 | $response_html = ob_get_clean(); |
| 58 | return $response_html; |
| 59 | } |
| 60 | |
| 61 | } |
| 62 | |
| 63 | endif; |