PluginProbe
WP Offload SES Lite / 1.7.2
WP Offload SES Lite v1.7.2
1.8.2 trunk 0.1.2 0.2.1 0.7.2.1 0.8.2 1.0 1.1 1.2 1.2.1 1.2.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
wp-ses / wp-ses.php

wp-ses.php in WP Offload SES Lite 1.7.2, at wp-ses.php

203 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Offload SES Lite
4 Description: Automatically send WordPress mail through Amazon SES (Simple Email Service).
5 Author: Delicious Brains
6 Version: 1.7.2
7 Author URI: https://deliciousbrains.com/
8 Plugin URI: https://deliciousbrains.com/
9 Network: True
10 Text Domain: wp-offload-ses
11 Domain Path: /languages/
12
13 // Copyright (c) 2018 Delicious Brains. All rights reserved.
14 //
15 // Released under the GPL license
16 // http://www.opensource.org/licenses/gpl-license.php
17 //
18 // **********************************************************************
19 // This program is distributed in the hope that it will be useful, but
20 // WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 // **********************************************************************
23 */
24
25 use DeliciousBrains\WP_Offload_SES\Utils;
26 use DeliciousBrains\WP_Offload_SES\WP_Offload_SES;
27 use DeliciousBrains\WP_Offload_SES\Compatibility_Check;
28
29 // Exit if accessed directly.
30 if ( ! defined( 'ABSPATH' ) ) {
31 exit;
32 }
33
34 // Avoid clash with WP Offload SES (Pro) if both installed as must-use plugins.
35 if ( defined( 'WPOSES_FILE' ) ) {
36 return;
37 }
38
39 $GLOBALS['wposes_meta']['wp-ses']['version'] = '1.7.2';
40
41 if ( ! defined( 'WPOSESLITE_FILE' ) ) {
42 // Defines the path to the main plugin file.
43 define( 'WPOSESLITE_FILE', __FILE__ );
44
45 // Defines the path to be used for includes.
46 define( 'WPOSESLITE_PATH', wposes_lite_get_plugin_dir_path() );
47 }
48
49 if ( ! class_exists( 'DeliciousBrains\WP_Offload_SES\Compatibility_Check' ) ) {
50 require_once WPOSESLITE_PATH . 'classes/Compatibility-Check.php';
51 }
52
53 global $wposes_compat_check;
54 $wposes_compat_check = new DeliciousBrains\WP_Offload_SES\Compatibility_Check(
55 'WP Offload SES Lite',
56 'wp-ses',
57 WPOSESLITE_FILE
58 );
59
60 add_action( 'activated_plugin', array( $wposes_compat_check, 'deactivate_other_instances' ) );
61
62 /**
63 * Initiate the WP Offload SES plugin.
64 */
65 function wp_offload_ses_lite_init() {
66 if ( class_exists( 'DeliciousBrains\WP_Offload_SES\WP_Offload_SES' ) ) {
67 return;
68 }
69
70 /** @var WP_Offload_SES $wp_offload_ses */
71 global $wp_offload_ses;
72
73 /** @var Compatibility_Check $wposes_compat_check */
74 global $wposes_compat_check;
75
76 if ( $wposes_compat_check->is_plugin_active( 'wp-offload-ses/wp-offload-ses.php' ) ) {
77 // Don't load if the pro version is installed.
78 return;
79 }
80
81 if ( ! $wposes_compat_check->is_compatible() ) {
82 return;
83 }
84
85 // Prevent error in Guzzle when PHP doesn't have the intl extension.
86 if ( ! function_exists( 'idn_to_ascii' ) && ! defined( 'IDNA_DEFAULT' ) ) {
87 define( 'IDNA_DEFAULT', 0 );
88 }
89
90 // Load autoloaders.
91 require_once WPOSESLITE_PATH . 'vendor/Aws3/aws-autoloader.php';
92 require_once WPOSESLITE_PATH . 'classes/Autoloader.php';
93 new DeliciousBrains\WP_Offload_SES\Autoloader( 'WP_Offload_SES', WPOSESLITE_PATH );
94
95 // Load compatibility functions for older PHP (< 8.0) and WordPress (< 5.9).
96 require_once WPOSESLITE_PATH . 'includes/compat.php';
97
98 // Kick off the plugin.
99 $wp_offload_ses = new DeliciousBrains\WP_Offload_SES\WP_Offload_SES( WPOSESLITE_FILE );
100
101 return $wp_offload_ses;
102 }
103
104 add_action( 'init', 'wp_offload_ses_lite_init', 1 );
105
106 /**
107 * Gets the path to the plugin files.
108 *
109 * @return string
110 */
111 function wposes_lite_get_plugin_dir_path() {
112 $abspath = wp_normalize_path( dirname( WPOSESLITE_FILE ) );
113 $mu_path = $abspath . '/wp-ses';
114 $core_class = '/classes/WP-Offload-SES.php';
115
116 // Is entry point file in directory above where plugin's files are?
117 if ( file_exists( $mu_path . $core_class ) ) {
118 $abspath = $mu_path;
119 }
120
121 return trailingslashit( $abspath );
122 }
123
124 /**
125 * Check whether we should send mail via SES.
126 *
127 * @return bool
128 */
129 function wposes_lite_sending_enabled() {
130 if ( defined( 'WPOSES_SETTINGS' ) ) {
131 require_once WPOSESLITE_PATH . 'classes/Utils.php';
132 $defined_settings = Utils::maybe_unserialize( constant( 'WPOSES_SETTINGS' ) );
133
134 if ( isset( $defined_settings['send-via-ses'] ) ) {
135 return (bool) $defined_settings['send-via-ses'];
136 }
137 }
138
139 $settings = get_option( 'wposes_settings' );
140
141 // Single sites & multisite subsites.
142 if ( isset( $settings['send-via-ses'] ) ) {
143 return (bool) $settings['send-via-ses'];
144 }
145
146 // If subsite isn't configured with an override, go with network setting.
147 if ( is_multisite() ) {
148 $network_settings = get_site_option( 'wposes_settings' );
149
150 if ( isset( $network_settings['send-via-ses'] ) ) {
151 return (bool) $network_settings['send-via-ses'];
152 }
153 }
154
155 return false;
156 }
157
158 // Override `wp_mail()` if sending via SES is enabled.
159 if ( ! function_exists( 'wp_mail' ) ) {
160 if ( wposes_lite_sending_enabled() ) {
161 /**
162 * Send mail via Amazon SES.
163 *
164 * @param string|array $to Array or comma-separated list of email addresses.
165 * @param string $subject Email subject.
166 * @param string $message Email message.
167 * @param string|array $headers Optional. Additional headers.
168 * @param string|array $attachments Optional. Files to attach.
169 *
170 * @return bool
171 */
172 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
173 /** @var WP_Offload_SES $wp_offload_ses */
174 global $wp_offload_ses;
175
176 if ( is_null( $wp_offload_ses ) ) {
177 $wp_offload_ses = wp_offload_ses_lite_init();
178 }
179
180 // Could not initialize plugin.
181 if ( is_null( $wp_offload_ses ) ) {
182 return false;
183 }
184
185 return $wp_offload_ses->mail_handler( $to, $subject, $message, $headers, $attachments );
186 }
187 }
188 } else {
189 global $pagenow;
190
191 if ( ! in_array( $pagenow, array( 'plugins.php', 'update-core.php' ), true ) ) {
192 require_once WPOSESLITE_PATH . 'classes/Error.php';
193 new DeliciousBrains\WP_Offload_SES\Error(
194 DeliciousBrains\WP_Offload_SES\Error::$mail_function_exists,
195 'Mail function already overridden.'
196 );
197 }
198 }
199
200 if ( file_exists( WPOSESLITE_PATH . 'ext/wposes-ext-functions.php' ) ) {
201 require_once WPOSESLITE_PATH . 'ext/wposes-ext-functions.php';
202 }
203