mailer.php
65 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() ) { |
| 18 | return true; |
| 19 | } |
| 20 | return wp_mail( $to, $subject, $message, $headers ); |
| 21 | } |
| 22 | |
| 23 | function get_headers() { |
| 24 | return $this->headers; |
| 25 | } |
| 26 | |
| 27 | function get_view_uri( $view_name ) { |
| 28 | return $this->views_folder . $view_name . '.php'; |
| 29 | } |
| 30 | |
| 31 | function __construct() { |
| 32 | $this->headers[] = 'Content-Type: text/html; charset=UTF-8'; |
| 33 | $this->headers[] = 'From: ' . OsNotificationsHelper::get_email_headers_from(); |
| 34 | } |
| 35 | |
| 36 | function set_layout( $layout = 'mailer' ) { |
| 37 | if ( isset( $this->params['layout'] ) ) { |
| 38 | $this->layout = $this->params['layout']; |
| 39 | } else { |
| 40 | $this->layout = $layout; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | function get_layout() { |
| 45 | return $this->layout; |
| 46 | } |
| 47 | |
| 48 | function render( $view, $extra_vars = array() ) { |
| 49 | $view = $this->get_view_uri( $view ); |
| 50 | extract( $this->vars ); |
| 51 | extract( $extra_vars ); |
| 52 | ob_start(); |
| 53 | if ( $this->get_layout() != 'none' ) { |
| 54 | // rendering layout, view variable will be passed and used in layout file |
| 55 | include LATEPOINT_VIEWS_LAYOUTS_ABSPATH . OsRouterHelper::add_extension( $this->get_layout(), '.php' ); |
| 56 | } else { |
| 57 | include OsRouterHelper::add_extension( $view, '.php' ); |
| 58 | } |
| 59 | $response_html = ob_get_clean(); |
| 60 | return $response_html; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | endif; |
| 65 |