-
Notifications
You must be signed in to change notification settings - Fork 0
/
fitpress-mandrill.php
102 lines (78 loc) · 2.15 KB
/
fitpress-mandrill.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* @package FitPress
*/
/*
Plugin Name: FitPress Mandrill
Plugin URI: http://fitpress.co.za
Description: Integrates FitPress to send mails via Mandrill.
Version: 1.0
Author: Leaps + Bounds
Author URI: https://leapsandbounds.io
License: GPLv2 or later
Text Domain: fitpress-payfast
*/
if ( ! defined( 'ABSPATH' ) ) :
exit; // Exit if accessed directly
endif;
function is_fitpress_active_for_mandrill(){
/**
* Check if WooCommerce is active, and if it isn't, disable Subscriptions.
*
* @since 1.0
*/
if ( !is_plugin_active( 'fitpress/fitpress.php' ) ) {
add_action( 'admin_notices', 'FP_Mandrill::fitpress_inactive_notice' );
deactivate_plugins( plugin_basename( __FILE__ ) );
}
}
add_action( 'admin_init', 'is_fitpress_active_for_mandrill' );
class FP_Mandrill {
/**
* @var FitPress The single instance of the class
* @since 1.0
*/
protected static $_instance = null;
protected $mandrill_username;
protected $mandrill_api_key;
/**
* Main FitPress Instance
*
* Ensures only one instance of FitPress is loaded or can be loaded.
*
* @since 1.0
* @static
* @see WC()
* @return FitPress - Main instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct() {
$this->mandrill_username = '';
$this->mandrill_api_key = '';
add_action( 'phpmailer_init', array( $this, 'use_mandrill' ) );
}
public function use_mandrill( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = "tls";
$phpmailer->Host = "smtp.mandrillapp.com";
$phpmailer->Port = "587";
$phpmailer->Username = $this->mandrill_username;
$phpmailer->Password = $this->mandrill_api_key;
$phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', 'X-MC-ReturnPathDomain', 'track.fitpress.co.za' ) );
$phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', 'X-MC-Subaccount', 'FitPress' ) );
}
}
/**
* Extension main function
*/
function __fp_mandrill_main() {
FP_Mandrill::instance();
}
// Initialize plugin when plugins are loaded
add_action( 'plugins_loaded', '__fp_mandrill_main' );