OneSignal – Free Web Push Notifications - Version 2.1.6

Version Description

  • Adds support for customizing title and body of notifications with scheduled notifications.
Download this release

Release Info

Developer OneSignal
Plugin Icon 128x128 OneSignal – Free Web Push Notifications
Version 2.1.6
Comparing to
See all releases

Code changes from version 2.1.5 to 2.1.6

Files changed (3) hide show
  1. onesignal-admin.php +46 -11
  2. onesignal.php +1 -2
  3. readme.txt +6 -2
onesignal-admin.php CHANGED
@@ -2,6 +2,7 @@
2
 
3
  defined('ABSPATH') or die('This page may not be accessed directly.');
4
 
 
5
  function onesignal_change_footer_admin()
6
  {
7
  return '';
@@ -155,6 +156,7 @@ class OneSignal_Admin
155
  */
156
  public static function on_save_post($post_id, $post, $updated)
157
  {
 
158
  if ($post->post_type === 'wdslp-wds-log') {
159
  // Prevent recursive post logging
160
  return;
@@ -197,6 +199,17 @@ class OneSignal_Admin
197
  } else {
198
  update_post_meta($post_id, 'onesignal_send_notification', false);
199
  }
 
 
 
 
 
 
 
 
 
 
 
200
  }
201
 
202
  public static function add_onesignal_post_options()
@@ -291,7 +304,10 @@ class OneSignal_Admin
291
  $site_title = OneSignalUtils::decode_entities(get_bloginfo('name'));
292
  }
293
 
294
-
 
 
 
295
  ?>
296
 
297
  <input type="hidden" name="onesignal_meta_box_present" value="true"></input>
@@ -311,17 +327,23 @@ class OneSignal_Admin
311
  </div>
312
  <label>
313
  <div id="onesignal_custom_contents_preferences">
314
- <input type="checkbox" id="onesignal_modify_title_and_content" value="true" name="onesignal_modify_title_and_content"></input> Customize notification content</label>
 
 
315
 
316
  <div id="onesignal_custom_contents" style="display:none;padding-top:10px;">
317
  <div>
318
  <label>Notification Title<br/>
319
- <input type="text" size="16" style="width:220px;" name="onesignal_notification_custom_heading" id="onesignal_notification_custom_heading" placeholder="<?php echo esc_attr(OneSignalUtils::decode_entities($onesignal_wp_settings['notification_title'])); ?>"></input>
 
 
320
  </label>
321
  </div>
322
  <div style="padding-top:10px">
323
  <label>Notification Text<br/>
324
- <input type="text" size="16" style="width:220px;" name="onesignal_notification_custom_content" id="onesignal_notification_custom_content" placeholder="The Post's Current Title"></input>
 
 
325
  </label>
326
  </div>
327
  </div>
@@ -342,6 +364,7 @@ class OneSignal_Admin
342
  jQuery('#onesignal_modify_title_and_content').prop("disabled",true);
343
  jQuery('#onesignal_modify_title_and_content').prop("checked",false).change();
344
  }
 
345
  jQuery("#send_onesignal_notification").change( function() {
346
  if(jQuery(this).is(":checked")) {
347
  jQuery('#onesignal_modify_title_and_content').prop("disabled",false);
@@ -349,8 +372,9 @@ class OneSignal_Admin
349
  jQuery('#onesignal_modify_title_and_content').prop("disabled",true);
350
  jQuery('#onesignal_modify_title_and_content').prop("checked",false).change();
351
  }
352
-
353
  })
 
354
  </script>
355
  <?php
356
  }
@@ -646,6 +670,7 @@ class OneSignal_Admin
646
  */
647
  public static function send_notification_on_wp_post($new_status, $old_status, $post)
