OneSignal – Free Web Push Notifications - Version 2.1.5

Version Description

  • 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.
Download this release

Release Info

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

Code changes from version 2.1.4 to 2.1.5

onesignal-admin.php CHANGED
@@ -284,19 +284,74 @@ class OneSignal_Admin
284
  if (has_filter('onesignal_meta_box_send_notification_checkbox_state')) {
285
  $meta_box_checkbox_send_notification = apply_filters('onesignal_meta_box_send_notification_checkbox_state', $post, $onesignal_wp_settings);
286
  }
 
 
 
 
 
 
 
 
287
  ?>
288
 
289
  <input type="hidden" name="onesignal_meta_box_present" value="true"></input>
290
- <input type="checkbox" name="send_onesignal_notification" value="true" <?php if ($meta_box_checkbox_send_notification) {
291
- echo 'checked';
292
- } ?>></input>
293
  <label>
294
- <?php if ($post->post_status === 'publish') {
295
- echo esc_attr('Send notification on '.$post_type.' update');
296
- } else {
297
- echo esc_attr('Send notification on '.$post_type.' publish');
298
- } ?>
299
- </label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  <?php
301
  }
302
 
@@ -630,6 +685,16 @@ class OneSignal_Admin
630
  $onesignal_meta_box_present = $was_posted && isset($_POST['onesignal_meta_box_present'], $_POST['onesignal_meta_box_present']) && $_POST['onesignal_meta_box_present'] === 'true';
631
  /* The checkbox "Send notification on post publish/update" on the OneSignal meta box is checked */
632
  $onesignal_meta_box_send_notification_checked = $was_posted && array_key_exists('send_onesignal_notification', $_POST) && $_POST['send_onesignal_notification'] === 'true';
 
 
 
 
 
 
 
 
 
 
633
  /* This is a scheduled post and the OneSignal meta box was present. */
634
  $post_metadata_was_onesignal_meta_box_present = (get_post_meta($post->ID, 'onesignal_meta_box_present', true) === '1');
635
  /* This is a scheduled post and the user checked "Send a notification on post publish/update". */
@@ -696,15 +761,24 @@ class OneSignal_Admin
696
  if (array_key_exists('send_onesignal_notification', $_POST)) {
697
  unset($_POST['send_onesignal_notification']);
698
  }
 
 
 
 
 
 
 
 
 
699
  }
700
 
701
- $notif_content = OneSignalUtils::decode_entities(get_the_title($post->ID));
702
  $site_title = '';
703
  if ($onesignal_wp_settings['notification_title'] !== '') {
704
  $site_title = OneSignalUtils::decode_entities($onesignal_wp_settings['notification_title']);
705
  } else {
706
  $site_title = OneSignalUtils::decode_entities(get_bloginfo('name'));
707
- }
708
 
709
  if (function_exists('qtrans_getLanguage')) {
710
  try {
@@ -716,14 +790,26 @@ class OneSignal_Admin
716
  }
717
  }
718
 
 
 
 
 
 
 
 
 
 
 
 
 
719
  $fields = array(
720
  'external_id' => self::uuid($notif_content),
721
  'app_id' => $onesignal_wp_settings['app_id'],
722
- 'headings' => array('en' => $site_title),
723
  'included_segments' => array('All'),
724
  'isAnyWeb' => true,
725
  'url' => get_permalink($post->ID),
726
- 'contents' => array('en' => $notif_content),
727
  );
728
 
729
  $send_to_mobile_platforms = $onesignal_wp_settings['send_to_mobile_platforms'];
284
  if (has_filter('onesignal_meta_box_send_notification_checkbox_state')) {
285
  $meta_box_checkbox_send_notification = apply_filters('onesignal_meta_box_send_notification_checkbox_state', $post, $onesignal_wp_settings);
286
  }
