From 78a8dd048c75f2217ec8e1b858e4ccf2f44270ef Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Mon, 27 Mar 2023 19:52:09 -0500 Subject: [PATCH 1/2] Remove `recipient` count usage across PHP and JS files Stop reading the `recipients` value from the notification create response. Update the `notice.js` to stop using `recipients` --- notice.js | 39 ++++++++++++++------------------------- onesignal-admin.php | 32 +++++++------------------------- 2 files changed, 21 insertions(+), 50 deletions(-) diff --git a/notice.js b/notice.js index 2cac7a6..bca8443 100644 --- a/notice.js +++ b/notice.js @@ -15,9 +15,6 @@ function notice() { } const editor = wp.data.select("core/editor"); - const get_wp_attr = attr => { - return editor.getEditedPostAttribute(attr); - }; /* * Subscribes function to WP's state-change listener @@ -46,7 +43,7 @@ function notice() { // is checked let send_os_notif; const htmlElement = jQuery("#send_onesignal_notification")[0]; - + if (!!htmlElement) { send_os_notif = htmlElement.checked; } @@ -75,18 +72,19 @@ function notice() { jQuery.get(ajax_object.ajax_url, data, function(response) { response = JSON.parse(response); - const { recipients, status_code, response_body } = response; + const { status_code, response_body } = response; if(window.DEBUG_MODE){ console.log(response); } const is_status_empty = status_code.length == 0; - const is_recipients_empty = recipients.length == 0; - if(!is_status_empty && !is_recipients_empty){ + if(!is_status_empty){ + status_code = parseInt(status_code); + // status 0: HTTP request failed - if (status_code === "0") { + if (status_code === 0) { error_notice("OneSignal Push: request failed with status code 0. "+response_body); reset_state(); return; @@ -108,16 +106,8 @@ function notice() { return; } - if (recipients === "0") { - error_notice( - "OneSignal Push: there were no recipients." - ); - reset_state(); - - } else if (recipients) { - show_notice(recipients); - reset_state(); - } + show_notice(); + reset_state(); } }); @@ -128,29 +118,28 @@ function notice() { ); reset_state(); } - + state.interval_count += 1; }; /* * Gets recipient count and shows notice */ - const show_notice = recipients => { - const plural = recipients == 1 ? "" : "s"; + const show_notice = () => { var delivery_link_text = ""; if (state.status === "publish") { - var notice_text = "OneSignal Push: Successfully sent a notification to "; - delivery_link_text = ". Go to your app's \"Delivery\" tab to check sent messages: https://app.onesignal.com/apps"; + var notice_text = "OneSignal Push: Successfully sent a notification."; + delivery_link_text = " Go to your app's Delivery tab to check sent messages: https://dashboard.onesignal.com/apps/"; } else if (state.status === "future"){ - var notice_text = "OneSignal Push: Successfully scheduled a notification for "; + var notice_text = "OneSignal Push: Successfully scheduled a notification."; } wp.data .dispatch("core/notices") .createNotice( "info", - notice_text + recipients + " recipient" + plural + delivery_link_text, + notice_text + delivery_link_text, { id:'onesignal-notice', isDismissible: true diff --git a/onesignal-admin.php b/onesignal-admin.php index cb3d49f..c866f44 100644 --- a/onesignal-admin.php +++ b/onesignal-admin.php @@ -949,34 +949,16 @@ public static function send_notification_on_wp_post($new_status, $old_status, $p } } else { if (!empty($response)) { - - // API can send a 200 OK even if the notification failed to send - if (isset($response['body'])) { - $response_body = json_decode($response['body'], true); - if (isset($response_body['recipients'])) { - $recipient_count = $response_body['recipients']; - } - } - - // updates meta so that recipient count is available for GET request from client - update_post_meta($post->ID, 'recipients', $recipient_count); - - $sent_or_scheduled = array_key_exists('send_after', $fields) ? 'scheduled' : 'sent'; $config_show_notification_send_status_message = $onesignal_wp_settings['show_notification_send_status_message'] === true; if ($config_show_notification_send_status_message) { - if ($recipient_count !== 0) { - $delivery_link_text = $sent_or_scheduled === 'sent' ? ' Go to your app\'s "Delivery" tab to check sent messages: https://app.onesignal.com/apps/' : ''; - set_transient('onesignal_transient_success', '
-
-

OneSignal Push: Successfully '.$sent_or_scheduled.' a notification to '.$recipient_count.' recipients.'.$delivery_link_text.'

-
-
', 86400); - } else { - set_transient('onesignal_transient_success', '
-

OneSignal Push:There were no recipients. You likely have no subscribers.

-
', 86400); - } + $app_id = $onesignal_wp_settings['app_id']; + $delivery_link_text = ' Go to your app\'s Delivery tab to check sent messages: https://dashboard.onesignal.com/apps/' . $app_id . '/notifications'; + set_transient('onesignal_transient_success', '
+
+

OneSignal Push: Successfully scheduled a notification.' . $delivery_link_text . '

+
+
', 86400); } } } From 31a289ccf67e7986053b7fd3f82774b1421dc6ce Mon Sep 17 00:00:00 2001 From: Rodrigo Gomez Palacio Date: Fri, 24 Mar 2023 18:51:23 -0500 Subject: [PATCH 2/2] 2.4.0 Release Commit --- onesignal-public.php | 6 +++--- onesignal.php | 2 +- readme.txt | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/onesignal-public.php b/onesignal-public.php index ce8ba20..5b0a90c 100644 --- a/onesignal-public.php +++ b/onesignal-public.php @@ -9,7 +9,7 @@ function add_async_for_script($url) else if (is_admin()) return str_replace('#asyncload', '', $url); else - return str_replace('#asyncload', '', $url)."' async='async"; + return str_replace('#asyncload', '', $url)."' async='async"; } class OneSignal_Public @@ -321,7 +321,7 @@ public static function onesignal_header() OneSignal.init(window._oneSignalInitOptions); /* OneSignal: Using custom SDK initialization. */ diff --git a/onesignal.php b/onesignal.php index c689234..9c300de 100644 --- a/onesignal.php +++ b/onesignal.php @@ -6,7 +6,7 @@ * Plugin Name: OneSignal Push Notifications * Plugin URI: https://onesignal.com/ * Description: Free web push notifications. - * Version: 2.3.3 + * Version: 2.4.0 * Author: OneSignal * Author URI: https://onesignal.com * License: MIT diff --git a/readme.txt b/readme.txt index a5372f4..361047b 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ Contributors: OneSignal Donate link: https://onesignal.com 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 Requires at least: 3.8 -Tested up to: 6.1 -Stable tag: 2.3.3 +Tested up to: 6.3 +Stable tag: 2.4.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -23,7 +23,7 @@ You can configure notification delivery at preset intervals, create user segment OneSignal’s free plan allows targeting up to 10,000 subscribers with push notifications. Contact support@onesignal.com if you have any questions. We’d love to hear from you! = Company = -OneSignal is trusted by over 1,800,000 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. +OneSignal is trusted by over 1.8M+ 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. = Features = * **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,9 @@ HTTPS Setup Video: [youtube https://www.youtube.com/watch?v=BeTZ2KgytC0] == Changelog == += 2.4.0 = +- Remove recipient count after post publishing. + = 2.3.3 = - Update "Tested up to" Wordpress version 6.1