From 9533278e4e4ac54cce328a4b1d82b3ae2994abf8 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Wed, 9 Jun 2021 21:58:47 -0700 Subject: [PATCH] Fix sw scope for non wp-content Wordpress setups * Some Wordpress setups (such as roots/bedrock) use "app" instead of "wp-content" as URL path. * Instead of assuming "wp-content" is present we always use the full path URL. - Created a getOneSignalPluginPath function to generate the path without the domain to provide this. * Tested with Both Standard Wordpress and presslabs/wordpress-runtime:bedrock to ensure it works end-to-end. --- onesignal-public.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/onesignal-public.php b/onesignal-public.php index 6997594..96a7ea4 100644 --- a/onesignal-public.php +++ b/onesignal-public.php @@ -39,6 +39,16 @@ private static function valid_for_key($key, $array) { return false; } + // Returns the OneSignal plugin URL path + // Examples: + // /wp-content/plugins/onesignal-free-web-push-notifications + // /app/plugins/onesignal-free-web-push-notifications + private static function getOneSignalPluginPath() + { + $path = parse_url(ONESIGNAL_PLUGIN_URL)['path']; + return rtrim($path, '/'); + } + public static function onesignal_header() { $onesignal_wp_settings = OneSignal::get_onesignal_settings(); @@ -68,15 +78,10 @@ public static function onesignal_header() OneSignal.push( function() {