287
+
288
+ if ($onesignal_wp_settings['notification_title'] !== '') {
289
+ $site_title = OneSignalUtils::decode_entities($onesignal_wp_settings['notification_title']);
290
+ } else {
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>
298
+ <div id="onesignal_send_preference">
 
 
299
  <label>
300
+ <input type="checkbox" id="send_onesignal_notification" name="send_onesignal_notification" value="true" <?php if ($meta_box_checkbox_send_notification) {
301
+ echo 'checked';
302
+ } ?>></input>
303
+
304
+ <?php if ($post->post_status === 'publish') {
305
+ echo esc_attr('Send notification on '.$post_type.' update');
306
+ } else {
307
+ echo esc_attr('Send notification on '.$post_type.' publish');
308
+
309
+ } ?>
310
+ </label>
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>
328
+ </div>
329
+
330
+ <script>
331
+ jQuery('#onesignal_modify_title_and_content').change( function() {
332
+ if(jQuery(this).is(":checked")) {
333
+ jQuery('#onesignal_custom_contents').show();
334
+ if(!jQuery('#onesignal_notification_custom_content').val()) {
335
+ jQuery('#onesignal_notification_custom_content').val(jQuery("#title").val());
336
+ }
337
+ } else {
338
+ jQuery('#onesignal_custom_contents').hide();
339
+ }
340
+ });
341
+ if(!jQuery("#send_onesignal_notification").is(":checked")) {
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);
348
+ } else {
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
  }
357
 
685
  $onesignal_meta_box_present = $was_posted && isset($_POST['onesignal_meta_box_present'], $_POST['onesignal_meta_box_present']) && $_POST['onesignal_meta_box_present'] === 'true';
686
  /* The checkbox "Send notification on post publish/update" on the OneSignal meta box is checked */
687
  $onesignal_meta_box_send_notification_checked = $was_posted && array_key_exists('send_onesignal_notification', $_POST) && $_POST['send_onesignal_notification'] === 'true';
688
+
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". */
761
  if (array_key_exists('send_onesignal_notification', $_POST)) {
762
  unset($_POST['send_onesignal_notification']);
763
  }
764
+ if (array_key_exists('onesignal_modify_title_and_content', $_POST)) {
765
+ unset($_POST['onesignal_modify_title_and_content']);
766
+ }
767
+ if (array_key_exists('onesignal_notification_custom_heading', $_POST)) {
768
+ unset($_POST['onesignal_notification_custom_heading']);
769
+ }
770
+ if (array_key_exists('onesignal_notification_custom_content', $_POST)) {
771
+ unset($_POST['onesignal_notification_custom_content']);
772
+ }
773
  }
774
 
775
+
776
  $site_title = '';
777
  if ($onesignal_wp_settings['notification_title'] !== '') {
778
  $site_title = OneSignalUtils::decode_entities($onesignal_wp_settings['notification_title']);
779
  } else {
780
  $site_title = OneSignalUtils::decode_entities(get_bloginfo('name'));
781
+ }
782
 
783
  if (function_exists('qtrans_getLanguage')) {
784
  try {
790
  }
791
  }
792
 
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
+ }
800
+ if($onesignal_custom_notification_content) {
801
+ $notif_content = $onesignal_custom_notification_content;
802
+ }
803
+ }
804
+
805
  $fields = array(
806
  'external_id' => self::uuid($notif_content),
807
  'app_id' => $onesignal_wp_settings['app_id'],
808
+ 'headings' => array('en' => stripslashes_deep($site_title)),
809
  'included_segments' => array('All'),
810
  'isAnyWeb' => true,
811
  'url' => get_permalink($post->ID),
812
+ 'contents' => array('en' => stripslashes_deep($notif_content)),
813
  );
814
 
815
  $send_to_mobile_platforms = $onesignal_wp_settings['send_to_mobile_platforms'];
onesignal-public.php CHANGED
@@ -55,10 +55,10 @@ class OneSignal_Public
55
  add_filter('clean_url', 'add_async_for_script', 11, 1);
56
 
57
  if (defined('ONESIGNAL_DEBUG') && defined('ONESIGNAL_LOCAL')) {
58
- wp_register_script('local_sdk', 'https://localhost:3001/sdks/OneSignalSDK.js#asyncload', array('jquery'), false, true);
59
  wp_enqueue_script('local_sdk');
60
  } else {
61
- wp_register_script('remote_sdk', 'https://cdn.onesignal.com/sdks/OneSignalSDK.js#asyncload', array('jquery'), false, true);
62
  wp_enqueue_script('remote_sdk');
63
  } ?>
64
  <script>
@@ -82,6 +82,7 @@ class OneSignal_Public
82
  <?php
83
  echo "oneSignal_options['wordpress'] = true;\n";
84
  echo "oneSignal_options['appId'] = '".esc_html($onesignal_wp_settings['app_id'])."';\n";
 
85
 
