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

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