648
  {
 
649
  try {
650
  // quirk of Gutenberg editor leads to two passes if meta box is added
651
  // conditional removes first pass
@@ -674,6 +699,7 @@ class OneSignal_Admin
674
  return;
675
  }
676
 
 
677
  $onesignal_wp_settings = OneSignal::get_onesignal_settings();
678
 
679
  /* Looks like on_save_post is called after transition_post_status so we'll have to check POST data in addition to post meta data */
@@ -689,17 +715,23 @@ class OneSignal_Admin
689
  /* Check if the checkbox "Customize notification content" is selected */
690
  $onesignal_customize_content_checked = $was_posted && array_key_exists('onesignal_modify_title_and_content', $_POST) && $_POST['onesignal_modify_title_and_content'] === 'true';
691
 
692
- if($onesignal_customize_content_checked) {
693
- // Load the custom content if the user has selected to use it
694
- $onesignal_custom_notification_heading = $_POST['onesignal_notification_custom_heading'];
695
- $onesignal_custom_notification_content = $_POST['onesignal_notification_custom_content'];
 
 
 
 
 
696
  }
697
-
698
  /* This is a scheduled post and the OneSignal meta box was present. */
699
  $post_metadata_was_onesignal_meta_box_present = (get_post_meta($post->ID, 'onesignal_meta_box_present', true) === '1');
700
  /* This is a scheduled post and the user checked "Send a notification on post publish/update". */
701
  $post_metadata_was_send_notification_checked = (get_post_meta($post->ID, 'onesignal_send_notification', true) === '1');
702
 
 
703
  /* Either we were just posted from the WordPress post editor form, or this is a scheduled notification and it was previously submitted from the post editor form */
704
  $posted_from_wordpress_editor = $onesignal_meta_box_present || $post_metadata_was_onesignal_meta_box_present;
705
  /* ********************************************************************************************************* */
@@ -749,6 +781,9 @@ class OneSignal_Admin
749
  */
750
  update_post_meta($post->ID, 'onesignal_meta_box_present', false);
751
  update_post_meta($post->ID, 'onesignal_send_notification', false);
 
 
 
752
 
753
  /* Some WordPress environments seem to be inconsistent about whether on_save_post is called before transition_post_status
754
  * This sets the metadata back to true, and will cause a post to be sent even if the checkbox is not checked the next time
@@ -793,7 +828,7 @@ class OneSignal_Admin
793
  $notif_content = OneSignalUtils::decode_entities(get_the_title($post->ID));
794
 
795
  //Override content and/or title if the user has chosen to do so
796
- if($onesignal_customize_content_checked) {
797
  if($onesignal_custom_notification_heading) {
798
  $site_title = $onesignal_custom_notification_heading;
799
  }
2
 
3
  defined('ABSPATH') or die('This page may not be accessed directly.');
4
 
5
+
6
  function onesignal_change_footer_admin()
7
  {
8
  return '';
156
  */
157
  public static function on_save_post($post_id, $post, $updated)
158
  {
159
+
160
  if ($post->post_type === 'wdslp-wds-log') {
161
  // Prevent recursive post logging
162
  return;
199
  } else {
200
  update_post_meta($post_id, 'onesignal_send_notification', false);
201
  }
202
+
203
+ if (array_key_exists('onesignal_modify_title_and_content', $_POST)) {
204
+ update_post_meta($post_id, 'onesignal_modify_title_and_content', true);
205
+ update_post_meta($post_id, 'onesignal_notification_custom_heading', $_POST['onesignal_notification_custom_heading']);
206
+ update_post_meta($post_id, 'onesignal_notification_custom_content', $_POST['onesignal_notification_custom_content']);
207
+ } else {
208
+ update_post_meta($post_id, 'onesignal_modify_title_and_content', false);
209
+ update_post_meta($post_id, 'onesignal_notification_custom_heading', null);
210
+ update_post_meta($post_id, 'onesignal_notification_custom_content', null);
211
+ }
212
+
213
  }
214
 
215
  public static function add_onesignal_post_options()
304
  $site_title = OneSignalUtils::decode_entities(get_bloginfo('name'));
305
  }
306
 
307
+ $onesignal_customize_content_checked = (get_post_meta($post->ID, 'onesignal_modify_title_and_content', true) === '1');
308
+ $onesignal_notification_custom_content = get_post_meta($post->ID, 'onesignal_notification_custom_content', true);
309
+ $onesignal_notification_custom_heading = get_post_meta($post->ID, 'onesignal_notification_custom_heading', true);
310
+
311
  ?>
312
 
313
  <input type="hidden" name="onesignal_meta_box_present" value="true"></input>
327
  </div>
328
  <label>
329
  <div id="onesignal_custom_contents_preferences">
330
+ <input type="checkbox" id="onesignal_modify_title_and_content" value="true" name="onesignal_modify_title_and_content" <?php if ($onesignal_customize_content_checked) {
331
+ echo 'checked';
332
+ } ?>></input> Customize notification content</label>
333
 
334
  <div id="onesignal_custom_contents" style="display:none;padding-top:10px;">
335
  <div>
336
  <label>Notification Title<br/>
