OneSignal – Free Web Push Notifications - Version 1.17.3

Version Description

  • Added debug to logging to responses with non 200-level status codes
  • Made notices unique
  • Bug fixes
Download this release

Release Info

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

Code changes from version 1.17.2 to 1.17.3

Files changed (4) hide show
  1. notice.js +34 -28
  2. onesignal-admin.php +8 -6
  3. onesignal.php +1 -1
  4. readme.txt +8 -2
notice.js CHANGED
@@ -1,11 +1,11 @@
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() {
@@ -25,19 +25,20 @@ function notice() {
25
  */
26
  wp.data.subscribe(() => {
27
  // runs with each change in wp state
28
- const post = wp.data.select("core/editor").getCurrentPost();
29
 
 
30
  if(!post || post === {}){
31
  return;
32
  }
33
 
34
- // runs until post data loads
35
  if (!state.first_modified) {
36
  // captures last modified date of loaded post
37
  state.first_modified = post.modified;
38
  }
39
 
40
- // latest modified date
41
  const { modified, status } = post;
42
 
43
  // is checked
@@ -45,11 +46,14 @@ function notice() {
45
  "checked"
46
  );
47
 
 
48
  const post_modified = modified !== state.first_modified;
49
-
50
- // if hasn't started and change is detected
51
- if (!state.started && post_modified && send_os_notif && (status === "publish")) {
52
- state.interval = setInterval(get_metadata, 3000);
 
 
53
  state.started = true;
54
  }
55
  });
@@ -72,12 +76,12 @@ function notice() {
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;
@@ -92,14 +96,14 @@ function notice() {
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
  );
@@ -109,17 +113,17 @@ function notice() {
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
  };
125
 
@@ -137,14 +141,16 @@ function notice() {
137
  " recipient" +
138
  plural,
139
  {
140
- isDismissible: true
 
141
  }
142
  );
143
  };
144
 
145
  const error_notice = error => {
146
  wp.data.dispatch("core/notices").createNotice("error", error, {
147
- isDismissible: true
 
148
  });
149
  };
150
 
1
  jQuery(document).ready(notice);
2
 
3
  var state = {
4
+ post_id : ajax_object.post_id, // post id sent from php backend
5
+ first_modified : undefined, // when the post was first modified
6
+ started : false, // post notification requests started
7
+ interval: undefined, // global interval for reattempting requests
8
+ interval_count : 0 // how many times has the request been attempted
9
  }
10
 
11
  function notice() {
25
  */
26
  wp.data.subscribe(() => {
27
  // runs with each change in wp state
28
+ const post = editor.getCurrentPost();
29
 
30
+ // runs until post data loads
31
  if(!post || post === {}){
32
  return;
33
  }
34
 
35
+ // post is defined now
36
  if (!state.first_modified) {
37
  // captures last modified date of loaded post
38
  state.first_modified = post.modified;
39
  }
40
 
41
+ // latest modified date, status of the post
42
  const { modified, status } = post;
43
 
44
  // is checked
46
  "checked"
47
  );
48
 
49
+ // if last modified differs from first modified times, post_modified = true
50
  const post_modified = modified !== state.first_modified;
51
+
52
+ const is_published = status === "publish";
53
+
54
+ // if hasn't started, change detected, box checked, and the status is 'publish'
55
+ if (!state.started && post_modified && send_os_notif && is_published) {
56
+ state.interval = setInterval(get_metadata, 3000); // starts requests
57
  state.started = true;
58
  }
59
  });
76
  console.log(response);
77
  }
78
 
79
+ const is_status_empty = status_code.length == 0;
80
+ const is_recipients_empty = recipients.length == 0;
81
 
82
  if(!is_status_empty && !is_recipients_empty){
83
  // status 0: HTTP request failed
84
+ if (status_code === "0") {
85
  error_notice("OneSignal Push: request failed with status code 0. "+error_message);
86
  reset_state();
87
  return;
96
  " error sending your notification"
97
  );
98
  } else {
99
+ error_notice("OneSignal Push: there was a " + status_code + " error sending your notification: " + error_message);
100
  }
101
 
102
  reset_state();
103
  return;
104
  }
105
 
106
+ if (recipients === "0") {
107
  error_notice(
108
  "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"
109
  );
113
  show_notice(recipients);
114
  reset_state();
115
  }
 
 
 
 
 
 
 
 
116
  }
 
117
  });
118
+
119
+ // try for 1 minute (each interval = 3s)
120
+ if (state.interval_count > 20) {
121
+ error_notice(
122
+ "OneSignal Push: Did not receive a response status from last notification sent"
123
+ );
124
+ reset_state();
125
+ }
126
+
127
  state.interval_count += 1;
128
  };
129
 
141
  " recipient" +
142
  plural,
143
  {
144
+ id:'onesignal-notice',
145
+ isDismissible: true
146
  }
147
  );
148
  };
149
 
