| 1 |
<?php |
| 2 |
namespace WeDevs\ERP; |
| 3 |
|
| 4 |
/** |
| 5 |
* Emailer Class |
| 6 |
*/ |
| 7 |
class Emailer { |
| 8 |
|
| 9 |
public $emails; |
| 10 |
|
| 11 |
/** |
| 12 |
* Initializes the WeDevs_ERP() class |
| 13 |
* |
| 14 |
* Checks for an existing WeDevs_ERP() instance |
| 15 |
* and if it doesn't find one, creates it. |
| 16 |
*/ |
| 17 |
public static function init() { |
| 18 |
static $instance = false; |
| 19 |
|
| 20 |
if ( ! $instance ) { |
| 21 |
$instance = new self(); |
| 22 |
} |
| 23 |
|
| 24 |
return $instance; |
| 25 |
} |
| 26 |
|
| 27 |
public function __construct() { |
| 28 |
|
| 29 |
// Email Header, Footer and content hooks |
| 30 |
add_action( 'erp_email_header', array( $this, 'email_header' ) ); |
| 31 |
add_action( 'erp_email_footer', array( $this, 'email_footer' ) ); |
| 32 |
|
| 33 |
// Let 3rd parties unhook the above via this hook |
| 34 |
do_action( 'erp_email', $this ); |
| 35 |
} |
| 36 |
|
| 37 |
function init_emails() { |
| 38 |
$this->emails = apply_filters( 'erp_email_classes', $this->emails ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Return the email classes - used in admin to load settings. |
| 43 |
* |
| 44 |
* @return array |
| 45 |
*/ |
| 46 |
public function get_emails() { |
| 47 |
return $this->emails; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Get an registered email instance |
| 52 |
* |
| 53 |
* @param string $class_name |
| 54 |
* |
| 55 |
* @return \Email|false |
| 56 |
*/ |
| 57 |
public function get_email( $class_name ) { |
| 58 |
if ( $this->emails && array_key_exists( $class_name, $this->emails ) ) { |
| 59 |
return $this->emails[ $class_name ]; |
| 60 |
} |
| 61 |
|
| 62 |
return false; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Get the email header. |
| 67 |
* |
| 68 |
* @param mixed $email_heading heading for the email |
| 69 |
*/ |
| 70 |
public function email_header( $email_heading ) { |
| 71 |
include WPERP_INCLUDES . '/email/email-header.php'; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Get the email footer. |
| 76 |
*/ |
| 77 |
public function email_footer() { |
| 78 |
include WPERP_INCLUDES . '/email/email-footer.php'; |
| 79 |
} |
| 80 |
} |
| 81 |
|