337
+ <input type="text" size="16" style="width:220px;" name="onesignal_notification_custom_heading" value="<?php
338
+ echo esc_attr(OneSignalUtils::decode_entities($onesignal_notification_custom_heading));
339
+ ?>" id="onesignal_notification_custom_heading" placeholder="<?php echo esc_attr(OneSignalUtils::decode_entities($onesignal_wp_settings['notification_title'])); ?>"></input>
340
  </label>
341
  </div>
342
  <div style="padding-top:10px">
343
  <label>Notification Text<br/>
344
+ <input type="text" size="16" style="width:220px;" name="onesignal_notification_custom_content" value="<?php
345
+ echo esc_attr(OneSignalUtils::decode_entities($onesignal_notification_custom_content));
346
+ ?>" id="onesignal_notification_custom_content" placeholder="The Post's Current Title"></input>
347
  </label>
348
  </div>
349
  </div>
364
  jQuery('#onesignal_modify_title_and_content').prop("disabled",true);
365
  jQuery('#onesignal_modify_title_and_content').prop("checked",false).change();
366
  }
367
+
368
  jQuery("#send_onesignal_notification").change( function() {
369
  if(jQuery(this).is(":checked")) {
370
  jQuery('#onesignal_modify_title_and_content').prop("disabled",false);
372
  jQuery('#onesignal_modify_title_and_content').prop("disabled",true);
373
  jQuery('#onesignal_modify_title_and_content').prop("checked",false).change();
374
  }
375
+
376
  })
377
+ jQuery('#onesignal_modify_title_and_content').change();
378
  </script>
379
  <?php
380
  }
670
  */
671
  public static function send_notification_on_wp_post($new_status, $old_status, $post)
