OneSignal – Free Web Push Notifications - Version 1.17.2

Version Description

  • Lengthened timeout, debugging tool, status-code bug fixes
Download this release

Release Info

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

Code changes from version 1.17.1 to 1.17.2

Files changed (5) hide show
  1. notice.js +75 -44
  2. onesignal-admin.php +5 -1
  3. onesignal-settings.php +2 -2
  4. onesignal.php +1 -1
  5. readme.txt +5 -1
notice.js CHANGED
@@ -1,4 +1,14 @@
1
- jQuery(document).ready(function() {
 
 
 
 
 
 
 
 
 
 
2
  if (!isWpCoreEditorDefined()) {
3
  return;
4
  }
@@ -7,14 +17,6 @@ jQuery(document).ready(function() {
7
  const get_wp_attr = attr => {
8
  return editor.getEditedPostAttribute(attr);
9
  };
10
-
11
- var state = {
12
- post_id : ajax_object.post_id,
13
- first_modified : undefined,
14
- started : false,
15
- interval: undefined,
16
- interval_count : 0
17
- }
18
 
19
  /*
20
  * Subscribes function to WP's state-change listener
@@ -65,48 +67,58 @@ jQuery(document).ready(function() {
65
  jQuery.get(ajax_object.ajax_url, data, function(response) {
66
  response = JSON.parse(response);
67
  const { recipients, status_code, error_message } = response;
68
-
69
- // status 0: HTTP request failed
70
- if (status_code == 0) {
71
- error_notice("OneSignal Push: request failed. "+error_message);
72
- reset_state();
73
- return;
74
  }
75
 
76
- // 400 & 500 level errors
77
- if (status_code >= 400) {
78
- if (!error_message) {
79
- error_notice(
80
- "OneSignal Push: there was a " +
81
- status_code +
82
- " error sending your notification"
83
- );
84
- } else {
85
- error_notice("OneSignal Push: " + error_message);
86
  }
87
 
88
- reset_state();
89
- return;
90
- }
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
- if (recipients == 0) {
93
- error_notice(
94
- "OneSignal Push: there were no recipients. You either 1) have no subscribers yet or 2) you hit the rate-limit. Please try again in an hour. Learn more: https://bit.ly/2UDplAS"
95
- );
96
- reset_state();
97
 
98
- } else if (recipients) {
99
- show_notice(recipients);
100
- reset_state();
101
- }
102
 
103
- // try for 1 minute
104
- if (state.interval_count > 20) {
105
- error_notice(
106
- "OneSignal Push: Did not receive a response status from last notification sent"
107
- );
108
- reset_state();
 
109
  }
 
110
  });
111
  state.interval_count += 1;
112
  };
@@ -143,8 +155,8 @@ jQuery(document).ready(function() {
143
  state.started = false;
144
  state.first_modified = undefined;
145
  }
 
146
 
147
- });
148
  const isWpCoreEditorDefined = () => {
149
  var unloadable = ""; // variable name that couldn't be loaded
150
  if (!wp || !wp.data || !wp.data.select("core/editor")) {
@@ -164,3 +176,22 @@ const isWpCoreEditorDefined = () => {
164
  return true;
165
  }
166
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(notice);
2
+
3
+ var state = {
4
+ post_id : ajax_object.post_id,
5
+ first_modified : undefined,
6
+ started : false,
7
+ interval: undefined,
8
+ interval_count : 0
9
+ }
10
+
11
+ function notice() {
12
  if (!isWpCoreEditorDefined()) {
13
  return;
14
  }
17
  const get_wp_attr = attr => {
18
  return editor.getEditedPostAttribute(attr);
19
  };
 
 
 
 
 
 
 
 
20
 
21
  /*
22
  * Subscribes function to WP's state-change listener
67
  jQuery.get(ajax_object.ajax_url, data, function(response) {
68
  response = JSON.parse(response);
69
  const { recipients, status_code, error_message } = response;
70
+
71
+ if(window.DEBUG_MODE){
72
+ console.log(response);
 
 
 
73
  }
74
 
75
+ const is_status_empty = status_code === [];
76
+ const is_recipients_empty = recipients === [];
77
+
78
+ if(!is_status_empty && !is_recipients_empty){
79
+ // status 0: HTTP request failed
80
+ if (status_code === 0) {
81
+ error_notice("OneSignal Push: request failed with status code 0. "+error_message);
82
+ reset_state();
83
+ return;
 
84
  }
85
 
86
+ // 400 & 500 level errors
87
+ if (status_code >= 400) {
88
+ if (!error_message) {
89
+ error_notice(
90
+ "OneSignal Push: there was a " +
91
+ status_code +
92
+ " error sending your notification"
93
+ );
94
+ } else {
95
+ error_notice("OneSignal Push: " + error_message);
96
+ }
97
+
98
+ reset_state();
99
+ return;
100
+ }
101
 
102
+ if (recipients == 0) {
103
+ error_notice(
104
+ "OneSignal Push: there were no recipients. You either 1) have no subscribers yet or 2) you hit the rate-limit. Please try again in an hour. Learn more: https://bit.ly/2UDplAS"
105
+ );
106
+ reset_state();
107
 
108
+ } else if (recipients) {
109
+ show_notice(recipients);
110
+ reset_state();
111
+ }
112
 
113
+ // try for 1 minute
114
+ if (state.interval_count > 20) {
115
+ error_notice(
116
+ "OneSignal Push: Did not receive a response status from last notification sent"
117
+ );
118
+ reset_state();
119
+ }
120
  }
121
+
122
  });
123
  state.interval_count += 1;
124
  };
155
  state.started = false;
156
  state.first_modified = undefined;
157
  }
158
+ };
159
 
 
160
  const isWpCoreEditorDefined = () => {
161
  var unloadable = ""; // variable name that couldn't be loaded
162
  if (!wp || !wp.data || !wp.data.select("core/editor")) {
176
  return true;
177
  }
178
  };
179
+
180
+ /**
181
+ * - use the debug method in the console to show data about the request
182
+ * - works in Gutenberg editor
183
+ *
184
+ * returns an object in the format
185
+ * { status : "200",
186
+ * recipients : "1374",
187
+ * error_message : []
188
+ * }
189
+ *
190
+ * - if the recipient number is "0", the error_message will contain the entire HTTP response as JSON
191
+ */
192
+ window.OneSignal = {
193
+ debug : () => {
194
+ window.DEBUG_MODE = window.DEBUG_MODE ? !window.DEBUG_MODE : true;
195
+ notice();
196
+ }
197
+ };
onesignal-admin.php CHANGED
@@ -798,7 +798,8 @@ public static function uuid($title) {
798
  "content-type" => "application/json;charset=utf-8",
799
  "Authorization" => "Basic " . $onesignal_auth_key
800
  ),
801
- "body" => json_encode($fields)
 
802
  );
803
 
804
  $response = wp_remote_post($onesignal_post_url, $request);
@@ -823,6 +824,9 @@ public static function uuid($title) {
823
  $status = $response['response']['code'];
824
  }
825
 
 
 
 
826
 
827
  update_post_meta($post->ID, "status", $status);
828
 
798
  "content-type" => "application/json;charset=utf-8",
799
  "Authorization" => "Basic " . $onesignal_auth_key
800
  ),
801
+ "body" => json_encode($fields),
802
+ "timeout" => 60
803
  );
804
 
805
  $response = wp_remote_post($onesignal_post_url, $request);
824
  $status = $response['response']['code'];
825
  }
