PluginProbe
WP Offload SES Lite / 1.7.0
WP Offload SES Lite v1.7.0
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.0, at wp-ses.php

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