Version Description
- 2018-01-28 =
- Fixed: Improved escaping with debug reporting.
Download this release
Release Info
Developer | slaFFik |
Plugin | ![]() |
Version | 1.2.4 |
Comparing to | |
See all releases |
Code changes from version 1.2.3 to 1.2.4
- class-wpms-am-notification.php +450 -450
- readme.txt +351 -348
- src/AM_Notification.php +452 -452
- src/Admin/Area.php +457 -457
- src/Admin/PageAbstract.php +66 -66
- src/Admin/PageInterface.php +45 -45
- src/Admin/Pages/Auth.php +59 -59
- src/Admin/Pages/Misc.php +99 -99
- src/Admin/Pages/Settings.php +250 -250
- src/Admin/Pages/Test.php +216 -216
- src/Core.php +239 -239
- src/Debug.php +118 -118
- src/MailCatcher.php +69 -69
- src/Migration.php +245 -245
- src/Options.php +596 -596
- src/Processor.php +175 -175
- src/Providers/AuthAbstract.php +22 -22
- src/Providers/AuthInterface.php +19 -19
- src/Providers/Gmail/Auth.php +321 -321
- src/Providers/Gmail/Mailer.php +162 -162
- src/Providers/Gmail/Options.php +131 -131
- src/Providers/Loader.php +182 -182
- src/Providers/Mail/Mailer.php +35 -35
- src/Providers/Mail/Options.php +42 -42
- src/Providers/MailerAbstract.php +366 -366
- src/Providers/MailerInterface.php +74 -74
- src/Providers/Mailgun/Mailer.php +344 -344
- src/Providers/Mailgun/Options.php +106 -106
- src/Providers/OptionsAbstract.php +312 -312
- src/Providers/OptionsInterface.php +64 -64
- src/Providers/Pepipost/Mailer.php +15 -15
- src/Providers/Pepipost/Options.php +29 -29
- src/Providers/SMTP/Mailer.php +15 -15
- src/Providers/SMTP/Options.php +45 -45
- src/Providers/Sendgrid/Mailer.php +344 -344
- src/Providers/Sendgrid/Options.php +89 -89
- src/Upgrade.php +71 -71
- src/WP.php +140 -140
- wp-mail-smtp.php +80 -80
- wp_mail_smtp.php +856 -856
class-wpms-am-notification.php
CHANGED
@@ -1,450 +1,450 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Awesome Motive Notifications
|
5 |
-
*
|
6 |
-
* This creates a custom post type (if it doesn't exist) and calls the API to
|
7 |
-
* retrieve notifications for this product.
|
8 |
-
*
|
9 |
-
* @package AwesomeMotive
|
10 |
-
* @author Benjamin Rojas
|
11 |
-
* @license GPL-2.0+
|
12 |
-
* @copyright Copyright (c) 2017, Retyp LLC
|
13 |
-
* @version 1.0.2
|
14 |
-
*/
|
15 |
-
class WPMS_AM_Notification {
|
16 |
-
/**
|
17 |
-
* The api url we are calling.
|
18 |
-
*
|
19 |
-
* @since 1.0.0
|
20 |
-
*
|
21 |
-
* @var string
|
22 |
-
*/
|
23 |
-
public $api_url = 'https://api.awesomemotive.com/v1/notification/';
|
24 |
-
|
25 |
-
/**
|
26 |
-
* A unique slug for this plugin.
|
27 |
-
* (Not the WordPress plugin slug)
|
28 |
-
*
|
29 |
-
* @since 1.0.0
|
30 |
-
*
|
31 |
-
* @var string
|
32 |
-
*/
|
33 |
-
public $plugin;
|
34 |
-
|
35 |
-
/**
|
36 |
-
* The current plugin version.
|
37 |
-
*
|
38 |
-
* @since 1.0.0
|
39 |
-
*
|
40 |
-
* @var string
|
41 |
-
*/
|
42 |
-
public $plugin_version;
|
43 |
-
|
44 |
-
/**
|
45 |
-
* Flag if a notice has been registered.
|
46 |
-
*
|
47 |
-
* @since 1.0.0
|
48 |
-
*
|
49 |
-
* @var bool
|
50 |
-
*/
|
51 |
-
public static $registered = false;
|
52 |
-
|
53 |
-
/**
|
54 |
-
* Construct.
|
55 |
-
*
|
56 |
-
* @since 1.0.0
|
57 |
-
*
|
58 |
-
* @param string $plugin The plugin slug.
|
59 |
-
* @param mixed $version The version of the plugin.
|
60 |
-
*/
|
61 |
-
public function __construct( $plugin = '', $version = 0 ) {
|
62 |
-
$this->plugin = $plugin;
|
63 |
-
$this->plugin_version = $version;
|
64 |
-
|
65 |
-
add_action( 'init', array( $this, 'custom_post_type' ) );
|
66 |
-
add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
|
67 |
-
add_action( 'admin_notices', array( $this, 'display_notifications' ) );
|
68 |
-
add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
|
69 |
-
}
|
70 |
-
|
71 |
-
/**
|
72 |
-
* Registers a custom post type.
|
73 |
-
*
|
74 |
-
* @since 1.0.0
|
75 |
-
*/
|
76 |
-
public function custom_post_type() {
|
77 |
-
register_post_type( 'amn_' . $this->plugin, array(
|
78 |
-
'label' => $this->plugin . ' Announcements',
|
79 |
-
'can_export' => false,
|
80 |
-
'supports' => false,
|
81 |
-
) );
|
82 |
-
}
|
83 |
-
|
84 |
-
/**
|
85 |
-
* Retrieve the remote notifications if the time has expired.
|
86 |
-
*
|
87 |
-
* @since 1.0.0
|
88 |
-
*/
|
89 |
-
public function get_remote_notifications() {
|
90 |
-
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
91 |
-
return;
|
92 |
-
}
|
93 |
-
|
94 |
-
$last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
|
95 |
-
|
96 |
-
if ( $last_checked < strtotime( 'today midnight' ) ) {
|
97 |
-
$plugin_notifications = $this->get_plugin_notifications( 1 );
|
98 |
-
$notification_id = null;
|
99 |
-
|
100 |
-
if ( ! empty( $plugin_notifications ) ) {
|
101 |
-
// Unset it from the array.
|
102 |
-
$notification = $plugin_notifications[0];
|
103 |
-
$notification_id = get_post_meta( $notification->ID, 'notification_id', true );
|
104 |
-
}
|
105 |
-
|
106 |
-
$response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
|
107 |
-
'body' => array(
|
108 |
-
'slug' => $this->plugin,
|
109 |
-
'version' => $this->plugin_version,
|
110 |
-
'last_notification' => $notification_id,
|
111 |
-
),
|
112 |
-
) ) );
|
113 |
-
|
114 |
-
$data = json_decode( $response );
|
115 |
-
|
116 |
-
if ( ! empty( $data->id ) ) {
|
117 |
-
$notifications = array();
|
118 |
-
|
119 |
-
foreach ( (array) $data->slugs as $slug ) {
|
120 |
-
$notifications = array_merge(
|
121 |
-
$notifications,
|
122 |
-
(array) get_posts(
|
123 |
-
array(
|
124 |
-
'post_type' => 'amn_' . $slug,
|
125 |
-
'post_status' => 'all',
|
126 |
-
'meta_key' => 'notification_id',
|
127 |
-
'meta_value' => $data->id,
|
128 |
-
)
|
129 |
-
)
|
130 |
-
);
|
131 |
-
}
|
132 |
-
|
133 |
-
if ( empty( $notifications ) ) {
|
134 |
-
$new_notification_id = wp_insert_post( array(
|
135 |
-
'post_content' => wp_kses_post( $data->content ),
|
136 |
-
'post_type' => 'amn_' . $this->plugin,
|
137 |
-
) );
|
138 |
-
|
139 |
-
update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
|
140 |
-
update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
|
141 |
-
update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
|
142 |
-
update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
|
143 |
-
update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
|
144 |
-
update_post_meta( $new_notification_id, 'viewed', 0 );
|
145 |
-
update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
|
146 |
-
update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
|
147 |
-
}
|
148 |
-
}
|
149 |
-
|
150 |
-
// Possibly revoke notifications.
|
151 |
-
if ( ! empty( $data->revoked ) ) {
|
152 |
-
$this->revoke_notifications( $data->revoked );
|
153 |
-
}
|
154 |
-
|
155 |
-
// Set the option now so we can't run this again until after 24 hours.
|
156 |
-
update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
|
157 |
-
}
|
158 |
-
}
|
159 |
-
|
160 |
-
/**
|
161 |
-
* Get local plugin notifications that have already been set.
|
162 |
-
*
|
163 |
-
* @since 1.0.0
|
164 |
-
*
|
165 |
-
* @param integer $limit Set the limit for how many posts to retrieve.
|
166 |
-
* @param array $args Any top-level arguments to add to the array.
|
167 |
-
*
|
168 |
-
* @return WP_Post[] WP_Post that match the query.
|
169 |
-
*/
|
170 |
-
public function get_plugin_notifications( $limit = -1, $args = array() ) {
|
171 |
-
return get_posts(
|
172 |
-
array(
|
173 |
-
'posts_per_page' => $limit,
|
174 |
-
'post_type' => 'amn_' . $this->plugin,
|
175 |
-
) + $args
|
176 |
-
);
|
177 |
-
}
|
178 |
-
|
179 |
-
/**
|
180 |
-
* Display any notifications that should be displayed.
|
181 |
-
*
|
182 |
-
* @since 1.0.0
|
183 |
-
*/
|
184 |
-
public function display_notifications() {
|
185 |
-
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
186 |
-
return;
|
187 |
-
}
|
188 |
-
|
189 |
-
$plugin_notifications = $this->get_plugin_notifications( -1, array(
|
190 |
-
'post_status' => 'all',
|
191 |
-
'meta_key' => 'viewed',
|
192 |
-
'meta_value' => '0',
|
193 |
-
) );
|
194 |
-
|
195 |
-
$plugin_notifications = $this->validate_notifications( $plugin_notifications );
|
196 |
-
|
197 |
-
if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
|
198 |
-
foreach ( $plugin_notifications as $notification ) {
|
199 |
-
$dismissable = get_post_meta( $notification->ID, 'dismissable', true );
|
200 |
-
$type = get_post_meta( $notification->ID, 'type', true );
|
201 |
-
?>
|
202 |
-
<div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
|
203 |
-
<?php echo $notification->post_content; ?>
|
204 |
-
</div>
|
205 |
-
<script type="text/javascript">
|
206 |
-
jQuery(document).ready(function ($) {
|
207 |
-
$(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
|
208 |
-
$.post(ajaxurl, {
|
209 |
-
action: 'am_notification_dismiss',
|
210 |
-
notification_id: '<?php echo $notification->ID; ?>'
|
211 |
-
});
|
212 |
-
});
|
213 |
-
});
|
214 |
-
</script>
|
215 |
-
<?php
|
216 |
-
}
|
217 |
-
|
218 |
-
self::$registered = true;
|
219 |
-
}
|
220 |
-
}
|
221 |
-
|
222 |
-
/**
|
223 |
-
* Validate the notifications before displaying them.
|
224 |
-
*
|
225 |
-
* @since 1.0.0
|
226 |
-
*
|
227 |
-
* @param array $plugin_notifications An array of plugin notifications.
|
228 |
-
*
|
229 |
-
* @return array A filtered array of plugin notifications.
|
230 |
-
*/
|
231 |
-
public function validate_notifications( $plugin_notifications ) {
|
232 |
-
global $pagenow;
|
233 |
-
|
234 |
-
foreach ( $plugin_notifications as $key => $notification ) {
|
235 |
-
// Location validation.
|
236 |
-
$location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
|
237 |
-
$continue = false;
|
238 |
-
if ( ! in_array( 'everywhere', $location, true ) ) {
|
239 |
-
if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
|
240 |
-
$continue = true;
|
241 |
-
}
|
242 |
-
|
243 |
-
if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
|
244 |
-
$continue = true;
|
245 |
-
}
|
246 |
-
|
247 |
-
if ( ! $continue ) {
|
248 |
-
unset( $plugin_notifications[ $key ] );
|
249 |
-
}
|
250 |
-
}
|
251 |
-
|
252 |
-
// Plugin validation (OR conditional).
|
253 |
-
$plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
|
254 |
-
$continue = false;
|
255 |
-
if ( ! empty( $plugins ) ) {
|
256 |
-
foreach ( $plugins as $plugin ) {
|
257 |
-
if ( is_plugin_active( $plugin ) ) {
|
258 |
-
$continue = true;
|
259 |
-
}
|
260 |
-
}
|
261 |
-
|
262 |
-
if ( ! $continue ) {
|
263 |
-
unset( $plugin_notifications[ $key ] );
|
264 |
-
}
|
265 |
-
}
|
266 |
-
|
267 |
-
// Theme validation.
|
268 |
-
$theme = get_post_meta( $notification->ID, 'theme', true );
|
269 |
-
$continue = (string) wp_get_theme() === $theme;
|
270 |
-
|
271 |
-
if ( ! empty( $theme ) && ! $continue ) {
|
272 |
-
unset( $plugin_notifications[ $key ] );
|
273 |
-
}
|
274 |
-
|
275 |
-
// Version validation.
|
276 |
-
$version = get_post_meta( $notification->ID, 'version', true );
|
277 |
-
$continue = false;
|
278 |
-
if ( ! empty( $version ) ) {
|
279 |
-
if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
|
280 |
-
$continue = true;
|
281 |
-
}
|
282 |
-
|
283 |
-
if ( ! $continue ) {
|
284 |
-
unset( $plugin_notifications[ $key ] );
|
285 |
-
}
|
286 |
-
}
|
287 |
-
|
288 |
-
// Expiration validation.
|
289 |
-
$expiration = get_post_meta( $notification->ID, 'expiration', true );
|
290 |
-
$continue = false;
|
291 |
-
if ( ! empty( $expiration ) ) {
|
292 |
-
if ( $expiration > time() ) {
|
293 |
-
$continue = true;
|
294 |
-
}
|
295 |
-
|
296 |
-
if ( ! $continue ) {
|
297 |
-
unset( $plugin_notifications[ $key ] );
|
298 |
-
}
|
299 |
-
}
|
300 |
-
|
301 |
-
// Plan validation.
|
302 |
-
$plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
|
303 |
-
$continue = false;
|
304 |
-
if ( ! empty( $plans ) ) {
|
305 |
-
$level = $this->get_plan_level();
|
306 |
-
if ( in_array( $level, $plans, true ) ) {
|
307 |
-
$continue = true;
|
308 |
-
}
|
309 |
-
|
310 |
-
if ( ! $continue ) {
|
311 |
-
unset( $plugin_notifications[ $key ] );
|
312 |
-
}
|
313 |
-
}
|
314 |
-
}
|
315 |
-
|
316 |
-
return $plugin_notifications;
|
317 |
-
}
|
318 |
-
|
319 |
-
/**
|
320 |
-
* Grab the current plan level.
|
321 |
-
*
|
322 |
-
* @since 1.0.0
|
323 |
-
*
|
324 |
-
* @return string The current plan level.
|
325 |
-
*/
|
326 |
-
public function get_plan_level() {
|
327 |
-
// Prepare variables.
|
328 |
-
$key = '';
|
329 |
-
$level = '';
|
330 |
-
$option = false;
|
331 |
-
switch ( $this->plugin ) {
|
332 |
-
case 'wpforms' :
|
333 |
-
$option = get_option( 'wpforms_license' );
|
334 |
-
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
335 |
-
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
336 |
-
|
337 |
-
// Possibly check for a constant.
|
338 |
-
if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
|
339 |
-
$key = WPFORMS_LICENSE_KEY;
|
340 |
-
}
|
341 |
-
break;
|
342 |
-
case 'mi' :
|
343 |
-
$option = get_option( 'monsterinsights_license' );
|
344 |
-
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
345 |
-
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
346 |
-
|
347 |
-
// Possibly check for a constant.
|
348 |
-
if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
|
349 |
-
$key = MONSTERINSIGHTS_LICENSE_KEY;
|
350 |
-
}
|
351 |
-
break;
|
352 |
-
case 'sol' :
|
353 |
-
$option = get_option( 'soliloquy' );
|
354 |
-
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
355 |
-
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
356 |
-
|
357 |
-
// Possibly check for a constant.
|
358 |
-
if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
|
359 |
-
$key = SOLILOQUY_LICENSE_KEY;
|
360 |
-
}
|
361 |
-
break;
|
362 |
-
case 'envira' :
|
363 |
-
$option = get_option( 'envira_gallery' );
|
364 |
-
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
365 |
-
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
366 |
-
|
367 |
-
// Possibly check for a constant.
|
368 |
-
if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
|
369 |
-
$key = ENVIRA_LICENSE_KEY;
|
370 |
-
}
|
371 |
-
break;
|
372 |
-
case 'om' :
|
373 |
-
$option = get_option( 'optin_monster_api' );
|
374 |
-
$key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
|
375 |
-
|
376 |
-
// Possibly check for a constant.
|
377 |
-
if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
|
378 |
-
$key = OPTINMONSTER_REST_API_LICENSE_KEY;
|
379 |
-
}
|
380 |
-
|
381 |
-
// If the key is still empty, check for the old legacy key.
|
382 |
-
if ( empty( $key ) ) {
|
383 |
-
$key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
|
384 |
-
}
|
385 |
-
break;
|
386 |
-
}
|
387 |
-
|
388 |
-
// Possibly set the level to 'none' if the key is empty and no level has been set.
|
389 |
-
if ( empty( $key ) && empty( $level ) ) {
|
390 |
-
$level = 'none';
|
391 |
-
}
|
392 |
-
|
393 |
-
// Normalize the level.
|
394 |
-
switch ( $level ) {
|
395 |
-
case 'bronze' :
|
396 |
-
case 'personal' :
|
397 |
-
$level = 'basic';
|
398 |
-
break;
|
399 |
-
case 'silver' :
|
400 |
-
case 'multi' :
|
401 |
-
$level = 'plus';
|
402 |
-
break;
|
403 |
-
case 'gold' :
|
404 |
-
case 'developer' :
|
405 |
-
$level = 'pro';
|
406 |
-
break;
|
407 |
-
case 'platinum' :
|
408 |
-
case 'master' :
|
409 |
-
$level = 'ultimate';
|
410 |
-
break;
|
411 |
-
}
|
412 |
-
|
413 |
-
// Return the plan level.
|
414 |
-
return $level;
|
415 |
-
}
|
416 |
-
|
417 |
-
/**
|
418 |
-
* Dismiss the notification via AJAX.
|
419 |
-
*
|
420 |
-
* @since 1.0.0
|
421 |
-
*/
|
422 |
-
public function dismiss_notification() {
|
423 |
-
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
424 |
-
die;
|
425 |
-
}
|
426 |
-
|
427 |
-
$notification_id = intval( $_POST['notification_id'] );
|
428 |
-
update_post_meta( $notification_id, 'viewed', 1 );
|
429 |
-
die;
|
430 |
-
}
|
431 |
-
|
432 |
-
/**
|
433 |
-
* Revokes notifications.
|
434 |
-
*
|
435 |
-
* @since 1.0.0
|
436 |
-
*
|
437 |
-
* @param array $ids An array of notification IDs to revoke.
|
438 |
-
*/
|
439 |
-
public function revoke_notifications( $ids ) {
|
440 |
-
// Loop through each of the IDs and find the post that has it as meta.
|
441 |
-
foreach ( (array) $ids as $id ) {
|
442 |
-
$notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
|
443 |
-
if ( $notifications ) {
|
444 |
-
foreach ( $notifications as $notification ) {
|
445 |
-
update_post_meta( $notification->ID, 'viewed', 1 );
|
446 |
-
}
|
447 |
-
}
|
448 |
-
}
|
449 |
-
}
|
450 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Awesome Motive Notifications
|
5 |
+
*
|
6 |
+
* This creates a custom post type (if it doesn't exist) and calls the API to
|
7 |
+
* retrieve notifications for this product.
|
8 |
+
*
|
9 |
+
* @package AwesomeMotive
|
10 |
+
* @author Benjamin Rojas
|
11 |
+
* @license GPL-2.0+
|
12 |
+
* @copyright Copyright (c) 2017, Retyp LLC
|
13 |
+
* @version 1.0.2
|
14 |
+
*/
|
15 |
+
class WPMS_AM_Notification {
|
16 |
+
/**
|
17 |
+
* The api url we are calling.
|
18 |
+
*
|
19 |
+
* @since 1.0.0
|
20 |
+
*
|
21 |
+
* @var string
|
22 |
+
*/
|
23 |
+
public $api_url = 'https://api.awesomemotive.com/v1/notification/';
|
24 |
+
|
25 |
+
/**
|
26 |
+
* A unique slug for this plugin.
|
27 |
+
* (Not the WordPress plugin slug)
|
28 |
+
*
|
29 |
+
* @since 1.0.0
|
30 |
+
*
|
31 |
+
* @var string
|
32 |
+
*/
|
33 |
+
public $plugin;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* The current plugin version.
|
37 |
+
*
|
38 |
+
* @since 1.0.0
|
39 |
+
*
|
40 |
+
* @var string
|
41 |
+
*/
|
42 |
+
public $plugin_version;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Flag if a notice has been registered.
|
46 |
+
*
|
47 |
+
* @since 1.0.0
|
48 |
+
*
|
49 |
+
* @var bool
|
50 |
+
*/
|
51 |
+
public static $registered = false;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Construct.
|
55 |
+
*
|
56 |
+
* @since 1.0.0
|
57 |
+
*
|
58 |
+
* @param string $plugin The plugin slug.
|
59 |
+
* @param mixed $version The version of the plugin.
|
60 |
+
*/
|
61 |
+
public function __construct( $plugin = '', $version = 0 ) {
|
62 |
+
$this->plugin = $plugin;
|
63 |
+
$this->plugin_version = $version;
|
64 |
+
|
65 |
+
add_action( 'init', array( $this, 'custom_post_type' ) );
|
66 |
+
add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
|
67 |
+
add_action( 'admin_notices', array( $this, 'display_notifications' ) );
|
68 |
+
add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Registers a custom post type.
|
73 |
+
*
|
74 |
+
* @since 1.0.0
|
75 |
+
*/
|
76 |
+
public function custom_post_type() {
|
77 |
+
register_post_type( 'amn_' . $this->plugin, array(
|
78 |
+
'label' => $this->plugin . ' Announcements',
|
79 |
+
'can_export' => false,
|
80 |
+
'supports' => false,
|
81 |
+
) );
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Retrieve the remote notifications if the time has expired.
|
86 |
+
*
|
87 |
+
* @since 1.0.0
|
88 |
+
*/
|
89 |
+
public function get_remote_notifications() {
|
90 |
+
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
91 |
+
return;
|
92 |
+
}
|
93 |
+
|
94 |
+
$last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
|
95 |
+
|
96 |
+
if ( $last_checked < strtotime( 'today midnight' ) ) {
|
97 |
+
$plugin_notifications = $this->get_plugin_notifications( 1 );
|
98 |
+
$notification_id = null;
|
99 |
+
|
100 |
+
if ( ! empty( $plugin_notifications ) ) {
|
101 |
+
// Unset it from the array.
|
102 |
+
$notification = $plugin_notifications[0];
|
103 |
+
$notification_id = get_post_meta( $notification->ID, 'notification_id', true );
|
104 |
+
}
|
105 |
+
|
106 |
+
$response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
|
107 |
+
'body' => array(
|
108 |
+
'slug' => $this->plugin,
|
109 |
+
'version' => $this->plugin_version,
|
110 |
+
'last_notification' => $notification_id,
|
111 |
+
),
|
112 |
+
) ) );
|
113 |
+
|
114 |
+
$data = json_decode( $response );
|
115 |
+
|
116 |
+
if ( ! empty( $data->id ) ) {
|
117 |
+
$notifications = array();
|
118 |
+
|
119 |
+
foreach ( (array) $data->slugs as $slug ) {
|
120 |
+
$notifications = array_merge(
|
121 |
+
$notifications,
|
122 |
+
(array) get_posts(
|
123 |
+
array(
|
124 |
+
'post_type' => 'amn_' . $slug,
|
125 |
+
'post_status' => 'all',
|
126 |
+
'meta_key' => 'notification_id',
|
127 |
+
'meta_value' => $data->id,
|
128 |
+
)
|
129 |
+
)
|
130 |
+
);
|
131 |
+
}
|
132 |
+
|
133 |
+
if ( empty( $notifications ) ) {
|
134 |
+
$new_notification_id = wp_insert_post( array(
|
135 |
+
'post_content' => wp_kses_post( $data->content ),
|
136 |
+
'post_type' => 'amn_' . $this->plugin,
|
137 |
+
) );
|
138 |
+
|
139 |
+
update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
|
140 |
+
update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
|
141 |
+
update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
|
142 |
+
update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
|
143 |
+
update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
|
144 |
+
update_post_meta( $new_notification_id, 'viewed', 0 );
|
145 |
+
update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
|
146 |
+
update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
// Possibly revoke notifications.
|
151 |
+
if ( ! empty( $data->revoked ) ) {
|
152 |
+
$this->revoke_notifications( $data->revoked );
|
153 |
+
}
|
154 |
+
|
155 |
+
// Set the option now so we can't run this again until after 24 hours.
|
156 |
+
update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
|
157 |
+
}
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Get local plugin notifications that have already been set.
|
162 |
+
*
|
163 |
+
* @since 1.0.0
|
164 |
+
*
|
165 |
+
* @param integer $limit Set the limit for how many posts to retrieve.
|
166 |
+
* @param array $args Any top-level arguments to add to the array.
|
167 |
+
*
|
168 |
+
* @return WP_Post[] WP_Post that match the query.
|
169 |
+
*/
|
170 |
+
public function get_plugin_notifications( $limit = -1, $args = array() ) {
|
171 |
+
return get_posts(
|
172 |
+
array(
|
173 |
+
'posts_per_page' => $limit,
|
174 |
+
'post_type' => 'amn_' . $this->plugin,
|
175 |
+
) + $args
|
176 |
+
);
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Display any notifications that should be displayed.
|
181 |
+
*
|
182 |
+
* @since 1.0.0
|
183 |
+
*/
|
184 |
+
public function display_notifications() {
|
185 |
+
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
186 |
+
return;
|
187 |
+
}
|
188 |
+
|
189 |
+
$plugin_notifications = $this->get_plugin_notifications( -1, array(
|
190 |
+
'post_status' => 'all',
|
191 |
+
'meta_key' => 'viewed',
|
192 |
+
'meta_value' => '0',
|
193 |
+
) );
|
194 |
+
|
195 |
+
$plugin_notifications = $this->validate_notifications( $plugin_notifications );
|
196 |
+
|
197 |
+
if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
|
198 |
+
foreach ( $plugin_notifications as $notification ) {
|
199 |
+
$dismissable = get_post_meta( $notification->ID, 'dismissable', true );
|
200 |
+
$type = get_post_meta( $notification->ID, 'type', true );
|
201 |
+
?>
|
202 |
+
<div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
|
203 |
+
<?php echo $notification->post_content; ?>
|
204 |
+
</div>
|
205 |
+
<script type="text/javascript">
|
206 |
+
jQuery(document).ready(function ($) {
|
207 |
+
$(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
|
208 |
+
$.post(ajaxurl, {
|
209 |
+
action: 'am_notification_dismiss',
|
210 |
+
notification_id: '<?php echo $notification->ID; ?>'
|
211 |
+
});
|
212 |
+
});
|
213 |
+
});
|
214 |
+
</script>
|
215 |
+
<?php
|
216 |
+
}
|
217 |
+
|
218 |
+
self::$registered = true;
|
219 |
+
}
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Validate the notifications before displaying them.
|
224 |
+
*
|
225 |
+
* @since 1.0.0
|
226 |
+
*
|
227 |
+
* @param array $plugin_notifications An array of plugin notifications.
|
228 |
+
*
|
229 |
+
* @return array A filtered array of plugin notifications.
|
230 |
+
*/
|
231 |
+
public function validate_notifications( $plugin_notifications ) {
|
232 |
+
global $pagenow;
|
233 |
+
|
234 |
+
foreach ( $plugin_notifications as $key => $notification ) {
|
235 |
+
// Location validation.
|
236 |
+
$location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
|
237 |
+
$continue = false;
|
238 |
+
if ( ! in_array( 'everywhere', $location, true ) ) {
|
239 |
+
if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
|
240 |
+
$continue = true;
|
241 |
+
}
|
242 |
+
|
243 |
+
if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
|
244 |
+
$continue = true;
|
245 |
+
}
|
246 |
+
|
247 |
+
if ( ! $continue ) {
|
248 |
+
unset( $plugin_notifications[ $key ] );
|
249 |
+
}
|
250 |
+
}
|
251 |
+
|
252 |
+
// Plugin validation (OR conditional).
|
253 |
+
$plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
|
254 |
+
$continue = false;
|
255 |
+
if ( ! empty( $plugins ) ) {
|
256 |
+
foreach ( $plugins as $plugin ) {
|
257 |
+
if ( is_plugin_active( $plugin ) ) {
|
258 |
+
$continue = true;
|
259 |
+
}
|
260 |
+
}
|
261 |
+
|
262 |
+
if ( ! $continue ) {
|
263 |
+
unset( $plugin_notifications[ $key ] );
|
264 |
+
}
|
265 |
+
}
|
266 |
+
|
267 |
+
// Theme validation.
|
268 |
+
$theme = get_post_meta( $notification->ID, 'theme', true );
|
269 |
+
$continue = (string) wp_get_theme() === $theme;
|
270 |
+
|
271 |
+
if ( ! empty( $theme ) && ! $continue ) {
|
272 |
+
unset( $plugin_notifications[ $key ] );
|
273 |
+
}
|
274 |
+
|
275 |
+
// Version validation.
|
276 |
+
$version = get_post_meta( $notification->ID, 'version', true );
|
277 |
+
$continue = false;
|
278 |
+
if ( ! empty( $version ) ) {
|
279 |
+
if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
|
280 |
+
$continue = true;
|
281 |
+
}
|
282 |
+
|
283 |
+
if ( ! $continue ) {
|
284 |
+
unset( $plugin_notifications[ $key ] );
|
285 |
+
}
|
286 |
+
}
|
287 |
+
|
288 |
+
// Expiration validation.
|
289 |
+
$expiration = get_post_meta( $notification->ID, 'expiration', true );
|
290 |
+
$continue = false;
|
291 |
+
if ( ! empty( $expiration ) ) {
|
292 |
+
if ( $expiration > time() ) {
|
293 |
+
$continue = true;
|
294 |
+
}
|
295 |
+
|
296 |
+
if ( ! $continue ) {
|
297 |
+
unset( $plugin_notifications[ $key ] );
|
298 |
+
}
|
299 |
+
}
|
300 |
+
|
301 |
+
// Plan validation.
|
302 |
+
$plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
|
303 |
+
$continue = false;
|
304 |
+
if ( ! empty( $plans ) ) {
|
305 |
+
$level = $this->get_plan_level();
|
306 |
+
if ( in_array( $level, $plans, true ) ) {
|
307 |
+
$continue = true;
|
308 |
+
}
|
309 |
+
|
310 |
+
if ( ! $continue ) {
|
311 |
+
unset( $plugin_notifications[ $key ] );
|
312 |
+
}
|
313 |
+
}
|
314 |
+
}
|
315 |
+
|
316 |
+
return $plugin_notifications;
|
317 |
+
}
|
318 |
+
|
319 |
+
/**
|
320 |
+
* Grab the current plan level.
|
321 |
+
*
|
322 |
+
* @since 1.0.0
|
323 |
+
*
|
324 |
+
* @return string The current plan level.
|
325 |
+
*/
|
326 |
+
public function get_plan_level() {
|
327 |
+
// Prepare variables.
|
328 |
+
$key = '';
|
329 |
+
$level = '';
|
330 |
+
$option = false;
|
331 |
+
switch ( $this->plugin ) {
|
332 |
+
case 'wpforms' :
|
333 |
+
$option = get_option( 'wpforms_license' );
|
334 |
+
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
335 |
+
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
336 |
+
|
337 |
+
// Possibly check for a constant.
|
338 |
+
if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
|
339 |
+
$key = WPFORMS_LICENSE_KEY;
|
340 |
+
}
|
341 |
+
break;
|
342 |
+
case 'mi' :
|
343 |
+
$option = get_option( 'monsterinsights_license' );
|
344 |
+
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
345 |
+
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
346 |
+
|
347 |
+
// Possibly check for a constant.
|
348 |
+
if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
|
349 |
+
$key = MONSTERINSIGHTS_LICENSE_KEY;
|
350 |
+
}
|
351 |
+
break;
|
352 |
+
case 'sol' :
|
353 |
+
$option = get_option( 'soliloquy' );
|
354 |
+
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
355 |
+
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
356 |
+
|
357 |
+
// Possibly check for a constant.
|
358 |
+
if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
|
359 |
+
$key = SOLILOQUY_LICENSE_KEY;
|
360 |
+
}
|
361 |
+
break;
|
362 |
+
case 'envira' :
|
363 |
+
$option = get_option( 'envira_gallery' );
|
364 |
+
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
365 |
+
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
366 |
+
|
367 |
+
// Possibly check for a constant.
|
368 |
+
if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
|
369 |
+
$key = ENVIRA_LICENSE_KEY;
|
370 |
+
}
|
371 |
+
break;
|
372 |
+
case 'om' :
|
373 |
+
$option = get_option( 'optin_monster_api' );
|
374 |
+
$key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
|
375 |
+
|
376 |
+
// Possibly check for a constant.
|
377 |
+
if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
|
378 |
+
$key = OPTINMONSTER_REST_API_LICENSE_KEY;
|
379 |
+
}
|
380 |
+
|
381 |
+
// If the key is still empty, check for the old legacy key.
|
382 |
+
if ( empty( $key ) ) {
|
383 |
+
$key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
|
384 |
+
}
|
385 |
+
break;
|
386 |
+
}
|
387 |
+
|
388 |
+
// Possibly set the level to 'none' if the key is empty and no level has been set.
|
389 |
+
if ( empty( $key ) && empty( $level ) ) {
|
390 |
+
$level = 'none';
|
391 |
+
}
|
392 |
+
|
393 |
+
// Normalize the level.
|
394 |
+
switch ( $level ) {
|
395 |
+
case 'bronze' :
|
396 |
+
case 'personal' :
|
397 |
+
$level = 'basic';
|
398 |
+
break;
|
399 |
+
case 'silver' :
|
400 |
+
case 'multi' :
|
401 |
+
$level = 'plus';
|
402 |
+
break;
|
403 |
+
case 'gold' :
|
404 |
+
case 'developer' :
|
405 |
+
$level = 'pro';
|
406 |
+
break;
|
407 |
+
case 'platinum' :
|
408 |
+
case 'master' :
|
409 |
+
$level = 'ultimate';
|
410 |
+
break;
|
411 |
+
}
|
412 |
+
|
413 |
+
// Return the plan level.
|
414 |
+
return $level;
|
415 |
+
}
|
416 |
+
|
417 |
+
/**
|
418 |
+
* Dismiss the notification via AJAX.
|
419 |
+
*
|
420 |
+
* @since 1.0.0
|
421 |
+
*/
|
422 |
+
public function dismiss_notification() {
|
423 |
+
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
424 |
+
die;
|
425 |
+
}
|
426 |
+
|
427 |
+
$notification_id = intval( $_POST['notification_id'] );
|
428 |
+
update_post_meta( $notification_id, 'viewed', 1 );
|
429 |
+
die;
|
430 |
+
}
|
431 |
+
|
432 |
+
/**
|
433 |
+
* Revokes notifications.
|
434 |
+
*
|
435 |
+
* @since 1.0.0
|
436 |
+
*
|
437 |
+
* @param array $ids An array of notification IDs to revoke.
|
438 |
+
*/
|
439 |
+
public function revoke_notifications( $ids ) {
|
440 |
+
// Loop through each of the IDs and find the post that has it as meta.
|
441 |
+
foreach ( (array) $ids as $id ) {
|
442 |
+
$notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
|
443 |
+
if ( $notifications ) {
|
444 |
+
foreach ( $notifications as $notification ) {
|
445 |
+
update_post_meta( $notification->ID, 'viewed', 1 );
|
446 |
+
}
|
447 |
+
}
|
448 |
+
}
|
449 |
+
}
|
450 |
+
}
|
readme.txt
CHANGED
@@ -1,348 +1,351 @@
|
|
1 |
-
=== WP Mail SMTP by WPForms ===
|
2 |
-
Contributors: wpforms, jaredatch, smub, slaFFik
|
3 |
-
Tags: smtp, wp mail smtp, wordpress smtp, gmail smtp, sendgrid smtp, mailgun smtp, mail, mailer, phpmailer, wp_mail, email, mailgun, sengrid, gmail, wp smtp
|
4 |
-
Requires at least: 3.6
|
5 |
-
Tested up to: 4.9
|
6 |
-
Stable tag: trunk
|
7 |
-
Requires PHP: 5.3
|
8 |
-
|
9 |
-
The most popular WordPress SMTP and PHP Mailer plugin. Trusted by over 700k sites.
|
10 |
-
|
11 |
-
== Description ==
|
12 |
-
|
13 |
-
= WordPress Mail SMTP Plugin =
|
14 |
-
|
15 |
-
Having problems with your WordPress site not sending emails? You're not alone. Over 700,000 websites use WP Mail SMTP to fix their email deliverability issues.
|
16 |
-
|
17 |
-
WP Mail SMTP fixes your email deliverability by reconfiguring the wp_mail() PHP function to use a proper SMTP provider.
|
18 |
-
|
19 |
-
= What is SMTP? =
|
20 |
-
|
21 |
-
SMTP (Simple Mail Transfer Protocol) is an industry standard for sending emails. SMTP helps increase email deliverability by using proper authentication.
|
22 |
-
|
23 |
-
Popular email clients like Gmail, Yahoo, Outlook, etc are constantly improving their services to reduce email spam. One of the things their spam tools look for is whether an email is originating from the location it claims to be originating from.
|
24 |
-
|
25 |
-
If the proper authentication isn't there, then the emails either go in your SPAM folder or worst not get delivered at all.
|
26 |
-
|
27 |
-
This is a problem for a lot of WordPress sites because by default, WordPress uses the PHP mail function to send emails generated by WordPress or any contact form plugin like <a href="https://wpforms.com/" rel="friend">WPForms</a>.
|
28 |
-
|
29 |
-
The issue is that most <a href"http://www.wpbeginner.com/wordpress-hosting/" rel="friend">WordPress hosting companies</a> don't have their servers properly configured for sending PHP emails.
|
30 |
-
|
31 |
-
The combination of two causes your WordPress emails to not get delivered.
|
32 |
-
|
33 |
-
= How does WP Mail SMTP work? =
|
34 |
-
|
35 |
-
WP Mail SMTP plugin allows you to easily reconfigure the wp_mail() function to use a trusted SMTP provider.
|
36 |
-
|
37 |
-
This helps you fix all WordPress not sending email issues.
|
38 |
-
|
39 |
-
WP Mail SMTP plugin includes four different SMTP setup options:
|
40 |
-
|
41 |
-
1. Mailgun SMTP
|
42 |
-
2. SendGrid SMTP
|
43 |
-
3. Gmail SMTP
|
44 |
-
4. All Other SMTP
|
45 |
-
|
46 |
-
For all options, you can specify the "from name" and "email address" for outgoing emails.
|
47 |
-
|
48 |
-
Instead of having users use different SMTP plugins and workflows for different SMTP providers, we decided to bring it all in one. This is what makes WP Mail SMTP, the best SMTP solution for WordPress.
|
49 |
-
|
50 |
-
= Mailgun SMTP =
|
51 |
-
|
52 |
-
Mailgun SMTP is a popular SMTP service provider that allows you to send large quantities of emails. They allow you to send your first 10,000 emails for free every month.
|
53 |
-
|
54 |
-
WP Mail SMTP plugin offers a native integration with MailGun. All you have to do is connect your Mailgun account, and you will improve your email deliverability.
|
55 |
-
|
56 |
-
Read our <a href="https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/" rel="friend">Mailgun documentation</a> for more details.
|
57 |
-
|
58 |
-
= Gmail SMTP =
|
59 |
-
|
60 |
-
Often bloggers and small business owners don't want to use third-party SMTP services. Well you can use your Gmail or G Suite account for SMTP emails.
|
61 |
-
|
62 |
-
This allows you to use your <a href="http://www.wpbeginner.com/beginners-guide/how-to-setup-a-professional-email-address-with-gmail-and-google-apps/" rel="friend">professional email address</a> and improve email deliverability.
|
63 |
-
|
64 |
-
Unlike other Gmail SMTP plugins, our Gmail SMTP option uses OAuth to authenticate your Google account, keeping your login information 100% secure.
|
65 |
-
|
66 |
-
Read our <a href="https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/" rel="friend">Gmail documentation</a> for more details.
|
67 |
-
|
68 |
-
= SendGrid SMTP =
|
69 |
-
|
70 |
-
SendGrid has a free SMTP plan that you can use to send up to 100 emails per day. With our native SendGrid SMTP integration, you can easily and securely set up SendGrid SMTP on your WordPress site.
|
71 |
-
|
72 |
-
Read our <a href="https://wpforms.com/fix-wordpress-email-notifications-with-sendgrid/" rel="friend">SendGrid documentation</a> for more details.
|
73 |
-
|
74 |
-
= Other SMTP =
|
75 |
-
|
76 |
-
WP Mail SMTP plugin also works with all major email services such as Gmail, Yahoo, Outlook, Microsoft Live, and any other email sending service that offers SMTP.
|
77 |
-
|
78 |
-
You can set the following options:
|
79 |
-
|
80 |
-
* Specify an SMTP host.
|
81 |
-
* Specify an SMTP port.
|
82 |
-
* Choose SSL / TLS encryption.
|
83 |
-
* Choose to use SMTP authentication or not.
|
84 |
-
* Specify an SMTP username and password.
|
85 |
-
|
86 |
-
WP Mail SMTP also gives you the option to insert your password in your wp-config.php file, so it's not visible in your WordPress settings.
|
87 |
-
|
88 |
-
To see recommended settings for the popular services as well as troubleshooting tips, check out our <a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" rel="friend">SMTP documentation</a>.
|
89 |
-
|
90 |
-
We hope that you find WP Mail SMTP plugin helpful.
|
91 |
-
|
92 |
-
= Credits =
|
93 |
-
|
94 |
-
WP Mail SMTP plugin was originally created by Callum Macdonald. It is now owned and maintained by the team behind <a href="https://wpforms.com/" rel="friend">WPForms</a> - the best drag & drop form builder for WordPress.
|
95 |
-
|
96 |
-
You can try the <a href="https://wordpress.org/plugins/wpforms-lite/" rel="friend">free version of WPForms plugin</a> to see why it's the best in the market.
|
97 |
-
|
98 |
-
= What's Next =
|
99 |
-
|
100 |
-
If you like this plugin, then please consider checking out our other popular plugins:
|
101 |
-
|
102 |
-
* <a href="http://optinmonster.com/" rel="friend" title="OptinMonster">OptinMonster</a> - Get More Email Subscribers
|
103 |
-
* <a href="https://www.monsterinsights.com/" rel="friend" title="MonsterInsights">MonsterInsights</a> - Best Google Analytics Plugin for WordPress
|
104 |
-
|
105 |
-
Visit <a href="http://www.wpbeginner.com/" rel="friend" title="WPBeginner">WPBeginner</a> to learn from our <a href="http://www.wpbeginner.com/category/wp-tutorials/" rel="friend" title="WordPress Tutorials">WordPress Tutorials</a> and find out about other <a href="http://www.wpbeginner.com/category/plugins/" rel="friend" title="Best WordPress Plugins">best WordPress plugins</a>.
|
106 |
-
|
107 |
-
== Installation ==
|
108 |
-
|
109 |
-
1. Install WP Mail SMTP by WPForms either via the WordPress.org plugin repository or by uploading the files to your server. (See instructions on <a href="http://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/" rel="friend">how to install a WordPress plugin</a>)
|
110 |
-
2. Activate WP Mail SMTP by WPForms.
|
111 |
-
3. Navigate to the Settings area of WP Mail SMTP in the WordPress admin.
|
112 |
-
4. Choose your SMTP option (Mailgun SMTP, SendGrid SMTP, Gmail SMTP, or Other SMTP) and follow the instructions to set it up.
|
113 |
-
5. Want to support us? Consider trying <a href="https://wpforms.com/?utm_source=wprepo&utm_medium=link&utm_campaign=liteversion" rel="friend" title="WPForms">WPForms Pro</a> - the best WordPress contact form plugin!
|
114 |
-
|
115 |
-
== Frequently Asked Questions ==
|
116 |
-
|
117 |
-
= Can I use this plugin to send email via Gmail, G Suite, Outlook.com, Office 365, Hotmail, Yahoo, or AOL SMTP? =
|
118 |
-
|
119 |
-
Yes! We have extensive documentation that covers setting up SMTP most popular email services.
|
120 |
-
|
121 |
-
<a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" rel="friend">Read our docs</a> to see the correct SMTP settings for each service.
|
122 |
-
|
123 |
-
= Help! I need support or have an issue. =
|
124 |
-
|
125 |
-
Please read <a href="https://wordpress.org/support/topic/wp-mail-smtp-support-policy/">our support policy</a> for more information.
|
126 |
-
|
127 |
-
= I found a bug, now what? =
|
128 |
-
|
129 |
-
If you've stumbled upon a bug, the best place to report it is in the <a href="https://github.com/awesomemotive/wp-mail-smtp">WP Mail SMTP GitHub repository</a>. GitHub is where the plugin is actively developed, and posting there will get your issue quickly seen by our developers (myself and Slava). Once posted, we'll review your bug report and triage the bug. When creating an issue, the more details you can add to your report, the faster the bug can be solved.
|
130 |
-
|
131 |
-
= Can you add feature x, y or z to the plugin? =
|
132 |
-
|
133 |
-
Short answer: maybe.
|
134 |
-
|
135 |
-
By all means please contact us to discuss features or options you'd like to see added to the plugin. We can't guarantee to add all of them, but we will consider all sensible requests. We can be contacted here:
|
136 |
-
<a href="https://wpforms.com/contact/" rel="friend">https://wpforms.com/contact/</a>
|
137 |
-
|
138 |
-
== Screenshots ==
|
139 |
-
|
140 |
-
1. WP Mail SMTP Settings page
|
141 |
-
2. Gmail / G Suite settings
|
142 |
-
3. Mailgun settings
|
143 |
-
4. SendGrid settings
|
144 |
-
5. SMTP settings
|
145 |
-
6. Send a Test Email
|
146 |
-
|
147 |
-
== Changelog ==
|
148 |
-
|
149 |
-
= 1.2.
|
150 |
-
* Fixed:
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
* Fixed:
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
*
|
160 |
-
|
161 |
-
= 1.2.
|
162 |
-
* Fixed:
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
*
|
167 |
-
|
168 |
-
|
169 |
-
*
|
170 |
-
* Changed: Improve
|
171 |
-
*
|
172 |
-
*
|
173 |
-
*
|
174 |
-
|
175 |
-
|
176 |
-
* Fixed:
|
177 |
-
|
178 |
-
= 1.0.
|
179 |
-
* Fixed:
|
180 |
-
|
181 |
-
= 1.0.
|
182 |
-
*
|
183 |
-
|
184 |
-
|
185 |
-
* Added:
|
186 |
-
* Added:
|
187 |
-
*
|
188 |
-
*
|
189 |
-
*
|
190 |
-
* Changed:
|
191 |
-
* Changed:
|
192 |
-
|
193 |
-
|
194 |
-
*
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
*
|
199 |
-
|
200 |
-
= 0.11 - 2017-10-30 =
|
201 |
-
*
|
202 |
-
|
203 |
-
|
204 |
-
* Added:
|
205 |
-
*
|
206 |
-
*
|
207 |
-
*
|
208 |
-
* Changed:
|
209 |
-
* Changed:
|
210 |
-
* Changed:
|
211 |
-
|
212 |
-
|
213 |
-
*
|
214 |
-
|
215 |
-
= 0.10.
|
216 |
-
* Addition of Pepipost and cleanup of admin page.
|
217 |
-
|
218 |
-
= 0.
|
219 |
-
*
|
220 |
-
|
221 |
-
= 0.9.
|
222 |
-
* Minor security fix,
|
223 |
-
|
224 |
-
= 0.9.
|
225 |
-
*
|
226 |
-
|
227 |
-
= 0.9.
|
228 |
-
*
|
229 |
-
|
230 |
-
= 0.9.
|
231 |
-
*
|
232 |
-
|
233 |
-
= 0.9.
|
234 |
-
*
|
235 |
-
|
236 |
-
= 0.9.
|
237 |
-
*
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
*
|
243 |
-
|
244 |
-
= 0.8.
|
245 |
-
*
|
246 |
-
|
247 |
-
= 0.8.
|
248 |
-
*
|
249 |
-
|
250 |
-
= 0.8.
|
251 |
-
*
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
*
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
*
|
260 |
-
|
261 |
-
= 0.8.
|
262 |
-
*
|
263 |
-
|
264 |
-
= 0.8 =
|
265 |
-
*
|
266 |
-
|
267 |
-
= 0.
|
268 |
-
* Added
|
269 |
-
|
270 |
-
= 0.
|
271 |
-
* Added
|
272 |
-
|
273 |
-
= 0.
|
274 |
-
*
|
275 |
-
|
276 |
-
= 0.5.
|
277 |
-
*
|
278 |
-
|
279 |
-
= 0.5.
|
280 |
-
*
|
281 |
-
|
282 |
-
= 0.
|
283 |
-
*
|
284 |
-
|
285 |
-
= 0.4.
|
286 |
-
*
|
287 |
-
|
288 |
-
= 0.4 =
|
289 |
-
* Added the test
|
290 |
-
|
291 |
-
= 0.
|
292 |
-
*
|
293 |
-
|
294 |
-
= 0.3.
|
295 |
-
*
|
296 |
-
|
297 |
-
= 0.3 =
|
298 |
-
*
|
299 |
-
|
300 |
-
= 0.
|
301 |
-
*
|
302 |
-
|
303 |
-
= 0.
|
304 |
-
*
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
= 0.10.
|
312 |
-
Addition of Pepipost and cleanup of admin page.
|
313 |
-
|
314 |
-
= 0.
|
315 |
-
|
316 |
-
|
317 |
-
= 0.9.
|
318 |
-
Minor security fix,
|
319 |
-
|
320 |
-
= 0.9.
|
321 |
-
|
322 |
-
|
323 |
-
= 0.9.
|
324 |
-
|
325 |
-
|
326 |
-
= 0.9.
|
327 |
-
|
328 |
-
|
329 |
-
= 0.9.
|
330 |
-
|
331 |
-
|
332 |
-
= 0.9.
|
333 |
-
|
334 |
-
|
335 |
-
= 0.
|
336 |
-
|
337 |
-
|
338 |
-
= 0.8.
|
339 |
-
|
340 |
-
|
341 |
-
= 0.8.
|
342 |
-
|
343 |
-
|
344 |
-
= 0.8.
|
345 |
-
Minor bugfix
|
346 |
-
|
347 |
-
= 0.8.
|
348 |
-
Minor bugfix for users using constants.
|
Â
|
|
Â
|
|
Â
|
1 |
+
=== WP Mail SMTP by WPForms ===
|
2 |
+
Contributors: wpforms, jaredatch, smub, slaFFik
|
3 |
+
Tags: smtp, wp mail smtp, wordpress smtp, gmail smtp, sendgrid smtp, mailgun smtp, mail, mailer, phpmailer, wp_mail, email, mailgun, sengrid, gmail, wp smtp
|
4 |
+
Requires at least: 3.6
|
5 |
+
Tested up to: 4.9
|
6 |
+
Stable tag: trunk
|
7 |
+
Requires PHP: 5.3
|
8 |
+
|
9 |
+
The most popular WordPress SMTP and PHP Mailer plugin. Trusted by over 700k sites.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
= WordPress Mail SMTP Plugin =
|
14 |
+
|
15 |
+
Having problems with your WordPress site not sending emails? You're not alone. Over 700,000 websites use WP Mail SMTP to fix their email deliverability issues.
|
16 |
+
|
17 |
+
WP Mail SMTP fixes your email deliverability by reconfiguring the wp_mail() PHP function to use a proper SMTP provider.
|
18 |
+
|
19 |
+
= What is SMTP? =
|
20 |
+
|
21 |
+
SMTP (Simple Mail Transfer Protocol) is an industry standard for sending emails. SMTP helps increase email deliverability by using proper authentication.
|
22 |
+
|
23 |
+
Popular email clients like Gmail, Yahoo, Outlook, etc are constantly improving their services to reduce email spam. One of the things their spam tools look for is whether an email is originating from the location it claims to be originating from.
|
24 |
+
|
25 |
+
If the proper authentication isn't there, then the emails either go in your SPAM folder or worst not get delivered at all.
|
26 |
+
|
27 |
+
This is a problem for a lot of WordPress sites because by default, WordPress uses the PHP mail function to send emails generated by WordPress or any contact form plugin like <a href="https://wpforms.com/" rel="friend">WPForms</a>.
|
28 |
+
|
29 |
+
The issue is that most <a href"http://www.wpbeginner.com/wordpress-hosting/" rel="friend">WordPress hosting companies</a> don't have their servers properly configured for sending PHP emails.
|
30 |
+
|
31 |
+
The combination of two causes your WordPress emails to not get delivered.
|
32 |
+
|
33 |
+
= How does WP Mail SMTP work? =
|
34 |
+
|
35 |
+
WP Mail SMTP plugin allows you to easily reconfigure the wp_mail() function to use a trusted SMTP provider.
|
36 |
+
|
37 |
+
This helps you fix all WordPress not sending email issues.
|
38 |
+
|
39 |
+
WP Mail SMTP plugin includes four different SMTP setup options:
|
40 |
+
|
41 |
+
1. Mailgun SMTP
|
42 |
+
2. SendGrid SMTP
|
43 |
+
3. Gmail SMTP
|
44 |
+
4. All Other SMTP
|
45 |
+
|
46 |
+
For all options, you can specify the "from name" and "email address" for outgoing emails.
|
47 |
+
|
48 |
+
Instead of having users use different SMTP plugins and workflows for different SMTP providers, we decided to bring it all in one. This is what makes WP Mail SMTP, the best SMTP solution for WordPress.
|
49 |
+
|
50 |
+
= Mailgun SMTP =
|
51 |
+
|
52 |
+
Mailgun SMTP is a popular SMTP service provider that allows you to send large quantities of emails. They allow you to send your first 10,000 emails for free every month.
|
53 |
+
|
54 |
+
WP Mail SMTP plugin offers a native integration with MailGun. All you have to do is connect your Mailgun account, and you will improve your email deliverability.
|
55 |
+
|
56 |
+
Read our <a href="https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/" rel="friend">Mailgun documentation</a> for more details.
|
57 |
+
|
58 |
+
= Gmail SMTP =
|
59 |
+
|
60 |
+
Often bloggers and small business owners don't want to use third-party SMTP services. Well you can use your Gmail or G Suite account for SMTP emails.
|
61 |
+
|
62 |
+
This allows you to use your <a href="http://www.wpbeginner.com/beginners-guide/how-to-setup-a-professional-email-address-with-gmail-and-google-apps/" rel="friend">professional email address</a> and improve email deliverability.
|
63 |
+
|
64 |
+
Unlike other Gmail SMTP plugins, our Gmail SMTP option uses OAuth to authenticate your Google account, keeping your login information 100% secure.
|
65 |
+
|
66 |
+
Read our <a href="https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/" rel="friend">Gmail documentation</a> for more details.
|
67 |
+
|
68 |
+
= SendGrid SMTP =
|
69 |
+
|
70 |
+
SendGrid has a free SMTP plan that you can use to send up to 100 emails per day. With our native SendGrid SMTP integration, you can easily and securely set up SendGrid SMTP on your WordPress site.
|
71 |
+
|
72 |
+
Read our <a href="https://wpforms.com/fix-wordpress-email-notifications-with-sendgrid/" rel="friend">SendGrid documentation</a> for more details.
|
73 |
+
|
74 |
+
= Other SMTP =
|
75 |
+
|
76 |
+
WP Mail SMTP plugin also works with all major email services such as Gmail, Yahoo, Outlook, Microsoft Live, and any other email sending service that offers SMTP.
|
77 |
+
|
78 |
+
You can set the following options:
|
79 |
+
|
80 |
+
* Specify an SMTP host.
|
81 |
+
* Specify an SMTP port.
|
82 |
+
* Choose SSL / TLS encryption.
|
83 |
+
* Choose to use SMTP authentication or not.
|
84 |
+
* Specify an SMTP username and password.
|
85 |
+
|
86 |
+
WP Mail SMTP also gives you the option to insert your password in your wp-config.php file, so it's not visible in your WordPress settings.
|
87 |
+
|
88 |
+
To see recommended settings for the popular services as well as troubleshooting tips, check out our <a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" rel="friend">SMTP documentation</a>.
|
89 |
+
|
90 |
+
We hope that you find WP Mail SMTP plugin helpful.
|
91 |
+
|
92 |
+
= Credits =
|
93 |
+
|
94 |
+
WP Mail SMTP plugin was originally created by Callum Macdonald. It is now owned and maintained by the team behind <a href="https://wpforms.com/" rel="friend">WPForms</a> - the best drag & drop form builder for WordPress.
|
95 |
+
|
96 |
+
You can try the <a href="https://wordpress.org/plugins/wpforms-lite/" rel="friend">free version of WPForms plugin</a> to see why it's the best in the market.
|
97 |
+
|
98 |
+
= What's Next =
|
99 |
+
|
100 |
+
If you like this plugin, then please consider checking out our other popular plugins:
|
101 |
+
|
102 |
+
* <a href="http://optinmonster.com/" rel="friend" title="OptinMonster">OptinMonster</a> - Get More Email Subscribers
|
103 |
+
* <a href="https://www.monsterinsights.com/" rel="friend" title="MonsterInsights">MonsterInsights</a> - Best Google Analytics Plugin for WordPress
|
104 |
+
|
105 |
+
Visit <a href="http://www.wpbeginner.com/" rel="friend" title="WPBeginner">WPBeginner</a> to learn from our <a href="http://www.wpbeginner.com/category/wp-tutorials/" rel="friend" title="WordPress Tutorials">WordPress Tutorials</a> and find out about other <a href="http://www.wpbeginner.com/category/plugins/" rel="friend" title="Best WordPress Plugins">best WordPress plugins</a>.
|
106 |
+
|
107 |
+
== Installation ==
|
108 |
+
|
109 |
+
1. Install WP Mail SMTP by WPForms either via the WordPress.org plugin repository or by uploading the files to your server. (See instructions on <a href="http://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/" rel="friend">how to install a WordPress plugin</a>)
|
110 |
+
2. Activate WP Mail SMTP by WPForms.
|
111 |
+
3. Navigate to the Settings area of WP Mail SMTP in the WordPress admin.
|
112 |
+
4. Choose your SMTP option (Mailgun SMTP, SendGrid SMTP, Gmail SMTP, or Other SMTP) and follow the instructions to set it up.
|
113 |
+
5. Want to support us? Consider trying <a href="https://wpforms.com/?utm_source=wprepo&utm_medium=link&utm_campaign=liteversion" rel="friend" title="WPForms">WPForms Pro</a> - the best WordPress contact form plugin!
|
114 |
+
|
115 |
+
== Frequently Asked Questions ==
|
116 |
+
|
117 |
+
= Can I use this plugin to send email via Gmail, G Suite, Outlook.com, Office 365, Hotmail, Yahoo, or AOL SMTP? =
|
118 |
+
|
119 |
+
Yes! We have extensive documentation that covers setting up SMTP most popular email services.
|
120 |
+
|
121 |
+
<a href="https://wpforms.com/docs/how-to-set-up-smtp-using-the-wp-mail-smtp-plugin/" rel="friend">Read our docs</a> to see the correct SMTP settings for each service.
|
122 |
+
|
123 |
+
= Help! I need support or have an issue. =
|
124 |
+
|
125 |
+
Please read <a href="https://wordpress.org/support/topic/wp-mail-smtp-support-policy/">our support policy</a> for more information.
|
126 |
+
|
127 |
+
= I found a bug, now what? =
|
128 |
+
|
129 |
+
If you've stumbled upon a bug, the best place to report it is in the <a href="https://github.com/awesomemotive/wp-mail-smtp">WP Mail SMTP GitHub repository</a>. GitHub is where the plugin is actively developed, and posting there will get your issue quickly seen by our developers (myself and Slava). Once posted, we'll review your bug report and triage the bug. When creating an issue, the more details you can add to your report, the faster the bug can be solved.
|
130 |
+
|
131 |
+
= Can you add feature x, y or z to the plugin? =
|
132 |
+
|
133 |
+
Short answer: maybe.
|
134 |
+
|
135 |
+
By all means please contact us to discuss features or options you'd like to see added to the plugin. We can't guarantee to add all of them, but we will consider all sensible requests. We can be contacted here:
|
136 |
+
<a href="https://wpforms.com/contact/" rel="friend">https://wpforms.com/contact/</a>
|
137 |
+
|
138 |
+
== Screenshots ==
|
139 |
+
|
140 |
+
1. WP Mail SMTP Settings page
|
141 |
+
2. Gmail / G Suite settings
|
142 |
+
3. Mailgun settings
|
143 |
+
4. SendGrid settings
|
144 |
+
5. SMTP settings
|
145 |
+
6. Send a Test Email
|
146 |
+
|
147 |
+
== Changelog ==
|
148 |
+
|
149 |
+
= 1.2.4 - 2018-01-28 =
|
150 |
+
* Fixed: Improved escaping with debug reporting.
|
151 |
+
|
152 |
+
= 1.2.3 - 2018-01-22 =
|
153 |
+
* Fixed: Gmail tokens were resetted after clicking Save Settings.
|
154 |
+
* Fixed: Slight typo in Gmail success message.
|
155 |
+
|
156 |
+
= 1.2.2 - 2017-12-27 =
|
157 |
+
* Fixed: Correctly handle Mailgun debug message for an incorrect api key.
|
158 |
+
* Fixed: Fatal error for Gmail and SMTP mailers with Nginx web-server (without Apache at all).
|
159 |
+
* Changed: Update X-Mailer emails header to show the real sender with a mailer and plugin version.
|
160 |
+
|
161 |
+
= 1.2.1 - 2017-12-21 =
|
162 |
+
* Fixed: Failed SMTP connections generate fatal errors.
|
163 |
+
|
164 |
+
= 1.2.0 - 2017-12-21 =
|
165 |
+
* Fixed: Decrease the factual minimum WordPress version from 3.9 to 3.6.
|
166 |
+
* Changed: Improve debug output for all mail providers.
|
167 |
+
|
168 |
+
= 1.1.0 - 2017-12-18 =
|
169 |
+
* Added: New option "Auto TLS" for SMTP mailer. Default is enabled. Migration routine for all sites.
|
170 |
+
* Changed: Improve debug output - clear styles and context-aware content.
|
171 |
+
* Changed: Better exceptions handling for Google authentication process.
|
172 |
+
* Changed: Do not sanitize passwords, api keys etc - as they may contain special characters in certain order and sanitization will break those values.
|
173 |
+
* Changed: Improve wording of some helpful texts inside plugin admin area.
|
174 |
+
* Fixed: Do not include certain files in dependency libraries that are not used by Google mailer. This should stop flagging plugin by Wordfence and VaultPress.
|
175 |
+
* Fixed: Constants usage is working now, to define the SMTP password, for example.
|
176 |
+
* Fixed: Notice for default mailer.
|
177 |
+
|
178 |
+
= 1.0.2 - 2017-12-12 =
|
179 |
+
* Fixed: PHPMailer using incorrect SMTPSecure value.
|
180 |
+
|
181 |
+
= 1.0.1 - 2017-12-12 =
|
182 |
+
* Fixed: Global POST processing conflict.
|
183 |
+
|
184 |
+
= 1.0.0 - 2017-12-12 =
|
185 |
+
* Added: Automatic migration tool to move options from older storage format to a new one.
|
186 |
+
* Added: Added Gmail & G Suite email provider integration - without your email and password.
|
187 |
+
* Added: Added SendGrid email provider integration - using the API key only.
|
188 |
+
* Added: Added Mailgun email provider integration - using the API key and configured domain only.
|
189 |
+
* Added: New compatibility mode - for PHP 5.2 old plugin will be loaded, for PHP 5.3 and higher - new version of admin area and new functionality.
|
190 |
+
* Changed: The new look of the admin area.
|
191 |
+
* Changed: SMTP password field now has "password" type.
|
192 |
+
* Changed: SMTP password field does not display real password at all when using constants in `wp-config.php` to define it.
|
193 |
+
* Changed: Escape properly all translations.
|
194 |
+
* Changed: More helpful test email content (with a mailer name).
|
195 |
+
|
196 |
+
= 0.11.2 - 2017-11-28 =
|
197 |
+
* Added: Setting to hide announcement feed.
|
198 |
+
* Changed: Announcement feed data.
|
199 |
+
|
200 |
+
= 0.11.1 - 2017-10-30 =
|
201 |
+
* Fixed: Older PHP compatibility fix.
|
202 |
+
|
203 |
+
= 0.11 - 2017-10-30 =
|
204 |
+
* Added: Helper description to Return Path option.
|
205 |
+
* Added: Filter `wp_mail_smtp_admin_test_email_smtp_debug` to increase the debug message verbosity.
|
206 |
+
* Added: PHP 5.2 notice.
|
207 |
+
* Added: Announcement feed.
|
208 |
+
* Changed: Localization fixes, proper locale name.
|
209 |
+
* Changed: Code style improvements and optimizations for both HTML and PHP.
|
210 |
+
* Changed: Inputs for emails now have a proper type `email`, instead of a generic `text`.
|
211 |
+
* Changed: Turn off `$phpmailer->SMTPAutoTLS` when `No encryption` option is set to prevent error while sending emails.
|
212 |
+
* Changed: Hide Pepipost for those who are not using it.
|
213 |
+
* Changed: WP CLI support improved.
|
214 |
+
|
215 |
+
= 0.10.1 =
|
216 |
+
* Addition of Pepipost and cleanup of admin page.
|
217 |
+
|
218 |
+
= 0.10.0 =
|
219 |
+
* Addition of Pepipost and cleanup of admin page.
|
220 |
+
|
221 |
+
= 0.9.6 =
|
222 |
+
* Minor security fix, sanitize test email address.
|
223 |
+
|
224 |
+
= 0.9.5 =
|
225 |
+
* Minor security fix, hat tip JD Grimes.
|
226 |
+
|
227 |
+
= 0.9.4 =
|
228 |
+
* Improvement to the test email function, very low priority update.
|
229 |
+
|
230 |
+
= 0.9.3 =
|
231 |
+
* Fixing reported issue with passing by reference. props Adam Conway
|
232 |
+
|
233 |
+
= 0.9.2 =
|
234 |
+
* Removing the deprecation notice.
|
235 |
+
|
236 |
+
= 0.9.1 =
|
237 |
+
* $phpmailer->language became protected in WP 3.2, no longer unset on debug output.
|
238 |
+
|
239 |
+
= 0.9.0 =
|
240 |
+
* Typo in the From email description.
|
241 |
+
* Removed changelog from plugin file, no need to duplicate it.
|
242 |
+
* Optionally set $phpmailer->Sender from from email, helps with sendmail / mail().
|
243 |
+
|
244 |
+
= 0.8.7 =
|
245 |
+
* Fix for a long standing bug that caused an error during plugin activation.
|
246 |
+
|
247 |
+
= 0.8.6 =
|
248 |
+
* The Settings link really does work this time, promise. Apologies for the unnecessary updates.
|
249 |
+
|
250 |
+
= 0.8.5 =
|
251 |
+
* Bugfix, the settings link on the Plugin page was broken by 0.8.4.
|
252 |
+
|
253 |
+
= 0.8.4 =
|
254 |
+
* Minor bugfix, remove use of esc_html() to improve backwards compatibility.
|
255 |
+
* Removed second options page menu props ovidiu.
|
256 |
+
|
257 |
+
= 0.8.3 =
|
258 |
+
* Bugfix, return WPMS_MAIL_FROM_NAME, props nacin.
|
259 |
+
* Add Settings link, props Mike Challis http://profiles.wordpress.org/MikeChallis/
|
260 |
+
|
261 |
+
= 0.8.2 =
|
262 |
+
* Bugfix, call phpmailer_init_smtp() correctly, props Sinklar.
|
263 |
+
|
264 |
+
= 0.8.1 =
|
265 |
+
* Internationalisation improvements.
|
266 |
+
|
267 |
+
= 0.8 =
|
268 |
+
* Added port, SSL/TLS, option whitelisting, validate_email(), and constant options.
|
269 |
+
|
270 |
+
= 0.7 =
|
271 |
+
* Added checks to only override the default from name / email
|
272 |
+
|
273 |
+
= 0.6 =
|
274 |
+
* Added additional SMTP debugging output
|
275 |
+
|
276 |
+
= 0.5.2 =
|
277 |
+
* Fixed a pre 2.3 bug to do with mail from
|
278 |
+
|
279 |
+
= 0.5.1 =
|
280 |
+
* Added a check to display a warning on versions prior to 2.3
|
281 |
+
|
282 |
+
= 0.5.0 =
|
283 |
+
* Upgraded to match 2.3 filters which add a second filter for from name
|
284 |
+
|
285 |
+
= 0.4.2 =
|
286 |
+
* Fixed a bug in 0.4.1 and added more debugging output
|
287 |
+
|
288 |
+
= 0.4.1 =
|
289 |
+
* Added $phpmailer->ErroInfo to the test mail output
|
290 |
+
|
291 |
+
= 0.4 =
|
292 |
+
* Added the test email feature and cleaned up some other bits and pieces
|
293 |
+
|
294 |
+
= 0.3.2 =
|
295 |
+
* Changed to use register_activation_hook for greater compatability
|
296 |
+
|
297 |
+
= 0.3.1 =
|
298 |
+
* Added readme for WP-Plugins.org compatability
|
299 |
+
|
300 |
+
= 0.3 =
|
301 |
+
* Various bugfixes and added From options
|
302 |
+
|
303 |
+
= 0.2 =
|
304 |
+
* Reworked approach as suggested by westi, added options page
|
305 |
+
|
306 |
+
= 0.1 =
|
307 |
+
* Initial approach, copying the wp_mail function and replacing it
|
308 |
+
|
309 |
+
== Upgrade Notice ==
|
310 |
+
|
311 |
+
= 0.10.1 =
|
312 |
+
Addition of Pepipost and cleanup of admin page.
|
313 |
+
|
314 |
+
= 0.10.0 =
|
315 |
+
Addition of Pepipost and cleanup of admin page.
|
316 |
+
|
317 |
+
= 0.9.6 =
|
318 |
+
Minor security fix, sanitize test email address.
|
319 |
+
|
320 |
+
= 0.9.5 =
|
321 |
+
Minor security fix, hat tip JD Grimes.
|
322 |
+
|
323 |
+
= 0.9.4 =
|
324 |
+
Improvement to the test email function, very low priority update.
|
325 |
+
|
326 |
+
= 0.9.3 =
|
327 |
+
Fixing reported issue with passing by reference.
|
328 |
+
|
329 |
+
= 0.9.2 =
|
330 |
+
Removing the deprecation notice.
|
331 |
+
|
332 |
+
= 0.9.1 =
|
333 |
+
Test mail functionality was broken on upgrade to 3.2, now restored.
|
334 |
+
|
335 |
+
= 0.9.0 =
|
336 |
+
Low priority upgrade. Improves the appearance of the options page.
|
337 |
+
|
338 |
+
= 0.8.7 =
|
339 |
+
Very low priority update. Fixes a bug that causes a spurious error during activation.
|
340 |
+
|
341 |
+
= 0.8.6 =
|
342 |
+
Low priority update. The Settings link was still broken in 0.8.5.
|
343 |
+
|
344 |
+
= 0.8.5 =
|
345 |
+
Minor bugfix correcting the Settings link bug introduced in 0.8.4. Very low priority update.
|
346 |
+
|
347 |
+
= 0.8.4 =
|
348 |
+
Minor bugfix for users using constants. Another very low priority upgrade. Apologies for the version creep.
|
349 |
+
|
350 |
+
= 0.8.3 =
|
351 |
+
Minor bugfix for users using constants. Very low priority upgrade.
|
src/AM_Notification.php
CHANGED
@@ -1,452 +1,452 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPMailSMTP;
|
4 |
-
|
5 |
-
/**
|
6 |
-
* Awesome Motive Notifications
|
7 |
-
*
|
8 |
-
* This creates a custom post type (if it doesn't exist) and calls the API to
|
9 |
-
* retrieve notifications for this product.
|
10 |
-
*
|
11 |
-
* @package AwesomeMotive
|
12 |
-
* @author Benjamin Rojas
|
13 |
-
* @license GPL-2.0+
|
14 |
-
* @copyright Copyright (c) 2017, Retyp LLC
|
15 |
-
* @version 1.0.2
|
16 |
-
*/
|
17 |
-
class AM_Notification {
|
18 |
-
/**
|
19 |
-
* The api url we are calling.
|
20 |
-
*
|
21 |
-
* @since 1.0.0
|
22 |
-
*
|
23 |
-
* @var string
|
24 |
-
*/
|
25 |
-
public $api_url = 'https://api.awesomemotive.com/v1/notification/';
|
26 |
-
|
27 |
-
/**
|
28 |
-
* A unique slug for this plugin.
|
29 |
-
* (Not the WordPress plugin slug)
|
30 |
-
*
|
31 |
-
* @since 1.0.0
|
32 |
-
*
|
33 |
-
* @var string
|
34 |
-
*/
|
35 |
-
public $plugin;
|
36 |
-
|
37 |
-
/**
|
38 |
-
* The current plugin version.
|
39 |
-
*
|
40 |
-
* @since 1.0.0
|
41 |
-
*
|
42 |
-
* @var string
|
43 |
-
*/
|
44 |
-
public $plugin_version;
|
45 |
-
|
46 |
-
/**
|
47 |
-
* Flag if a notice has been registered.
|
48 |
-
*
|
49 |
-
* @since 1.0.0
|
50 |
-
*
|
51 |
-
* @var bool
|
52 |
-
*/
|
53 |
-
public static $registered = false;
|
54 |
-
|
55 |
-
/**
|
56 |
-
* Construct.
|
57 |
-
*
|
58 |
-
* @since 1.0.0
|
59 |
-
*
|
60 |
-
* @param string $plugin The plugin slug.
|
61 |
-
* @param mixed $version The version of the plugin.
|
62 |
-
*/
|
63 |
-
public function __construct( $plugin = '', $version = 0 ) {
|
64 |
-
$this->plugin = $plugin;
|
65 |
-
$this->plugin_version = $version;
|
66 |
-
|
67 |
-
add_action( 'init', array( $this, 'custom_post_type' ) );
|
68 |
-
add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
|
69 |
-
add_action( 'admin_notices', array( $this, 'display_notifications' ) );
|
70 |
-
add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
|
71 |
-
}
|
72 |
-
|
73 |
-
/**
|
74 |
-
* Registers a custom post type.
|
75 |
-
*
|
76 |
-
* @since 1.0.0
|
77 |
-
*/
|
78 |
-
public function custom_post_type() {
|
79 |
-
register_post_type( 'amn_' . $this->plugin, array(
|
80 |
-
'label' => $this->plugin . ' Announcements',
|
81 |
-
'can_export' => false,
|
82 |
-
'supports' => false,
|
83 |
-
) );
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Retrieve the remote notifications if the time has expired.
|
88 |
-
*
|
89 |
-
* @since 1.0.0
|
90 |
-
*/
|
91 |
-
public function get_remote_notifications() {
|
92 |
-
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
93 |
-
return;
|
94 |
-
}
|
95 |
-
|
96 |
-
$last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
|
97 |
-
|
98 |
-
if ( $last_checked < strtotime( 'today midnight' ) ) {
|
99 |
-
$plugin_notifications = $this->get_plugin_notifications( 1 );
|
100 |
-
$notification_id = null;
|
101 |
-
|
102 |
-
if ( ! empty( $plugin_notifications ) ) {
|
103 |
-
// Unset it from the array.
|
104 |
-
$notification = $plugin_notifications[0];
|
105 |
-
$notification_id = get_post_meta( $notification->ID, 'notification_id', true );
|
106 |
-
}
|
107 |
-
|
108 |
-
$response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
|
109 |
-
'body' => array(
|
110 |
-
'slug' => $this->plugin,
|
111 |
-
'version' => $this->plugin_version,
|
112 |
-
'last_notification' => $notification_id,
|
113 |
-
),
|
114 |
-
) ) );
|
115 |
-
|
116 |
-
$data = json_decode( $response );
|
117 |
-
|
118 |
-
if ( ! empty( $data->id ) ) {
|
119 |
-
$notifications = array();
|
120 |
-
|
121 |
-
foreach ( (array) $data->slugs as $slug ) {
|
122 |
-
$notifications = array_merge(
|
123 |
-
$notifications,
|
124 |
-
(array) get_posts(
|
125 |
-
array(
|
126 |
-
'post_type' => 'amn_' . $slug,
|
127 |
-
'post_status' => 'all',
|
128 |
-
'meta_key' => 'notification_id',
|
129 |
-
'meta_value' => $data->id,
|
130 |
-
)
|
131 |
-
)
|
132 |
-
);
|
133 |
-
}
|
134 |
-
|
135 |
-
if ( empty( $notifications ) ) {
|
136 |
-
$new_notification_id = wp_insert_post( array(
|
137 |
-
'post_content' => wp_kses_post( $data->content ),
|
138 |
-
'post_type' => 'amn_' . $this->plugin,
|
139 |
-
) );
|
140 |
-
|
141 |
-
update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
|
142 |
-
update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
|
143 |
-
update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
|
144 |
-
update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
|
145 |
-
update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
|
146 |
-
update_post_meta( $new_notification_id, 'viewed', 0 );
|
147 |
-
update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
|
148 |
-
update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
|
149 |
-
}
|
150 |
-
}
|
151 |
-
|
152 |
-
// Possibly revoke notifications.
|
153 |
-
if ( ! empty( $data->revoked ) ) {
|
154 |
-
$this->revoke_notifications( $data->revoked );
|
155 |
-
}
|
156 |
-
|
157 |
-
// Set the option now so we can't run this again until after 24 hours.
|
158 |
-
update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
|
159 |
-
}
|
160 |
-
}
|
161 |
-
|
162 |
-
/**
|
163 |
-
* Get local plugin notifications that have already been set.
|
164 |
-
*
|
165 |
-
* @since 1.0.0
|
166 |
-
*
|
167 |
-
* @param integer $limit Set the limit for how many posts to retrieve.
|
168 |
-
* @param array $args Any top-level arguments to add to the array.
|
169 |
-
*
|
170 |
-
* @return WP_Post[] WP_Post that match the query.
|
171 |
-
*/
|
172 |
-
public function get_plugin_notifications( $limit = -1, $args = array() ) {
|
173 |
-
return get_posts(
|
174 |
-
array(
|
175 |
-
'posts_per_page' => $limit,
|
176 |
-
'post_type' => 'amn_' . $this->plugin,
|
177 |
-
) + $args
|
178 |
-
);
|
179 |
-
}
|
180 |
-
|
181 |
-
/**
|
182 |
-
* Display any notifications that should be displayed.
|
183 |
-
*
|
184 |
-
* @since 1.0.0
|
185 |
-
*/
|
186 |
-
public function display_notifications() {
|
187 |
-
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
188 |
-
return;
|
189 |
-
}
|
190 |
-
|
191 |
-
$plugin_notifications = $this->get_plugin_notifications( -1, array(
|
192 |
-
'post_status' => 'all',
|
193 |
-
'meta_key' => 'viewed',
|
194 |
-
'meta_value' => '0',
|
195 |
-
) );
|
196 |
-
|
197 |
-
$plugin_notifications = $this->validate_notifications( $plugin_notifications );
|
198 |
-
|
199 |
-
if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
|
200 |
-
foreach ( $plugin_notifications as $notification ) {
|
201 |
-
$dismissable = get_post_meta( $notification->ID, 'dismissable', true );
|
202 |
-
$type = get_post_meta( $notification->ID, 'type', true );
|
203 |
-
?>
|
204 |
-
<div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
|
205 |
-
<?php echo $notification->post_content; ?>
|
206 |
-
</div>
|
207 |
-
<script type="text/javascript">
|
208 |
-
jQuery(document).ready(function ($) {
|
209 |
-
$(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
|
210 |
-
$.post(ajaxurl, {
|
211 |
-
action: 'am_notification_dismiss',
|
212 |
-
notification_id: '<?php echo $notification->ID; ?>'
|
213 |
-
});
|
214 |
-
});
|
215 |
-
});
|
216 |
-
</script>
|
217 |
-
<?php
|
218 |
-
}
|
219 |
-
|
220 |
-
self::$registered = true;
|
221 |
-
}
|
222 |
-
}
|
223 |
-
|
224 |
-
/**
|
225 |
-
* Validate the notifications before displaying them.
|
226 |
-
*
|
227 |
-
* @since 1.0.0
|
228 |
-
*
|
229 |
-
* @param array $plugin_notifications An array of plugin notifications.
|
230 |
-
*
|
231 |
-
* @return array A filtered array of plugin notifications.
|
232 |
-
*/
|
233 |
-
public function validate_notifications( $plugin_notifications ) {
|
234 |
-
global $pagenow;
|
235 |
-
|
236 |
-
foreach ( $plugin_notifications as $key => $notification ) {
|
237 |
-
// Location validation.
|
238 |
-
$location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
|
239 |
-
$continue = false;
|
240 |
-
if ( ! in_array( 'everywhere', $location, true ) ) {
|
241 |
-
if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
|
242 |
-
$continue = true;
|
243 |
-
}
|
244 |
-
|
245 |
-
if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
|
246 |
-
$continue = true;
|
247 |
-
}
|
248 |
-
|
249 |
-
if ( ! $continue ) {
|
250 |
-
unset( $plugin_notifications[ $key ] );
|
251 |
-
}
|
252 |
-
}
|
253 |
-
|
254 |
-
// Plugin validation (OR conditional).
|
255 |
-
$plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
|
256 |
-
$continue = false;
|
257 |
-
if ( ! empty( $plugins ) ) {
|
258 |
-
foreach ( $plugins as $plugin ) {
|
259 |
-
if ( is_plugin_active( $plugin ) ) {
|
260 |
-
$continue = true;
|
261 |
-
}
|
262 |
-
}
|
263 |
-
|
264 |
-
if ( ! $continue ) {
|
265 |
-
unset( $plugin_notifications[ $key ] );
|
266 |
-
}
|
267 |
-
}
|
268 |
-
|
269 |
-
// Theme validation.
|
270 |
-
$theme = get_post_meta( $notification->ID, 'theme', true );
|
271 |
-
$continue = (string) wp_get_theme() === $theme;
|
272 |
-
|
273 |
-
if ( ! empty( $theme ) && ! $continue ) {
|
274 |
-
unset( $plugin_notifications[ $key ] );
|
275 |
-
}
|
276 |
-
|
277 |
-
// Version validation.
|
278 |
-
$version = get_post_meta( $notification->ID, 'version', true );
|
279 |
-
$continue = false;
|
280 |
-
if ( ! empty( $version ) ) {
|
281 |
-
if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
|
282 |
-
$continue = true;
|
283 |
-
}
|
284 |
-
|
285 |
-
if ( ! $continue ) {
|
286 |
-
unset( $plugin_notifications[ $key ] );
|
287 |
-
}
|
288 |
-
}
|
289 |
-
|
290 |
-
// Expiration validation.
|
291 |
-
$expiration = get_post_meta( $notification->ID, 'expiration', true );
|
292 |
-
$continue = false;
|
293 |
-
if ( ! empty( $expiration ) ) {
|
294 |
-
if ( $expiration > time() ) {
|
295 |
-
$continue = true;
|
296 |
-
}
|
297 |
-
|
298 |
-
if ( ! $continue ) {
|
299 |
-
unset( $plugin_notifications[ $key ] );
|
300 |
-
}
|
301 |
-
}
|
302 |
-
|
303 |
-
// Plan validation.
|
304 |
-
$plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
|
305 |
-
$continue = false;
|
306 |
-
if ( ! empty( $plans ) ) {
|
307 |
-
$level = $this->get_plan_level();
|
308 |
-
if ( in_array( $level, $plans, true ) ) {
|
309 |
-
$continue = true;
|
310 |
-
}
|
311 |
-
|
312 |
-
if ( ! $continue ) {
|
313 |
-
unset( $plugin_notifications[ $key ] );
|
314 |
-
}
|
315 |
-
}
|
316 |
-
}
|
317 |
-
|
318 |
-
return $plugin_notifications;
|
319 |
-
}
|
320 |
-
|
321 |
-
/**
|
322 |
-
* Grab the current plan level.
|
323 |
-
*
|
324 |
-
* @since 1.0.0
|
325 |
-
*
|
326 |
-
* @return string The current plan level.
|
327 |
-
*/
|
328 |
-
public function get_plan_level() {
|
329 |
-
// Prepare variables.
|
330 |
-
$key = '';
|
331 |
-
$level = '';
|
332 |
-
$option = false;
|
333 |
-
switch ( $this->plugin ) {
|
334 |
-
case 'wpforms' :
|
335 |
-
$option = get_option( 'wpforms_license' );
|
336 |
-
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
337 |
-
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
338 |
-
|
339 |
-
// Possibly check for a constant.
|
340 |
-
if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
|
341 |
-
$key = WPFORMS_LICENSE_KEY;
|
342 |
-
}
|
343 |
-
break;
|
344 |
-
case 'mi' :
|
345 |
-
$option = get_option( 'monsterinsights_license' );
|
346 |
-
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
347 |
-
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
348 |
-
|
349 |
-
// Possibly check for a constant.
|
350 |
-
if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
|
351 |
-
$key = MONSTERINSIGHTS_LICENSE_KEY;
|
352 |
-
}
|
353 |
-
break;
|
354 |
-
case 'sol' :
|
355 |
-
$option = get_option( 'soliloquy' );
|
356 |
-
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
357 |
-
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
358 |
-
|
359 |
-
// Possibly check for a constant.
|
360 |
-
if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
|
361 |
-
$key = SOLILOQUY_LICENSE_KEY;
|
362 |
-
}
|
363 |
-
break;
|
364 |
-
case 'envira' :
|
365 |
-
$option = get_option( 'envira_gallery' );
|
366 |
-
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
367 |
-
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
368 |
-
|
369 |
-
// Possibly check for a constant.
|
370 |
-
if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
|
371 |
-
$key = ENVIRA_LICENSE_KEY;
|
372 |
-
}
|
373 |
-
break;
|
374 |
-
case 'om' :
|
375 |
-
$option = get_option( 'optin_monster_api' );
|
376 |
-
$key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
|
377 |
-
|
378 |
-
// Possibly check for a constant.
|
379 |
-
if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
|
380 |
-
$key = OPTINMONSTER_REST_API_LICENSE_KEY;
|
381 |
-
}
|
382 |
-
|
383 |
-
// If the key is still empty, check for the old legacy key.
|
384 |
-
if ( empty( $key ) ) {
|
385 |
-
$key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
|
386 |
-
}
|
387 |
-
break;
|
388 |
-
}
|
389 |
-
|
390 |
-
// Possibly set the level to 'none' if the key is empty and no level has been set.
|
391 |
-
if ( empty( $key ) && empty( $level ) ) {
|
392 |
-
$level = 'none';
|
393 |
-
}
|
394 |
-
|
395 |
-
// Normalize the level.
|
396 |
-
switch ( $level ) {
|
397 |
-
case 'bronze' :
|
398 |
-
case 'personal' :
|
399 |
-
$level = 'basic';
|
400 |
-
break;
|
401 |
-
case 'silver' :
|
402 |
-
case 'multi' :
|
403 |
-
$level = 'plus';
|
404 |
-
break;
|
405 |
-
case 'gold' :
|
406 |
-
case 'developer' :
|
407 |
-
$level = 'pro';
|
408 |
-
break;
|
409 |
-
case 'platinum' :
|
410 |
-
case 'master' :
|
411 |
-
$level = 'ultimate';
|
412 |
-
break;
|
413 |
-
}
|
414 |
-
|
415 |
-
// Return the plan level.
|
416 |
-
return $level;
|
417 |
-
}
|
418 |
-
|
419 |
-
/**
|
420 |
-
* Dismiss the notification via AJAX.
|
421 |
-
*
|
422 |
-
* @since 1.0.0
|
423 |
-
*/
|
424 |
-
public function dismiss_notification() {
|
425 |
-
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
426 |
-
die;
|
427 |
-
}
|
428 |
-
|
429 |
-
$notification_id = intval( $_POST['notification_id'] );
|
430 |
-
update_post_meta( $notification_id, 'viewed', 1 );
|
431 |
-
die;
|
432 |
-
}
|
433 |
-
|
434 |
-
/**
|
435 |
-
* Revokes notifications.
|
436 |
-
*
|
437 |
-
* @since 1.0.0
|
438 |
-
*
|
439 |
-
* @param array $ids An array of notification IDs to revoke.
|
440 |
-
*/
|
441 |
-
public function revoke_notifications( $ids ) {
|
442 |
-
// Loop through each of the IDs and find the post that has it as meta.
|
443 |
-
foreach ( (array) $ids as $id ) {
|
444 |
-
$notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
|
445 |
-
if ( $notifications ) {
|
446 |
-
foreach ( $notifications as $notification ) {
|
447 |
-
update_post_meta( $notification->ID, 'viewed', 1 );
|
448 |
-
}
|
449 |
-
}
|
450 |
-
}
|
451 |
-
}
|
452 |
-
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace WPMailSMTP;
|
4 |
+
|
5 |
+
/**
|
6 |
+
* Awesome Motive Notifications
|
7 |
+
*
|
8 |
+
* This creates a custom post type (if it doesn't exist) and calls the API to
|
9 |
+
* retrieve notifications for this product.
|
10 |
+
*
|
11 |
+
* @package AwesomeMotive
|
12 |
+
* @author Benjamin Rojas
|
13 |
+
* @license GPL-2.0+
|
14 |
+
* @copyright Copyright (c) 2017, Retyp LLC
|
15 |
+
* @version 1.0.2
|
16 |
+
*/
|
17 |
+
class AM_Notification {
|
18 |
+
/**
|
19 |
+
* The api url we are calling.
|
20 |
+
*
|
21 |
+
* @since 1.0.0
|
22 |
+
*
|
23 |
+
* @var string
|
24 |
+
*/
|
25 |
+
public $api_url = 'https://api.awesomemotive.com/v1/notification/';
|
26 |
+
|
27 |
+
/**
|
28 |
+
* A unique slug for this plugin.
|
29 |
+
* (Not the WordPress plugin slug)
|
30 |
+
*
|
31 |
+
* @since 1.0.0
|
32 |
+
*
|
33 |
+
* @var string
|
34 |
+
*/
|
35 |
+
public $plugin;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* The current plugin version.
|
39 |
+
*
|
40 |
+
* @since 1.0.0
|
41 |
+
*
|
42 |
+
* @var string
|
43 |
+
*/
|
44 |
+
public $plugin_version;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Flag if a notice has been registered.
|
48 |
+
*
|
49 |
+
* @since 1.0.0
|
50 |
+
*
|
51 |
+
* @var bool
|
52 |
+
*/
|
53 |
+
public static $registered = false;
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Construct.
|
57 |
+
*
|
58 |
+
* @since 1.0.0
|
59 |
+
*
|
60 |
+
* @param string $plugin The plugin slug.
|
61 |
+
* @param mixed $version The version of the plugin.
|
62 |
+
*/
|
63 |
+
public function __construct( $plugin = '', $version = 0 ) {
|
64 |
+
$this->plugin = $plugin;
|
65 |
+
$this->plugin_version = $version;
|
66 |
+
|
67 |
+
add_action( 'init', array( $this, 'custom_post_type' ) );
|
68 |
+
add_action( 'admin_init', array( $this, 'get_remote_notifications' ), 100 );
|
69 |
+
add_action( 'admin_notices', array( $this, 'display_notifications' ) );
|
70 |
+
add_action( 'wp_ajax_am_notification_dismiss', array( $this, 'dismiss_notification' ) );
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Registers a custom post type.
|
75 |
+
*
|
76 |
+
* @since 1.0.0
|
77 |
+
*/
|
78 |
+
public function custom_post_type() {
|
79 |
+
register_post_type( 'amn_' . $this->plugin, array(
|
80 |
+
'label' => $this->plugin . ' Announcements',
|
81 |
+
'can_export' => false,
|
82 |
+
'supports' => false,
|
83 |
+
) );
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Retrieve the remote notifications if the time has expired.
|
88 |
+
*
|
89 |
+
* @since 1.0.0
|
90 |
+
*/
|
91 |
+
public function get_remote_notifications() {
|
92 |
+
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
93 |
+
return;
|
94 |
+
}
|
95 |
+
|
96 |
+
$last_checked = get_option( '_amn_' . $this->plugin . '_last_checked', strtotime( '-1 week' ) );
|
97 |
+
|
98 |
+
if ( $last_checked < strtotime( 'today midnight' ) ) {
|
99 |
+
$plugin_notifications = $this->get_plugin_notifications( 1 );
|
100 |
+
$notification_id = null;
|
101 |
+
|
102 |
+
if ( ! empty( $plugin_notifications ) ) {
|
103 |
+
// Unset it from the array.
|
104 |
+
$notification = $plugin_notifications[0];
|
105 |
+
$notification_id = get_post_meta( $notification->ID, 'notification_id', true );
|
106 |
+
}
|
107 |
+
|
108 |
+
$response = wp_remote_retrieve_body( wp_remote_post( $this->api_url, array(
|
109 |
+
'body' => array(
|
110 |
+
'slug' => $this->plugin,
|
111 |
+
'version' => $this->plugin_version,
|
112 |
+
'last_notification' => $notification_id,
|
113 |
+
),
|
114 |
+
) ) );
|
115 |
+
|
116 |
+
$data = json_decode( $response );
|
117 |
+
|
118 |
+
if ( ! empty( $data->id ) ) {
|
119 |
+
$notifications = array();
|
120 |
+
|
121 |
+
foreach ( (array) $data->slugs as $slug ) {
|
122 |
+
$notifications = array_merge(
|
123 |
+
$notifications,
|
124 |
+
(array) get_posts(
|
125 |
+
array(
|
126 |
+
'post_type' => 'amn_' . $slug,
|
127 |
+
'post_status' => 'all',
|
128 |
+
'meta_key' => 'notification_id',
|
129 |
+
'meta_value' => $data->id,
|
130 |
+
)
|
131 |
+
)
|
132 |
+
);
|
133 |
+
}
|
134 |
+
|
135 |
+
if ( empty( $notifications ) ) {
|
136 |
+
$new_notification_id = wp_insert_post( array(
|
137 |
+
'post_content' => wp_kses_post( $data->content ),
|
138 |
+
'post_type' => 'amn_' . $this->plugin,
|
139 |
+
) );
|
140 |
+
|
141 |
+
update_post_meta( $new_notification_id, 'notification_id', absint( $data->id ) );
|
142 |
+
update_post_meta( $new_notification_id, 'type', sanitize_text_field( trim( $data->type ) ) );
|
143 |
+
update_post_meta( $new_notification_id, 'dismissable', (bool) $data->dismissible ? 1 : 0 );
|
144 |
+
update_post_meta( $new_notification_id, 'location', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->location ) : json_encode( $data->location ) );
|
145 |
+
update_post_meta( $new_notification_id, 'version', sanitize_text_field( trim( $data->version ) ) );
|
146 |
+
update_post_meta( $new_notification_id, 'viewed', 0 );
|
147 |
+
update_post_meta( $new_notification_id, 'expiration', $data->expiration ? absint( $data->expiration ) : false );
|
148 |
+
update_post_meta( $new_notification_id, 'plans', function_exists( 'wp_json_encode' ) ? wp_json_encode( $data->plans ) : json_encode( $data->plans ) );
|
149 |
+
}
|
150 |
+
}
|
151 |
+
|
152 |
+
// Possibly revoke notifications.
|
153 |
+
if ( ! empty( $data->revoked ) ) {
|
154 |
+
$this->revoke_notifications( $data->revoked );
|
155 |
+
}
|
156 |
+
|
157 |
+
// Set the option now so we can't run this again until after 24 hours.
|
158 |
+
update_option( '_amn_' . $this->plugin . '_last_checked', strtotime( 'today midnight' ) );
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Get local plugin notifications that have already been set.
|
164 |
+
*
|
165 |
+
* @since 1.0.0
|
166 |
+
*
|
167 |
+
* @param integer $limit Set the limit for how many posts to retrieve.
|
168 |
+
* @param array $args Any top-level arguments to add to the array.
|
169 |
+
*
|
170 |
+
* @return WP_Post[] WP_Post that match the query.
|
171 |
+
*/
|
172 |
+
public function get_plugin_notifications( $limit = -1, $args = array() ) {
|
173 |
+
return get_posts(
|
174 |
+
array(
|
175 |
+
'posts_per_page' => $limit,
|
176 |
+
'post_type' => 'amn_' . $this->plugin,
|
177 |
+
) + $args
|
178 |
+
);
|
179 |
+
}
|
180 |
+
|
181 |
+
/**
|
182 |
+
* Display any notifications that should be displayed.
|
183 |
+
*
|
184 |
+
* @since 1.0.0
|
185 |
+
*/
|
186 |
+
public function display_notifications() {
|
187 |
+
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
188 |
+
return;
|
189 |
+
}
|
190 |
+
|
191 |
+
$plugin_notifications = $this->get_plugin_notifications( -1, array(
|
192 |
+
'post_status' => 'all',
|
193 |
+
'meta_key' => 'viewed',
|
194 |
+
'meta_value' => '0',
|
195 |
+
) );
|
196 |
+
|
197 |
+
$plugin_notifications = $this->validate_notifications( $plugin_notifications );
|
198 |
+
|
199 |
+
if ( ! empty( $plugin_notifications ) && ! self::$registered ) {
|
200 |
+
foreach ( $plugin_notifications as $notification ) {
|
201 |
+
$dismissable = get_post_meta( $notification->ID, 'dismissable', true );
|
202 |
+
$type = get_post_meta( $notification->ID, 'type', true );
|
203 |
+
?>
|
204 |
+
<div class="am-notification am-notification-<?php echo $notification->ID; ?> notice notice-<?php echo $type; ?><?php echo $dismissable ? ' is-dismissible' : ''; ?>">
|
205 |
+
<?php echo $notification->post_content; ?>
|
206 |
+
</div>
|
207 |
+
<script type="text/javascript">
|
208 |
+
jQuery(document).ready(function ($) {
|
209 |
+
$(document).on('click', '.am-notification-<?php echo $notification->ID; ?> button.notice-dismiss', function (event) {
|
210 |
+
$.post(ajaxurl, {
|
211 |
+
action: 'am_notification_dismiss',
|
212 |
+
notification_id: '<?php echo $notification->ID; ?>'
|
213 |
+
});
|
214 |
+
});
|
215 |
+
});
|
216 |
+
</script>
|
217 |
+
<?php
|
218 |
+
}
|
219 |
+
|
220 |
+
self::$registered = true;
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Validate the notifications before displaying them.
|
226 |
+
*
|
227 |
+
* @since 1.0.0
|
228 |
+
*
|
229 |
+
* @param array $plugin_notifications An array of plugin notifications.
|
230 |
+
*
|
231 |
+
* @return array A filtered array of plugin notifications.
|
232 |
+
*/
|
233 |
+
public function validate_notifications( $plugin_notifications ) {
|
234 |
+
global $pagenow;
|
235 |
+
|
236 |
+
foreach ( $plugin_notifications as $key => $notification ) {
|
237 |
+
// Location validation.
|
238 |
+
$location = (array) json_decode( get_post_meta( $notification->ID, 'location', true ) );
|
239 |
+
$continue = false;
|
240 |
+
if ( ! in_array( 'everywhere', $location, true ) ) {
|
241 |
+
if ( in_array( 'index.php', $location, true ) && 'index.php' === $pagenow ) {
|
242 |
+
$continue = true;
|
243 |
+
}
|
244 |
+
|
245 |
+
if ( in_array( 'plugins.php', $location, true ) && 'plugins.php' === $pagenow ) {
|
246 |
+
$continue = true;
|
247 |
+
}
|
248 |
+
|
249 |
+
if ( ! $continue ) {
|
250 |
+
unset( $plugin_notifications[ $key ] );
|
251 |
+
}
|
252 |
+
}
|
253 |
+
|
254 |
+
// Plugin validation (OR conditional).
|
255 |
+
$plugins = (array) json_decode( get_post_meta( $notification->ID, 'plugins', true ) );
|
256 |
+
$continue = false;
|
257 |
+
if ( ! empty( $plugins ) ) {
|
258 |
+
foreach ( $plugins as $plugin ) {
|
259 |
+
if ( is_plugin_active( $plugin ) ) {
|
260 |
+
$continue = true;
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
if ( ! $continue ) {
|
265 |
+
unset( $plugin_notifications[ $key ] );
|
266 |
+
}
|
267 |
+
}
|
268 |
+
|
269 |
+
// Theme validation.
|
270 |
+
$theme = get_post_meta( $notification->ID, 'theme', true );
|
271 |
+
$continue = (string) wp_get_theme() === $theme;
|
272 |
+
|
273 |
+
if ( ! empty( $theme ) && ! $continue ) {
|
274 |
+
unset( $plugin_notifications[ $key ] );
|
275 |
+
}
|
276 |
+
|
277 |
+
// Version validation.
|
278 |
+
$version = get_post_meta( $notification->ID, 'version', true );
|
279 |
+
$continue = false;
|
280 |
+
if ( ! empty( $version ) ) {
|
281 |
+
if ( version_compare( $this->plugin_version, $version, '<=' ) ) {
|
282 |
+
$continue = true;
|
283 |
+
}
|
284 |
+
|
285 |
+
if ( ! $continue ) {
|
286 |
+
unset( $plugin_notifications[ $key ] );
|
287 |
+
}
|
288 |
+
}
|
289 |
+
|
290 |
+
// Expiration validation.
|
291 |
+
$expiration = get_post_meta( $notification->ID, 'expiration', true );
|
292 |
+
$continue = false;
|
293 |
+
if ( ! empty( $expiration ) ) {
|
294 |
+
if ( $expiration > time() ) {
|
295 |
+
$continue = true;
|
296 |
+
}
|
297 |
+
|
298 |
+
if ( ! $continue ) {
|
299 |
+
unset( $plugin_notifications[ $key ] );
|
300 |
+
}
|
301 |
+
}
|
302 |
+
|
303 |
+
// Plan validation.
|
304 |
+
$plans = (array) json_decode( get_post_meta( $notification->ID, 'plans', true ) );
|
305 |
+
$continue = false;
|
306 |
+
if ( ! empty( $plans ) ) {
|
307 |
+
$level = $this->get_plan_level();
|
308 |
+
if ( in_array( $level, $plans, true ) ) {
|
309 |
+
$continue = true;
|
310 |
+
}
|
311 |
+
|
312 |
+
if ( ! $continue ) {
|
313 |
+
unset( $plugin_notifications[ $key ] );
|
314 |
+
}
|
315 |
+
}
|
316 |
+
}
|
317 |
+
|
318 |
+
return $plugin_notifications;
|
319 |
+
}
|
320 |
+
|
321 |
+
/**
|
322 |
+
* Grab the current plan level.
|
323 |
+
*
|
324 |
+
* @since 1.0.0
|
325 |
+
*
|
326 |
+
* @return string The current plan level.
|
327 |
+
*/
|
328 |
+
public function get_plan_level() {
|
329 |
+
// Prepare variables.
|
330 |
+
$key = '';
|
331 |
+
$level = '';
|
332 |
+
$option = false;
|
333 |
+
switch ( $this->plugin ) {
|
334 |
+
case 'wpforms' :
|
335 |
+
$option = get_option( 'wpforms_license' );
|
336 |
+
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
337 |
+
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
338 |
+
|
339 |
+
// Possibly check for a constant.
|
340 |
+
if ( empty( $key ) && defined( 'WPFORMS_LICENSE_KEY' ) ) {
|
341 |
+
$key = WPFORMS_LICENSE_KEY;
|
342 |
+
}
|
343 |
+
break;
|
344 |
+
case 'mi' :
|
345 |
+
$option = get_option( 'monsterinsights_license' );
|
346 |
+
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
347 |
+
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
348 |
+
|
349 |
+
// Possibly check for a constant.
|
350 |
+
if ( empty( $key ) && defined( 'MONSTERINSIGHTS_LICENSE_KEY' ) && is_string( MONSTERINSIGHTS_LICENSE_KEY ) && strlen( MONSTERINSIGHTS_LICENSE_KEY ) > 10 ) {
|
351 |
+
$key = MONSTERINSIGHTS_LICENSE_KEY;
|
352 |
+
}
|
353 |
+
break;
|
354 |
+
case 'sol' :
|
355 |
+
$option = get_option( 'soliloquy' );
|
356 |
+
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
357 |
+
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
358 |
+
|
359 |
+
// Possibly check for a constant.
|
360 |
+
if ( empty( $key ) && defined( 'SOLILOQUY_LICENSE_KEY' ) ) {
|
361 |
+
$key = SOLILOQUY_LICENSE_KEY;
|
362 |
+
}
|
363 |
+
break;
|
364 |
+
case 'envira' :
|
365 |
+
$option = get_option( 'envira_gallery' );
|
366 |
+
$key = is_array( $option ) && isset( $option['key'] ) ? $option['key'] : '';
|
367 |
+
$level = is_array( $option ) && isset( $option['type'] ) ? $option['type'] : '';
|
368 |
+
|
369 |
+
// Possibly check for a constant.
|
370 |
+
if ( empty( $key ) && defined( 'ENVIRA_LICENSE_KEY' ) ) {
|
371 |
+
$key = ENVIRA_LICENSE_KEY;
|
372 |
+
}
|
373 |
+
break;
|
374 |
+
case 'om' :
|
375 |
+
$option = get_option( 'optin_monster_api' );
|
376 |
+
$key = is_array( $option ) && isset( $option['api']['apikey'] ) ? $option['api']['apikey'] : '';
|
377 |
+
|
378 |
+
// Possibly check for a constant.
|
379 |
+
if ( empty( $key ) && defined( 'OPTINMONSTER_REST_API_LICENSE_KEY' ) ) {
|
380 |
+
$key = OPTINMONSTER_REST_API_LICENSE_KEY;
|
381 |
+
}
|
382 |
+
|
383 |
+
// If the key is still empty, check for the old legacy key.
|
384 |
+
if ( empty( $key ) ) {
|
385 |
+
$key = is_array( $option ) && isset( $option['api']['key'] ) ? $option['api']['key'] : '';
|
386 |
+
}
|
387 |
+
break;
|
388 |
+
}
|
389 |
+
|
390 |
+
// Possibly set the level to 'none' if the key is empty and no level has been set.
|
391 |
+
if ( empty( $key ) && empty( $level ) ) {
|
392 |
+
$level = 'none';
|
393 |
+
}
|
394 |
+
|
395 |
+
// Normalize the level.
|
396 |
+
switch ( $level ) {
|
397 |
+
case 'bronze' :
|
398 |
+
case 'personal' :
|
399 |
+
$level = 'basic';
|
400 |
+
break;
|
401 |
+
case 'silver' :
|
402 |
+
case 'multi' :
|
403 |
+
$level = 'plus';
|
404 |
+
break;
|
405 |
+
case 'gold' :
|
406 |
+
case 'developer' :
|
407 |
+
$level = 'pro';
|
408 |
+
break;
|
409 |
+
case 'platinum' :
|
410 |
+
case 'master' :
|
411 |
+
$level = 'ultimate';
|
412 |
+
break;
|
413 |
+
}
|
414 |
+
|
415 |
+
// Return the plan level.
|
416 |
+
return $level;
|
417 |
+
}
|
418 |
+
|
419 |
+
/**
|
420 |
+
* Dismiss the notification via AJAX.
|
421 |
+
*
|
422 |
+
* @since 1.0.0
|
423 |
+
*/
|
424 |
+
public function dismiss_notification() {
|
425 |
+
if ( ! current_user_can( apply_filters( 'am_notifications_display', 'manage_options' ) ) ) {
|
426 |
+
die;
|
427 |
+
}
|
428 |
+
|
429 |
+
$notification_id = intval( $_POST['notification_id'] );
|
430 |
+
update_post_meta( $notification_id, 'viewed', 1 );
|
431 |
+
die;
|
432 |
+
}
|
433 |
+
|
434 |
+
/**
|
435 |
+
* Revokes notifications.
|
436 |
+
*
|
437 |
+
* @since 1.0.0
|
438 |
+
*
|
439 |
+
* @param array $ids An array of notification IDs to revoke.
|
440 |
+
*/
|
441 |
+
public function revoke_notifications( $ids ) {
|
442 |
+
// Loop through each of the IDs and find the post that has it as meta.
|
443 |
+
foreach ( (array) $ids as $id ) {
|
444 |
+
$notifications = $this->get_plugin_notifications( -1, array( 'post_status' => 'all', 'meta_key' => 'notification_id', 'meta_value' => $id ) );
|
445 |
+
if ( $notifications ) {
|
446 |
+
foreach ( $notifications as $notification ) {
|
447 |
+
update_post_meta( $notification->ID, 'viewed', 1 );
|
448 |
+
}
|
449 |
+
}
|
450 |
+
}
|
451 |
+
}
|
452 |
+
}
|
src/Admin/Area.php
CHANGED
@@ -1,457 +1,457 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
namespace WPMailSMTP\Admin;
|
4 |
-
|
5 |
-
use WPMailSMTP\WP;
|
6 |
-
|
7 |
-
/**
|
8 |
-
* Class Area registers and process all wp-admin display functionality.
|
9 |
-
*
|
10 |
-
* @since 1.0.0
|
11 |
-
*/
|
12 |
-
class Area {
|
13 |
-
|
14 |
-
/**
|
15 |
-
* @var string Slug of the admin area page.
|
16 |
-
*/
|
17 |
-
const SLUG = 'wp-mail-smtp';
|
18 |
-
|
19 |
-
/**
|
20 |
-
* @var string Admin page unique hook.
|
21 |
-
*/
|
22 |
-
public $hook;
|
23 |
-
|
24 |
-
/**
|
25 |
-
* @var PageAbstract[]
|
26 |
-
*/
|
27 |
-
private $pages;
|
28 |
-
|
29 |
-
/**
|
30 |
-
* Area constructor.
|
31 |
-
*
|
32 |
-
* @since 1.0.0
|
33 |
-
*/
|
34 |
-
public function __construct() {
|
35 |
-
$this->hooks();
|
36 |
-
}
|
37 |
-
|
38 |
-
/**
|
39 |
-
* Assign all hooks to proper places.
|
40 |
-
*
|
41 |
-
* @since 1.0.0
|
42 |
-
*/
|
43 |
-
protected function hooks() {
|
44 |
-
|
45 |
-
// Add the Settings link to a plugin on Plugins page.
|
46 |
-
add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_link' ), 10, 2 );
|
47 |
-
|
48 |
-
// Add the options page.
|
49 |
-
add_action( 'admin_menu', array( $this, 'add_admin_options_page' ) );
|
50 |
-
|
51 |
-
// Admin footer text.
|
52 |
-
add_filter( 'admin_footer_text', array( $this, 'get_admin_footer' ), 1, 2 );
|
53 |
-
|
54 |
-
// Enqueue admin area scripts and styles.
|
55 |
-
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
|
56 |
-
|
57 |
-
// Process the admin page forms actions.
|
58 |
-
add_action( 'admin_init', array( $this, 'process_actions' ) );
|
59 |
-
|
60 |
-
// Display custom notices based on the error/success codes.
|
61 |
-
add_action( 'admin_init', array( $this, 'display_custom_auth_notices' ) );
|
62 |
-
|
63 |
-
// Outputs the plugin admin header.
|
64 |
-
add_action( 'in_admin_header', array( $this, 'display_admin_header' ), 100 );
|
65 |
-
|
66 |
-
// Hide all unrelated to the plugin notices on the plugin admin pages.
|
67 |
-
add_action( 'admin_print_scripts', array( $this, 'hide_unrelated_notices' ) );
|
68 |
-
}
|
69 |
-
|
70 |
-
/**
|
71 |
-
* Display custom notices based on the error/success codes.
|
72 |
-
*
|
73 |
-
* @since 1.0.0
|
74 |
-
*/
|
75 |
-
public function display_custom_auth_notices() {
|
76 |
-
|
77 |
-
$error = isset( $_GET['error'] ) ? $_GET['error'] : '';
|
78 |
-
$success = isset( $_GET['success'] ) ? $_GET['success'] : '';
|
79 |
-
|
80 |
-
if ( empty( $error ) && empty( $success ) ) {
|
81 |
-
return;
|
82 |
-
}
|
83 |
-
|
84 |
-
switch ( $error ) {
|
85 |
-
case 'google_access_denied':
|
86 |
-
WP::add_admin_notice(
|
87 |
-
/* translators: %s - error code, returned by Google API. */
|
88 |
-
sprintf( esc_html__( 'There was an error while processing the authentication request: %s. Please try again.', 'wp-mail-smtp' ), '<code>' . $error . '</code>' ),
|
89 |
-
WP::ADMIN_NOTICE_ERROR
|
90 |
-
);
|
91 |
-
break;
|
92 |
-
|
93 |
-
case 'google_no_code_scope':
|
94 |
-
WP::add_admin_notice(
|
95 |
-
esc_html__( 'There was an error while processing the authentication request. Please try again.', 'wp-mail-smtp' ),
|
96 |
-
WP::ADMIN_NOTICE_ERROR
|
97 |
-
);
|
98 |
-
break;
|
99 |
-
|
100 |
-
case 'google_no_clients':
|
101 |
-
WP::add_admin_notice(
|
102 |
-
esc_html__( 'There was an error while processing the authentication request. Please make sure that you have Client ID and Client Secret both valid and saved.', 'wp-mail-smtp' ),
|
103 |
-
WP::ADMIN_NOTICE_ERROR
|
104 |
-
);
|
105 |
-
break;
|
106 |
-
}
|
107 |
-
|
108 |
-
switch ( $success ) {
|
109 |
-
case 'google_site_linked':
|
110 |
-
WP::add_admin_notice(
|
111 |
-
esc_html__( 'You have successfully linked the current site with your Google API project. Now you can start sending emails through Google.', 'wp-mail-smtp' ),
|
112 |
-
WP::ADMIN_NOTICE_SUCCESS
|
113 |
-
);
|
114 |
-
break;
|
115 |
-
}
|
116 |
-
}
|
117 |
-
|
118 |
-
/**
|
119 |
-
* Add admin area menu item.
|
120 |
-
*
|
121 |
-
* @since 1.0.0
|
122 |
-
*/
|
123 |
-
public function add_admin_options_page() {
|
124 |
-
|
125 |
-
$this->hook = add_options_page(
|
126 |
-
esc_html__( 'WP Mail SMTP Options', 'wp-mail-smtp' ),
|
127 |
-
esc_html__( 'WP Mail SMTP', 'wp-mail-smtp' ),
|
128 |
-
'manage_options',
|
129 |
-
self::SLUG,
|
130 |
-
array( $this, 'display' )
|
131 |
-
);
|
132 |
-
}
|
133 |
-
|
134 |
-
/**
|
135 |
-
* Enqueue admin area scripts and styles.
|
136 |
-
*
|
137 |
-
* @since 1.0.0
|
138 |
-
*
|
139 |
-
* @param string $hook
|
140 |
-
*/
|
141 |
-
public function enqueue_assets( $hook ) {
|
142 |
-
|
143 |
-
if ( $hook !== $this->hook ) {
|
144 |
-
return;
|
145 |
-
}
|
146 |
-
|
147 |
-
wp_enqueue_style(
|
148 |
-
'wp-mail-smtp-admin',
|
149 |
-
wp_mail_smtp()->plugin_url . '/assets/css/smtp-admin.min.css',
|
150 |
-
false,
|
151 |
-
WPMS_PLUGIN_VER
|
152 |
-
);
|
153 |
-
|
154 |
-
wp_enqueue_script(
|
155 |
-
'wp-mail-smtp-admin',
|
156 |
-
wp_mail_smtp()->plugin_url . '/assets/js/smtp-admin' . WP::asset_min() . '.js',
|
157 |
-
array( 'jquery' ),
|
158 |
-
WPMS_PLUGIN_VER
|
159 |
-
);
|
160 |
-
}
|
161 |
-
|
162 |
-
/**
|
163 |
-
* Outputs the plugin admin header.
|
164 |
-
*
|
165 |
-
* @since 1.0.0
|
166 |
-
*/
|
167 |
-
public function display_admin_header() {
|
168 |
-
|
169 |
-
// Bail if we're not on a plugin page.
|
170 |
-
if ( ! $this->is_admin_page() ) {
|
171 |
-
return;
|
172 |
-
}
|
173 |
-
?>
|
174 |
-
|
175 |
-
<div id="wp-mail-smtp-header">
|
176 |
-
<!--suppress HtmlUnknownTarget -->
|
177 |
-
<img class="wp-mail-smtp-header-logo" src="<?php echo wp_mail_smtp()->plugin_url; ?>/assets/images/logo.png" alt="WP Mail SMTP"/>
|
178 |
-
</div>
|
179 |
-
|
180 |
-
<?php
|
181 |
-
}
|
182 |
-
|
183 |
-
/**
|
184 |
-
* Display a text to ask users to review the plugin on WP.org.
|
185 |
-
*
|
186 |
-
* @since 1.0.0
|
187 |
-
*
|
188 |
-
* @param string $text
|
189 |
-
*
|
190 |
-
* @return string
|
191 |
-
*/
|
192 |
-
public function get_admin_footer( $text ) {
|
193 |
-
|
194 |
-
if ( $this->is_admin_page() ) {
|
195 |
-
$url = 'https://wordpress.org/support/plugin/wp-mail-smtp/reviews/?filter=5#new-post';
|
196 |
-
|
197 |
-
$text = sprintf(
|
198 |
-
/* translators: %1$s - WP.org link; %2$s - same WP.org link. */
|
199 |
-
__( 'Please rate <strong>WP Mail SMTP</strong> <a href="%1$s" target="_blank" rel="noopener noreferrer">★★★★★</a> on <a href="%2$s" target="_blank">WordPress.org</a> to help us spread the word. Thank you from the WP Mail SMTP team!', 'wp-mail-smtp' ),
|
200 |
-
$url,
|
201 |
-
$url
|
202 |
-
);
|
203 |
-
}
|
204 |
-
|
205 |
-
return $text;
|
206 |
-
}
|
207 |
-
|
208 |
-
/**
|
209 |
-
* Display content of the admin area page.
|
210 |
-
*
|
211 |
-
* @since 1.0.0
|
212 |
-
*/
|
213 |
-
public function display() {
|
214 |
-
?>
|
215 |
-
|
216 |
-
<div class="wrap" id="wp-mail-smtp">
|
217 |
-
|
218 |
-
<div class="wp-mail-smtp-page-title">
|
219 |
-
<?php
|
220 |
-
foreach ( $this->get_pages() as $page_slug => $page ) :
|
221 |
-
$label = $page->get_label();
|
222 |
-
if ( empty( $label ) ) {
|
223 |
-
continue;
|
224 |
-
}
|
225 |
-
$class = $page_slug === $this->get_current_tab() ? 'class="active"' : '';
|
226 |
-
?>
|
227 |
-
|
228 |
-
<a href="<?php echo $page->get_link(); ?>" <?php echo $class; ?>><?php echo $label; ?></a>
|
229 |
-
|
230 |
-
<?php endforeach; ?>
|
231 |
-
</div>
|
232 |
-
|
233 |
-
<div class="wp-mail-smtp-page wp-mail-smtp-tab-<?php echo $this->get_current_tab(); ?>">
|
234 |
-
<h1 class="screen-reader-text"><?php echo $this->get_current_tab_title(); ?></h1>
|
235 |
-
|
236 |
-
<?php $this->display_current_tab_content(); ?>
|
237 |
-
</div>
|
238 |
-
|
239 |
-
</div>
|
240 |
-
|
241 |
-
<?php
|
242 |
-
}
|
243 |
-
|
244 |
-
/**
|
245 |
-
* Get the current tab title.
|
246 |
-
*
|
247 |
-
* @since 1.0.0
|
248 |
-
*/
|
249 |
-
public function display_current_tab_content() {
|
250 |
-
|
251 |
-
if ( ! array_key_exists( $this->get_current_tab(), $this->get_pages() ) ) {
|
252 |
-
return;
|
253 |
-
}
|
254 |
-
|
255 |
-
$this->pages[ $this->get_current_tab() ]->display();
|
256 |
-
}
|
257 |
-
|
258 |
-
/**
|
259 |
-
* Get the current admin area tab.
|
260 |
-
*
|
261 |
-
* @since 1.0.0
|
262 |
-
*
|
263 |
-
* @return string
|
264 |
-
*/
|
265 |
-
protected function get_current_tab() {
|
266 |
-
|
267 |
-
$current = '';
|
268 |
-
|
269 |
-
if ( $this->is_admin_page() ) {
|
270 |
-
$current = ! empty( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'settings';
|
271 |
-
}
|
272 |
-
|
273 |
-
return $current;
|
274 |
-
}
|
275 |
-
|
276 |
-
/**
|
277 |
-
* Get the array of default registered tabs for plugin admin area.
|
278 |
-
*
|
279 |
-
* @since 1.0.0
|
280 |
-
*
|
281 |
-
* @return \WPMailSMTP\Admin\PageAbstract[]
|
282 |
-
*/
|
283 |
-
public function get_pages() {
|
284 |
-
|
285 |
-
if ( empty( $this->pages ) ) {
|
286 |
-
$this->pages = array(
|
287 |
-
'settings' => new Pages\Settings(),
|
288 |
-
'test' => new Pages\Test(),
|
289 |
-
'misc' => new Pages\Misc(),
|
290 |
-
'auth' => new Pages\Auth(),
|
291 |
-
);
|
292 |
-
}
|
293 |
-
|
294 |
-
return apply_filters( 'wp_mail_smtp_admin_get_pages', $this->pages );
|
295 |
-
}
|
296 |
-
|
297 |
-
/**
|
298 |
-
* Get the current tab title.
|
299 |
-
*
|
300 |
|