826
 
827
+ if ($response_body['recipients'] == "0") {
828
+ update_post_meta($post->ID, "error_message", json_encode($response_body));
829
+ }
830
 
831
  update_post_meta($post->ID, "status", $status);
832
 
onesignal-settings.php CHANGED
@@ -263,7 +263,7 @@ class OneSignal {
263
  }
264
  }
265
 
266
- return $onesignal_wp_settings;
267
  }
268
 
269
  public static function save_onesignal_settings($settings) {
@@ -271,4 +271,4 @@ class OneSignal {
271
  update_option("OneSignalWPSetting", $onesignal_wp_settings);
272
  }
273
  }
274
- ?>
263
  }
264
  }
265
 
266
+ return apply_filters( 'onesignal_get_settings', $onesignal_wp_settings );
267
  }
268
 
269
  public static function save_onesignal_settings($settings) {
271
  update_option("OneSignalWPSetting", $onesignal_wp_settings);
272
  }
273
  }
274
+ ?>
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: 1.17.1
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: 1.17.2
10
  * Author: OneSignal
11
  * Author URI: https://onesignal.com
12
  * License: MIT
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://onesignal.com
4
  Tags: chrome, firefox, safari, push, push notifications, push notification, chrome push, safari push, firefox push, notification, notifications, web push, notify, mavericks, android, android push, android notifications, android notification, mobile notification, mobile notifications, mobile, desktop notification, roost, goroost, desktop notifications, gcm, push messages, onesignal
5
  Requires at least: 3.8
6
  Tested up to: 5.1
7
- Stable tag: 1.17.1
8
 
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -66,6 +66,10 @@ HTTPS Setup Video: [youtube https://www.youtube.com/watch?v=BeTZ2KgytC0]
66
 
67
  == Changelog ==
68
 
 
 
 
 
69
  = 1.17.1 =
70
 
71
  - Support for more detailed error messages
4
  Tags: chrome, firefox, safari, push, push notifications, push notification, chrome push, safari push, firefox push, notification, notifications, web push, notify, mavericks, android, android push, android notifications, android notification, mobile notification, mobile notifications, mobile, desktop notification, roost, goroost, desktop notifications, gcm, push messages, onesignal
5
  Requires at least: 3.8
6
  Tested up to: 5.1
7
+ Stable tag: 1.17.2
8
 
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
66
 
67
  == Changelog ==
68
 
69
+ = 1.17.2 =
70
+
71
+ - Lengthened timeout, debugging tool, status-code bug fixes
72
+
73
  = 1.17.1 =
74
 
75
  - Support for more detailed error messages