86
  if (array_key_exists('use_http_permission_request', $onesignal_wp_settings) && $onesignal_wp_settings['use_http_permission_request'] === true) {
87
  echo "oneSignal_options['httpPermissionRequest'] = { };\n";
@@ -119,34 +120,34 @@ class OneSignal_Public
119
  echo "oneSignal_options['promptOptions'] = { };\n";
120
  if (array_key_exists('prompt_customize_enable', $onesignal_wp_settings) && $onesignal_wp_settings['prompt_customize_enable'] === true) {
121
  if (self::valid_for_key('prompt_action_message', $onesignal_wp_settings)) {
122
- echo "oneSignal_options['promptOptions']['actionMessage'] = '".esc_html($onesignal_wp_settings['prompt_action_message'])."';\n";
123
  }
124
  if (self::valid_for_key('prompt_example_notification_title_desktop', $onesignal_wp_settings)) {
125
- echo "oneSignal_options['promptOptions']['exampleNotificationTitleDesktop'] = '".esc_html($onesignal_wp_settings['prompt_example_notification_title_desktop'])."';\n";
126
  }
127
  if (self::valid_for_key('prompt_example_notification_message_desktop', $onesignal_wp_settings)) {
128
- echo "oneSignal_options['promptOptions']['exampleNotificationMessageDesktop'] = '".esc_html($onesignal_wp_settings['prompt_example_notification_message_desktop'])."';\n";
129
  }
130
  if (self::valid_for_key('prompt_example_notification_title_mobile', $onesignal_wp_settings)) {
131
- echo "oneSignal_options['promptOptions']['exampleNotificationTitleMobile'] = '".esc_html($onesignal_wp_settings['prompt_example_notification_title_mobile'])."';\n";
132
  }
133
  if (self::valid_for_key('prompt_example_notification_message_mobile', $onesignal_wp_settings)) {
134
- echo "oneSignal_options['promptOptions']['exampleNotificationMessageMobile'] = '".esc_html($onesignal_wp_settings['prompt_example_notification_message_mobile'])."';\n";
135
  }
136
  if (self::valid_for_key('prompt_example_notification_caption', $onesignal_wp_settings)) {
137
- echo "oneSignal_options['promptOptions']['exampleNotificationCaption'] = '".esc_html($onesignal_wp_settings['prompt_example_notification_caption'])."';\n";
138
  }
139
  if (self::valid_for_key('prompt_accept_button_text', $onesignal_wp_settings)) {
140
- echo "oneSignal_options['promptOptions']['acceptButtonText'] = '".esc_html($onesignal_wp_settings['prompt_accept_button_text'])."';\n";
141
  }
142
  if (self::valid_for_key('prompt_cancel_button_text', $onesignal_wp_settings)) {
143
- echo "oneSignal_options['promptOptions']['cancelButtonText'] = '".esc_html($onesignal_wp_settings['prompt_cancel_button_text'])."';\n";
144
  }
145
  if (self::valid_for_key('prompt_site_name', $onesignal_wp_settings)) {
146
- echo "oneSignal_options['promptOptions']['siteName'] = '".esc_html($onesignal_wp_settings['prompt_site_name'])."';\n";
147
  }
148
  if (self::valid_for_key('prompt_auto_accept_title', $onesignal_wp_settings)) {
149
- echo "oneSignal_options['promptOptions']['autoAcceptTitle'] = '".esc_html($onesignal_wp_settings['prompt_auto_accept_title'])."';\n";
150
  }
151
  }
152
 
55
  add_filter('clean_url', 'add_async_for_script', 11, 1);
56
 
57
  if (defined('ONESIGNAL_DEBUG') && defined('ONESIGNAL_LOCAL')) {
58
+ wp_register_script('local_sdk', 'https://localhost:3001/sdks/OneSignalSDK.js#asyncload', array(), false, true);
59
  wp_enqueue_script('local_sdk');
60
  } else {
61
+ wp_register_script('remote_sdk', 'https://cdn.onesignal.com/sdks/OneSignalSDK.js#asyncload', array(), false, true);
62
  wp_enqueue_script('remote_sdk');
63
  } ?>
64
  <script>
82
  <?php
83
  echo "oneSignal_options['wordpress'] = true;\n";
84
  echo "oneSignal_options['appId'] = '".esc_html($onesignal_wp_settings['app_id'])."';\n";
85
+ echo "oneSignal_options['allowLocalhostAsSecureOrigin'] = true;\n";
86
 
87
  if (array_key_exists('use_http_permission_request', $onesignal_wp_settings) && $onesignal_wp_settings['use_http_permission_request'] === true) {
88
  echo "oneSignal_options['httpPermissionRequest'] = { };\n";
120
  echo "oneSignal_options['promptOptions'] = { };\n";
121
  if (array_key_exists('prompt_customize_enable', $onesignal_wp_settings) && $onesignal_wp_settings['prompt_customize_enable'] === true) {
122
  if (self::valid_for_key('prompt_action_message', $onesignal_wp_settings)) {
123
+ echo "oneSignal_options['promptOptions']['actionMessage'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings["prompt_action_message"]))."\";\n";
124
  }
125
  if (self::valid_for_key('prompt_example_notification_title_desktop', $onesignal_wp_settings)) {
126
+ echo "oneSignal_options['promptOptions']['exampleNotificationTitleDesktop'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_example_notification_title_desktop']))."\";\n";
127
  }
128
  if (self::valid_for_key('prompt_example_notification_message_desktop', $onesignal_wp_settings)) {
129
+ echo "oneSignal_options['promptOptions']['exampleNotificationMessageDesktop'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_example_notification_message_desktop']))."\";\n";
130
  }
131
  if (self::valid_for_key('prompt_example_notification_title_mobile', $onesignal_wp_settings)) {
132
+ echo "oneSignal_options['promptOptions']['exampleNotificationTitleMobile'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_example_notification_title_mobile']))."\";\n";
133
  }
134
  if (self::valid_for_key('prompt_example_notification_message_mobile', $onesignal_wp_settings)) {
135
+ echo "oneSignal_options['promptOptions']['exampleNotificationMessageMobile'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_example_notification_message_mobile']))."\";\n";
136
  }
137
  if (self::valid_for_key('prompt_example_notification_caption', $onesignal_wp_settings)) {
138
+ echo "oneSignal_options['promptOptions']['exampleNotificationCaption'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_example_notification_caption']))."\";\n";
139
  }
140
  if (self::valid_for_key('prompt_accept_button_text', $onesignal_wp_settings)) {
141
+ echo "oneSignal_options['promptOptions']['acceptButtonText'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_accept_button_text']))."\";\n";
142
  }
143
  if (self::valid_for_key('prompt_cancel_button_text', $onesignal_wp_settings)) {
144
+ echo "oneSignal_options['promptOptions']['cancelButtonText'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_cancel_button_text']))."\";\n";
145
  }
146
  if (self::valid_for_key('prompt_site_name', $onesignal_wp_settings)) {
147
+ echo "oneSignal_options['promptOptions']['siteName'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_site_name']))."\";\n";
148
  }
149
  if (self::valid_for_key('prompt_auto_accept_title', $onesignal_wp_settings)) {
150
+ echo "oneSignal_options['promptOptions']['autoAcceptTitle'] = \"".OneSignalUtils::decode_entities(esc_html($onesignal_wp_settings['prompt_auto_accept_title']))."\";\n";
151
  }
152
  }
153
 
onesignal-settings.php CHANGED
@@ -253,8 +253,8 @@ class OneSignal {
253
  }
254
  }
255
  }
256
-
257
- return apply_filters( 'onesignal_get_settings', $onesignal_wp_settings );
258
  }
259
 
260
  public static function save_onesignal_settings($settings) {
253
  }
254
  }
255
  }
256
+ $onesignal_settings_values_without_slashes = stripslashes_deep($onesignal_wp_settings);
257
+ return apply_filters( 'onesignal_get_settings', $onesignal_settings_values_without_slashes );
258
  }
259
 
260
  public static function save_onesignal_settings($settings) {
onesignal.php CHANGED
@@ -6,7 +6,7 @@ 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.4
10
  * Author: OneSignal
11
  * Author URI: https://onesignal.com
12
  * License: MIT
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
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: OneSignal
3
  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.5
7
- Stable tag: 2.1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -67,6 +67,10 @@ HTTPS Setup Video: [youtube https://www.youtube.com/watch?v=BeTZ2KgytC0]
67
 
68
  == Changelog ==
69
 
 
 
 
 
70
  = 2.1.4 =
71
 
72
  - Bug fix: adds check to prevent notifications for non-public post types
3
  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
 
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.
73
+
74
  = 2.1.4 =
75
 
76
  - Bug fix: adds check to prevent notifications for non-public post types