diff --git a/onesignal.php b/onesignal.php index 9ea54bc..7c841a5 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: 3.0.2 + * Version: 3.0.3 * Author: OneSignal * Author URI: https://onesignal.com * License: MIT diff --git a/readme.txt b/readme.txt index ceb5b29..92f6ac8 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ 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.7 -Stable tag: 3.0.2 +Stable tag: 3.0.3 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -64,6 +64,9 @@ OneSignal is trusted by over 1.8M+ developers and marketing strategists. We powe == Changelog == += 3.0.3 = +- Bug fix: fix service worker registration issue. + = 3.0.2 = - Adding an admin notice and updated styles to encourage settings migration. diff --git a/v3/onesignal-admin/onesignal-admin.js b/v3/onesignal-admin/onesignal-admin.js index 81b476b..a6c427a 100644 --- a/v3/onesignal-admin/onesignal-admin.js +++ b/v3/onesignal-admin/onesignal-admin.js @@ -2,53 +2,61 @@ window.addEventListener("DOMContentLoaded", () => { const helpIcon = document.querySelector(".help"); const infoDiv = document.querySelector(".information"); - helpIcon.addEventListener("click", () => { - infoDiv.style.display = - infoDiv.style.display === "none" ? "inherit" : "none"; - }); + if (helpIcon && infoDiv) { + helpIcon.addEventListener("click", () => { + infoDiv.style.display = + infoDiv.style.display === "none" ? "inherit" : "none"; + }); + } }); window.addEventListener("DOMContentLoaded", () => { - const appIdInput = document.querySelector('#appid'); - const apiKeyInput = document.querySelector('#apikey'); - const saveButton = document.querySelector('#save-settings-button'); + const appIdInput = document.querySelector("#appid"); + const apiKeyInput = document.querySelector("#apikey"); + const saveButton = document.querySelector("#save-settings-button"); + + if (appIdInput && apiKeyInput && saveButton) { + function isValidUUID(uuid) { + const uuidRegex = + /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + return uuid.length > 0 && uuidRegex.test(uuid); // Ensure it's not empty and matches regex + } - function isValidUUID(uuid) { - const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; - return uuid.length > 0 && uuidRegex.test(uuid); // Ensure it's not empty and matches regex - } + function isValidApiKey(apiKey) { + const base64Regex = + /^(?:[A-Za-z0-9+/]{4}){12,}(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/; // At least 48 characters in Base64 + const opaqueTokenRegex = /^os_v[2-9]_app_[2-7a-z]{56,}$/; + return ( + base64Regex.test(apiKey) || opaqueTokenRegex.test(apiKey) + ); // Ensure it's not empty and matches regex + } - function isValidApiKey(apiKey) { - const base64Regex = /^(?:[A-Za-z0-9+/]{4}){12,}(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/; // At least 48 characters in Base64 - const opaqueTokenRegex = /^os_v[2-9]_app_[2-7a-z]{56,}$/; - return (base64Regex.test(apiKey) || opaqueTokenRegex.test(apiKey)); // Ensure it's not empty and matches regex - } + function updateValidationIcon(input, isValid) { + const icon = input.parentElement.querySelector(".validation-icon"); + if (icon) { + icon.textContent = isValid ? "✅" : "❌"; + } + } - function updateValidationIcon(input, isValid) { - const icon = input.parentElement.querySelector('.validation-icon'); - if (icon) { - icon.textContent = isValid ? '✅' : '❌'; + function toggleSaveButton() { + const appIdValid = isValidUUID(appIdInput.value); + const apiKeyValid = isValidApiKey(apiKeyInput.value); + saveButton.disabled = !(appIdValid && apiKeyValid); // Enable button only if both are valid } - } - function toggleSaveButton() { - const appIdValid = isValidUUID(appIdInput.value); - const apiKeyValid = isValidApiKey(apiKeyInput.value); - saveButton.disabled = !(appIdValid && apiKeyValid); // Enable button only if both are valid - } + appIdInput.addEventListener("input", () => { + const isValid = isValidUUID(appIdInput.value); + updateValidationIcon(appIdInput, isValid); + toggleSaveButton(); + }); - appIdInput.addEventListener('input', () => { - const isValid = isValidUUID(appIdInput.value); - updateValidationIcon(appIdInput, isValid); - toggleSaveButton(); - }); + apiKeyInput.addEventListener("input", () => { + const isValid = isValidApiKey(apiKeyInput.value); + updateValidationIcon(apiKeyInput, isValid); + toggleSaveButton(); + }); - apiKeyInput.addEventListener('input', () => { - const isValid = isValidApiKey(apiKeyInput.value); - updateValidationIcon(apiKeyInput, isValid); + // Initial state on page load toggleSaveButton(); - }); - - // Initial state on page load - toggleSaveButton(); + } }); diff --git a/v3/onesignal-init.php b/v3/onesignal-init.php index 541a61a..5000b38 100644 --- a/v3/onesignal-init.php +++ b/v3/onesignal-init.php @@ -8,6 +8,10 @@ function onesignal_init() { $onesignal_wp_settings = get_option('OneSignalWPSetting'); + $use_root_scope = array_key_exists('onesignal_sw_js', $onesignal_wp_settings) ? false : true; + $path = rtrim(parse_url(ONESIGNAL_PLUGIN_URL)['path'], '/'); + $scope = $path . '/sdk_files/push/onesignal/'; + $filename = 'OneSignalSDKWorker.js' . ($use_root_scope ? '.php' : ''); ?>