672
  {
673
+
674
  try {
675
  // quirk of Gutenberg editor leads to two passes if meta box is added
676
  // conditional removes first pass
699
  return;
700
  }
701
 
702
+
703
  $onesignal_wp_settings = OneSignal::get_onesignal_settings();
704
 
705
  /* Looks like on_save_post is called after transition_post_status so we'll have to check POST data in addition to post meta data */
715
  /* Check if the checkbox "Customize notification content" is selected */
716
  $onesignal_customize_content_checked = $was_posted && array_key_exists('onesignal_modify_title_and_content', $_POST) && $_POST['onesignal_modify_title_and_content'] === 'true';
717
 
718
+ // If this post is newly being created and if the user has chosen to customize the content
719
+ $onesignal_customized_content = $onesignal_customize_content_checked || (get_post_meta($post->ID, 'onesignal_modify_title_and_content', true) === '1');
720
+
721
+ if($was_posted && $onesignal_customized_content) {
722
+ $onesignal_custom_notification_heading = $_POST['onesignal_notification_custom_heading'];
723
+ $onesignal_custom_notification_content = $_POST['onesignal_notification_custom_content'];
724
+ } else { // If this post was created previously (eg: scheduled), and the user had chosen to customize the content
725
+ $onesignal_custom_notification_heading = get_post_meta($post->ID, 'onesignal_notification_custom_heading', true);
726
+ $onesignal_custom_notification_content = get_post_meta($post->ID, 'onesignal_notification_custom_content', true);
727
  }
728
+
729
  /* This is a scheduled post and the OneSignal meta box was present. */
730
  $post_metadata_was_onesignal_meta_box_present = (get_post_meta($post->ID, 'onesignal_meta_box_present', true) === '1');
731
  /* This is a scheduled post and the user checked "Send a notification on post publish/update". */
732
  $post_metadata_was_send_notification_checked = (get_post_meta($post->ID, 'onesignal_send_notification', true) === '1');
733
 
734
+
735
  /* Either we were just posted from the WordPress post editor form, or this is a scheduled notification and it was previously submitted from the post editor form */
736
  $posted_from_wordpress_editor = $onesignal_meta_box_present || $post_metadata_was_onesignal_meta_box_present;
737
  /* ********************************************************************************************************* */
781
  */
782
  update_post_meta($post->ID, 'onesignal_meta_box_present', false);
783
  update_post_meta($post->ID, 'onesignal_send_notification', false);
784
+ update_post_meta($post->ID, 'onesignal_modify_title_and_content', false);
785
+ update_post_meta($post->ID, 'onesignal_notification_custom_heading', null);
786
+ update_post_meta($post->ID, 'onesignal_notification_custom_content', null);
787
 
788
  /* Some WordPress environments seem to be inconsistent about whether on_save_post is called before transition_post_status
789
  * This sets the metadata back to true, and will cause a post to be sent even if the checkbox is not checked the next time
828
  $notif_content = OneSignalUtils::decode_entities(get_the_title($post->ID));
829
 
830
  //Override content and/or title if the user has chosen to do so
831
+ if($onesignal_customized_content) {
832
  if($onesignal_custom_notification_heading) {
833
  $site_title = $onesignal_custom_notification_heading;
834
  }
onesignal.php CHANGED
@@ -6,14 +6,13 @@ defined('ABSPATH') or die('This page may not be accessed directly.');
6
  * Plugin Name: OneSignal Push Notifications
7
  * Plugin URI: https://onesignal.com/
8
  * Description: Free web push notifications.
9
- * Version: 2.1.5
10
  * Author: OneSignal
11
  * Author URI: https://onesignal.com
12
  * License: MIT
13
  */
14
 
15
  define('ONESIGNAL_PLUGIN_URL', plugin_dir_url(__FILE__));
16
-
17
  /*
18
  * The number of seconds required to wait between requests.
19
  */
6
  * Plugin Name: OneSignal Push Notifications
7
  * Plugin URI: https://onesignal.com/
8
  * Description: Free web push notifications.
9
+ * Version: 2.1.6
10
  * Author: OneSignal
11
  * Author URI: https://onesignal.com
12
  * License: MIT
13
  */
14
 
15
  define('ONESIGNAL_PLUGIN_URL', plugin_dir_url(__FILE__));
 
16
  /*
17
  * The number of seconds required to wait between requests.
18
  */
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://onesignal.com
4
  Tags: push notification, push notifications, desktop notifications, mobile notifications, chrome push, android, android notification, android notifications, android push, desktop notification, firefox, firefox push, mobile, mobile notification, notification, notifications, notify, onesignal, push, push messages, safari, safari push, web push, chrome
5
  Requires at least: 3.8
6
  Tested up to: 5.6
7
- Stable tag: 2.1.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -23,7 +23,7 @@ You can configure notification delivery at preset intervals, create user segment
23
  OneSignal’s free plan allows targeting up to 30,000 subscribers with push notifications. Contact support@onesignal.com if you have any questions. We’d love to hear from you!
24
 
25
  = Company =
26
- OneSignal is trusted by over 1,043,856 developers and marketing strategists. We power push notifications for everyone from early stage startups to Fortune 500 Companies, sending over 6 billion notifications per day. It is the most popular push notification plugin on Wordpress with 100,000+ installations.
27
 
28
  = Features =
29
  * **Supports Chrome** (Desktop & Android), **Safari** (Mac OS X), **Microsoft Edge** (Desktop & Android), **Opera** (Desktop & Android) and **Firefox** (Desktop & Android) on both HTTP and HTTPS sites.
@@ -67,6 +67,10 @@ HTTPS Setup Video: [youtube https://www.youtube.com/watch?v=BeTZ2KgytC0]
67
 
68
  == Changelog ==
69
 
 
 
 
 
70
  = 2.1.5 =
71
 
72
  - Update of "Tested up to" value (WP 5.6). Removed unnecessary jQuery. Includes support for customizing the title and body of notifications. Fixed formatting issues related to apostrophe use.
4
  Tags: push notification, push notifications, desktop notifications, mobile notifications, chrome push, android, android notification, android notifications, android push, desktop notification, firefox, firefox push, mobile, mobile notification, notification, notifications, notify, onesignal, push, push messages, safari, safari push, web push, chrome
5
  Requires at least: 3.8
6
  Tested up to: 5.6
7
+ Stable tag: 2.1.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
23
  OneSignal’s free plan allows targeting up to 30,000 subscribers with push notifications. Contact support@onesignal.com if you have any questions. We’d love to hear from you!
24
 
25
  = Company =
26
+ OneSignal is trusted by over 1,145,554 developers and marketing strategists. We power push notifications for everyone from early stage startups to Fortune 500 Companies, sending over 6 billion notifications per day. It is the most popular push notification plugin on Wordpress with 100,000+ installations.
27
 
28
  = Features =
29
  * **Supports Chrome** (Desktop & Android), **Safari** (Mac OS X), **Microsoft Edge** (Desktop & Android), **Opera** (Desktop & Android) and **Firefox** (Desktop & Android) on both HTTP and HTTPS sites.
67
 
68
  == Changelog ==
69
 
70
+ = 2.1.6 =
71
+
72
+ - Adds support for customizing title and body of notifications with scheduled notifications.
73
+
74
  = 2.1.5 =
75
 
76
  - Update of "Tested up to" value (WP 5.6). Removed unnecessary jQuery. Includes support for customizing the title and body of notifications. Fixed formatting issues related to apostrophe use.