This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
forked from deliciousbrains/wp-offload-ses-lite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwp-ses.php
167 lines (137 loc) · 4.66 KB
/
wp-ses.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/*
Plugin Name: WP Offload SES Lite
Description: Automatically send WordPress mail through Amazon SES (Simple Email Service).
Author: Delicious Brains
Version: 1.2.1
Author URI: https://deliciousbrains.com/
Network: True
Text Domain: wp-offload-ses
Domain Path: /languages/
// Copyright (c) 2018 Delicious Brains. All rights reserved.
//
// Released under the GPL license
// http://www.opensource.org/licenses/gpl-license.php
//
// **********************************************************************
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************
*/
use DeliciousBrains\WP_Offload_SES\WP_Offload_SES;
use DeliciousBrains\WP_Offload_SES\Compatibility_Check;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$GLOBALS['wposes_meta']['wp-offload-ses-lite']['version'] = '1.2.1';
if ( ! class_exists( 'DeliciousBrains\WP_Offload_SES\Compatibility_Check' ) ) {
require_once wposes_lite_get_plugin_dir_path() . '/classes/Compatibility-Check.php';
}
global $wposes_compat_check;
$wposes_compat_check = new DeliciousBrains\WP_Offload_SES\Compatibility_Check(
'WP Offload SES Lite',
'wp-offload-ses-lite',
__FILE__
);
add_action( 'activated_plugin', array( $wposes_compat_check, 'deactivate_other_instances' ) );
/**
* Initiate the WP Offload SES plugin.
*/
function wp_offload_ses_lite_init() {
if ( class_exists( 'DeliciousBrains\WP_Offload_SES\WP_Offload_SES' ) ) {
return;
}
/** @var WP_Offload_SES $wp_offload_ses */
global $wp_offload_ses;
/** @var Compatibility_Check $wposes_compat_check */
global $wposes_compat_check;
if ( $wposes_compat_check->is_plugin_active( 'wp-offload-ses/wp-offload-ses.php' ) ) {
// Don't load if the pro version is installed.
return;
}
if ( ! $wposes_compat_check->is_compatible() ) {
return;
}
$abspath = wposes_lite_get_plugin_dir_path();
// Load autoloaders.
require_once $abspath . '/vendor/Aws3/aws-autoloader.php';
require_once $abspath . '/classes/Autoloader.php';
new DeliciousBrains\WP_Offload_SES\Autoloader( 'WP_Offload_SES', $abspath );
// Kick off the plugin.
$wp_offload_ses = new DeliciousBrains\WP_Offload_SES\WP_Offload_SES( __FILE__ );
return $wp_offload_ses;
}
add_action( 'init', 'wp_offload_ses_lite_init', 1 );
/**
* Gets the path to the plugin files.
*
* @return string
*/
function wposes_lite_get_plugin_dir_path() {
$abspath = wp_normalize_path( dirname( __FILE__ ) );
$mu_path = wp_normalize_path( WPMU_PLUGIN_DIR );
if ( $mu_path === $abspath ) {
$abspath = $abspath . '/wp-ses/';
}
return $abspath;
}
/**
* Check whether we should send mail via SES.
*
* @return bool
*/
function wposes_lite_sending_enabled() {
if ( defined( 'WPOSES_SETTINGS' ) ) {
$defined_settings = maybe_unserialize( constant( 'WPOSES_SETTINGS' ) );
if ( isset( $defined_settings['send-via-ses'] ) ) {
return (bool) $defined_settings['send-via-ses'];
}
}
$settings = get_option( 'wposes_settings' );
// Single sites & multisite subsites.
if ( isset( $settings['send-via-ses'] ) ) {
return (bool) $settings['send-via-ses'];
}
// If subsite isn't configured with an override, go with network setting.
if ( is_multisite() ) {
$network_settings = get_site_option( 'wposes_settings' );
if ( isset( $network_settings['send-via-ses'] ) ) {
return (bool) $network_settings['send-via-ses'];
}
}
return false;
}
/*
* Override wp_mail if SES enabled
*/
if ( ! function_exists( 'wp_mail' ) ) {
if ( wposes_lite_sending_enabled() ) {
/**
* Send mail via Amazon SES.
*
* @param string|array $to Array or comma-separated list of email addresses.
* @param string $subject Email subject.
* @param string $message Email message.
* @param string|array $headers Optional. Additional headers.
* @param string|array $attachments Optional. Files to attach.
*
* @return bool
*/
function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
/** @var WP_Offload_SES $wp_offload_ses */
global $wp_offload_ses;
if ( is_null( $wp_offload_ses ) ) {
$wp_offload_ses = wp_offload_ses_lite_init();
}
return $wp_offload_ses->mail_handler( $to, $subject, $message, $headers, $attachments );
}
}
} else {
global $pagenow;
if ( ! in_array( $pagenow, array( 'plugins.php', 'update-core.php' ), true ) ) {
require_once dirname( __FILE__ ) . '/classes/Error.php';
new DeliciousBrains\WP_Offload_SES\Error( DeliciousBrains\WP_Offload_SES\Error::$mail_function_exists, 'Mail function already overridden.' );
}
}