Skip to content

Commit

Permalink
Merge pull request #324 from marclucraft/patch-1
Browse files Browse the repository at this point in the history
Updated async attribute.
  • Loading branch information
jkasten2 committed Dec 11, 2023
2 parents 4da98ff + 0cae2cd commit 0360cdd
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions onesignal-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

defined('ABSPATH') or die('This page may not be accessed directly.');

function add_async_for_script($url)
{
if (strpos($url, '#asyncload') === false)
return $url;
else if (is_admin())
return str_replace('#asyncload', '', $url);
else
return str_replace('#asyncload', '', $url)."' async='async";
}

class OneSignal_Public
{
public function __construct()
Expand Down Expand Up @@ -77,13 +67,11 @@ public static function onesignal_header()
OneSignal_Public::insert_onesignal_stamp();
} ?>
<?php
add_filter('clean_url', 'add_async_for_script', 11, 1);

if (defined('ONESIGNAL_DEBUG') && defined('ONESIGNAL_LOCAL')) {
wp_register_script('local_sdk', 'https://localhost:3001/sdks/OneSignalSDK.js#asyncload', array(), false, true);
wp_register_script('local_sdk', 'https://localhost:3001/sdks/OneSignalSDK.js', array(), '1.0.0', array('strategy' => 'async'));
wp_enqueue_script('local_sdk');
} else {
wp_register_script('remote_sdk', 'https://cdn.onesignal.com/sdks/OneSignalSDK.js#asyncload', array(), false, true);
wp_register_script('remote_sdk', 'https://cdn.onesignal.com/sdks/OneSignalSDK.js', array(), '1.0.0', array('strategy' => 'async'));
wp_enqueue_script('remote_sdk');
} ?>
<script>
Expand Down

0 comments on commit 0360cdd

Please sign in to comment.