150
  const error_notice = error => {
151
  wp.data.dispatch("core/notices").createNotice("error", error, {
152
+ isDismissible: true,
153
+ id:'onesignal-error'
154
  });
155
  };
156
 
onesignal-admin.php CHANGED
@@ -794,7 +794,7 @@ public static function uuid($title) {
794
 
795
 
796
  $request = array(
797
- "headers" => array(
798
  "content-type" => "application/json;charset=utf-8",
799
  "Authorization" => "Basic " . $onesignal_auth_key
800
  ),
@@ -831,8 +831,10 @@ public static function uuid($title) {
831
  update_post_meta($post->ID, "status", $status);
832
 
833
  if ($status != 200) {
 
 
834
  if ($status != 0) {
835
- set_transient( 'onesignal_transient_error', '<div class="error notice onesignal-error-notice">
836
  <p><strong>OneSignal Push:</strong><em> There was a ' . $status . ' error sending your notification.</em></p>
837
  </div>', 86400 );
838
  } else {
@@ -865,10 +867,10 @@ public static function uuid($title) {
865
 
866
  if ($config_show_notification_send_status_message) {
867
  if ($recipient_count != 0) {
868
- set_transient('onesignal_transient_success', '<div class="components-notice is-success is-dismissible">
869
- <div class="components-notice__content">
870
- <p><strong>OneSignal Push:</strong><em> Successfully ' . $sent_or_scheduled . ' a notification to ' . $recipient_count . ' recipients.</em></p>
871
- </div>
872
  </div>', 86400);
873
  } else {
874
  set_transient('onesignal_transient_success', '<div class="updated notice notice-success is-dismissible">
794
 
795
 
796
  $request = array(
797
+ "headers" => array(
798
  "content-type" => "application/json;charset=utf-8",
799
  "Authorization" => "Basic " . $onesignal_auth_key
800
  ),
831
  update_post_meta($post->ID, "status", $status);
832
 
833
  if ($status != 200) {
834
+ error_log("There was a ".$status." error sending your notification.");
835
+ error_log("Response from OneSignal:", json_encode($response));
836
  if ($status != 0) {
837
+ set_transient( 'onesignal_transient_error', '<div class="error notice onesignal-error-notice">
838
  <p><strong>OneSignal Push:</strong><em> There was a ' . $status . ' error sending your notification.</em></p>
839
  </div>', 86400 );
840
  } else {
867
 
868
  if ($config_show_notification_send_status_message) {
869
  if ($recipient_count != 0) {
870
+ set_transient('onesignal_transient_success', '<div class="components-notice is-success is-dismissible">
871
+ <div class="components-notice__content">
872
+ <p><strong>OneSignal Push:</strong><em> Successfully ' . $sent_or_scheduled . ' a notification to ' . $recipient_count . ' recipients.</em></p>
873
+ </div>
874
  </div>', 86400);
875
  } else {
876
  set_transient('onesignal_transient_success', '<div class="updated notice notice-success is-dismissible">
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.2
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.3
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.2
8
 
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -22,7 +22,7 @@ You can configure notification delivery at preset intervals, create user segment
22
  OneSignal is free for up to 30,000 subscribers; there are no limits on the number of push notifications you can send. Contact [support@onesignal.com](mailto:support@onesignal.com) if you have any questions. We’d love to hear from you.
23
 
24
  = Company =
25
- OneSignal is trusted by over 600,000 developers and marketing strategists. We power push notifications for everyone from early stage startups to Fortune 500 Companies, sending 4 billion notifications per day. It is the most popular push notification plugin on Wordpress with 90,000+ installations.
26
 
27
  = Features =
28
  * **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.
@@ -66,6 +66,12 @@ HTTPS Setup Video: [youtube https://www.youtube.com/watch?v=BeTZ2KgytC0]
66
 
67
  == Changelog ==
68
 
 
 
 
 
 
 
69
  = 1.17.2 =
70
 
71
  - Lengthened timeout, debugging tool, status-code bug fixes
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.3
8
 
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
22
  OneSignal is free for up to 30,000 subscribers; there are no limits on the number of push notifications you can send. Contact [support@onesignal.com](mailto:support@onesignal.com) if you have any questions. We’d love to hear from you.
23
 
24
  = Company =
25
+ OneSignal is trusted by over 650,000 developers and marketing strategists. We power push notifications for everyone from early stage startups to Fortune 500 Companies, sending 4 billion notifications per day. It is the most popular push notification plugin on Wordpress with 90,000+ installations.
26
 
27
  = Features =
28
  * **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.
66
 
67
  == Changelog ==
68
 
69
+ = 1.17.3 =
70
+
71
+ - Added debug to logging to responses with non 200-level status codes
72
+ - Made notices unique
73
+ - Bug fixes
74
+
75
  = 1.17.2 =
76
 
77
  - Lengthened timeout, debugging tool, status-code bug fixes