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

168 lines 4.6 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.3
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\WP_Offload_SES;
25 use DeliciousBrains\WP_Offload_SES\Compatibility_Check;
26
27 // Exit if accessed directly.
28 if ( ! defined( 'ABSPATH' ) ) {
29 exit;
30 }
31
32 $GLOBALS['wposes_meta']['wp-ses']['version'] = '1.3';
33
34 if ( ! class_exists( 'DeliciousBrains\WP_Offload_SES\Compatibility_Check' ) ) {
35 require_once wposes_lite_get_plugin_dir_path() . '/classes/Compatibility-Check.php';
36 }
37
38 global $wposes_compat_check;
39 $wposes_compat_check = new DeliciousBrains\WP_Offload_SES\Compatibility_Check(
40 'WP Offload SES Lite',
41 'wp-offload-ses-lite',
42 __FILE__
43 );
44
45 add_action( 'activated_plugin', array( $wposes_compat_check, 'deactivate_other_instances' ) );
46
47 /**
48 * Initiate the WP Offload SES plugin.
49 */
50 function wp_offload_ses_lite_init() {
51 if ( class_exists( 'DeliciousBrains\WP_Offload_SES\WP_Offload_SES' ) ) {
52 return;
53 }
54
55 /** @var WP_Offload_SES $wp_offload_ses */
56 global $wp_offload_ses;
57
58 /** @var Compatibility_Check $wposes_compat_check */
59 global $wposes_compat_check;
60
61 if ( $wposes_compat_check->is_plugin_active( 'wp-offload-ses/wp-offload-ses.php' ) ) {
62 // Don't load if the pro version is installed.
63 return;
64 }
65
66 if ( ! $wposes_compat_check->is_compatible() ) {
67 return;
68 }
69
70 $abspath = wposes_lite_get_plugin_dir_path();
71
72 // Load autoloaders.
73 require_once $abspath . '/vendor/Aws3/aws-autoloader.php';
74 require_once $abspath . '/classes/Autoloader.php';
75 new DeliciousBrains\WP_Offload_SES\Autoloader( 'WP_Offload_SES', $abspath );
76
77 // Kick off the plugin.
78 $wp_offload_ses = new DeliciousBrains\WP_Offload_SES\WP_Offload_SES( __FILE__ );
79
80 return $wp_offload_ses;
81 }
82 add_action( 'init', 'wp_offload_ses_lite_init', 1 );
83
84 /**
85 * Gets the path to the plugin files.
86 *
87 * @return string
88 */
89 function wposes_lite_get_plugin_dir_path() {
90 $abspath = wp_normalize_path( dirname( __FILE__ ) );
91 $mu_path = wp_normalize_path( WPMU_PLUGIN_DIR );
92
93 if ( $mu_path === $abspath ) {
94 $abspath = $abspath . '/wp-ses/';
95 }
96
97 return $abspath;
98 }
99
100 /**
101 * Check whether we should send mail via SES.
102 *
103 * @return bool
104 */
105 function wposes_lite_sending_enabled() {
106 if ( defined( 'WPOSES_SETTINGS' ) ) {
107 $defined_settings = maybe_unserialize( constant( 'WPOSES_SETTINGS' ) );
108
109 if ( isset( $defined_settings['send-via-ses'] ) ) {
110 return (bool) $defined_settings['send-via-ses'];
111 }
112 }
113
114 $settings = get_option( 'wposes_settings' );
115
116 // Single sites & multisite subsites.
117 if ( isset( $settings['send-via-ses'] ) ) {
118 return (bool) $settings['send-via-ses'];
119 }
120
121 // If subsite isn't configured with an override, go with network setting.
122 if ( is_multisite() ) {
123 $network_settings = get_site_option( 'wposes_settings' );
124
125 if ( isset( $network_settings['send-via-ses'] ) ) {
126 return (bool) $network_settings['send-via-ses'];
127 }
128 }
129
130 return false;
131 }
132
133 /*
134 * Override wp_mail if SES enabled
135 */
136 if ( ! function_exists( 'wp_mail' ) ) {
137 if ( wposes_lite_sending_enabled() ) {
138 /**
139 * Send mail via Amazon SES.
140 *
141 * @param string|array $to Array or comma-separated list of email addresses.
142 * @param string $subject Email subject.
143 * @param string $message Email message.
144 * @param string|array $headers Optional. Additional headers.
145 * @param string|array $attachments Optional. Files to attach.
146 *
147 * @return bool
148 */
149 function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) {
150 /** @var WP_Offload_SES $wp_offload_ses */
151 global $wp_offload_ses;
152
153 if ( is_null( $wp_offload_ses ) ) {
154 $wp_offload_ses = wp_offload_ses_lite_init();
155 }
156
157 return $wp_offload_ses->mail_handler( $to, $subject, $message, $headers, $attachments );
158 }
159 }
160 } else {
161 global $pagenow;
162
163 if ( ! in_array( $pagenow, array( 'plugins.php', 'update-core.php' ), true ) ) {
164 require_once dirname( __FILE__ ) . '/classes/Error.php';
165 new DeliciousBrains\WP_Offload_SES\Error( DeliciousBrains\WP_Offload_SES\Error::$mail_function_exists, 'Mail function already overridden.' );
166 }
167 }
168