OneSignal – Free Web Push Notifications - Version 2.2.5

Version Description

  • Adds AMP Support. Now works with the official AMP Wordpress Plugin.
Download this release

Release Info

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

Code changes from version 2.2.4 to 2.2.5

Files changed (3) hide show
  1. onesignal-public.php +113 -1
  2. onesignal.php +1 -1
  3. readme.txt +6 -2
onesignal-public.php CHANGED
@@ -21,6 +21,7 @@ class OneSignal_Public
21
  public static function init()
22
  {
23
  add_action('wp_head', array(__CLASS__, 'onesignal_header'), 10);
 
24
  }
25
 
26
  // For easier debugging of sites by identifying them as WordPress
@@ -51,6 +52,20 @@ class OneSignal_Public
51
 
52
  public static function onesignal_header()
53
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  $onesignal_wp_settings = OneSignal::get_onesignal_settings();
55
 
56
  if (array_key_exists('subdomain', $onesignal_wp_settings) && $onesignal_wp_settings['subdomain'] === '') {
@@ -346,5 +361,102 @@ class OneSignal_Public
346
  </script>
347
  <?php
348
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  }
350
- ?>
21
  public static function init()
22
  {
23
  add_action('wp_head', array(__CLASS__, 'onesignal_header'), 10);
24
+ add_action( 'wp_enqueue_scripts', array( __CLASS__, 'onesigal_amp_style' ) );
25
  }
26
 
27
  // For easier debugging of sites by identifying them as WordPress
52
 
53
  public static function onesignal_header()
54
  {
55
+
56
+ if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
57
+
58
+ if ( function_exists( 'amp_is_legacy' ) && amp_is_legacy() ) {
59
+ add_action( 'amp_post_template_body_open', array( __CLASS__, 'insert_amp_web_push' ) );
60
+ add_action( 'amp_post_template_footer', array( __CLASS__, 'insert_amp_one_signal_widget' ) );
61
+ } else {
62
+ add_action( 'wp_body_open', array( __CLASS__, 'insert_amp_web_push' ) );
63
+ add_action( 'wp_footer', array( __CLASS__, 'insert_amp_one_signal_widget' ) );
64
+ }
65
+
66
+ return;
67
+ }
68
+
69
  $onesignal_wp_settings = OneSignal::get_onesignal_settings();
70
 
71
  if (array_key_exists('subdomain', $onesignal_wp_settings) && $onesignal_wp_settings['subdomain'] === '') {
361
  </script>
362
  <?php
363
  }
364
+
365
+ /**
366
+ * Enqueues style for onesignal push notification button.
367
+ *
368
+ * @return void
369
+ */
370
+ public static function onesigal_amp_style() {
371
+ if ( ! self::onesignal_is_amp() ) {
372
+ return;
373
+ }
374
+
375
+ wp_enqueue_style( 'onesignal-amp', plugin_dir_url( __FILE__ ) . 'css/onsignal-amp-style.css', '', '0.1' );
376
+ }
377
+
378
+ /**
379
+ * OneSignal AMP endpoint.
380
+ *
381
+ * @return boolean
382
+ */
383
+ public static function onesignal_is_amp() {
384
+
385
+ $is_amp = false;
386
+
387
+ if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
388
+ $is_amp = true;
389
+ }
390
+
391
+ /**
392
+ * Filter to modify AMP check.
393
+ */
394
+ return apply_filters( 'onesignal_is_amp', $is_amp );
395
+ }
396
+
397
+ /**
398
+ * Returns One Signal App ID
399
+ *
400
+ * @return int | false return one singal app ID false otherwise.
401
+ */
402
+ public static function get_onesignal_app_id() {
403
+ $onesignal_wp_settings = OneSignal::get_onesignal_settings();
404
+ $onesignal_app_id = $onesignal_wp_settings['app_id'];
405
+ return $onesignal_app_id;
406
+ }
407
+
408
+ /**
409
+ * Add amp-web-push component.
410
+ *
411
+ * @return html
412
+ */
413
+ public static function insert_amp_web_push() {
414
+
415
+ $onesignal_app_id = self::get_onesignal_app_id();
416
+
417
+ if ( empty( $onesignal_app_id ) ) {
418
+ return;
419
+ }
420
+
421
+ $one_signal_sdk_files_url = plugin_dir_url( __FILE__ ) . 'sdk_files/';
422
+
423
+ $helper_iframe_url = $one_signal_sdk_files_url . 'amp-helper-frame.html?appId=' . $onesignal_app_id;
424
+ $permission_dialog_url = $one_signal_sdk_files_url . 'amp-permission-dialog.html?appId=' . $onesignal_app_id;
425
+ $service_worker_url = $one_signal_sdk_files_url . 'OneSignalSDKWorker.js.php?appId=' . $onesignal_app_id;
426
+
427
+ echo sprintf(
428
+ '<amp-web-push id="amp-web-push" layout="nodisplay" helper-iframe-url="%1$s" permission-dialog-url="%2$s" service-worker-url="%3$s"></amp-web-push>',
429
+ esc_url( $helper_iframe_url ),
430
+ esc_url( $permission_dialog_url ),
431
+ esc_url( $service_worker_url )
432
+ );
433
+ }
434
+
435
+ /**
436
+ * Add AMP webpush widget.
437
+ */
438
+ public static function insert_amp_one_signal_widget() {
439
+ $onesignal_app_id = self::get_onesignal_app_id();
440
+
441
+ if ( empty( $onesignal_app_id ) ) {
442
+ return;
443
+ }
444
+ ?>
445
+ <!-- A subscription widget -->
446
+ <amp-web-push-widget visibility="unsubscribed" layout="fixed" width="245" height="45">
447
+ <button class="subscribe has-background has-text-color" on="tap:amp-web-push.subscribe">
448
+ <svg class="onesignal-bell-svg" xmlns="http://www.w3.org/2000/svg" width="99.7" height="99.7" viewBox="0 0 99.7 99.7" style="filter: drop-shadow(0 2px 4px rgba(34,36,38,0.35));; -webkit-filter: drop-shadow(0 2px 4px rgba(34,36,38,0.35));;"><circle class="background" cx="49.9" cy="49.9" r="49.9" style=""></circle><path class="foreground" d="M50.1 66.2H27.7s-2-.2-2-2.1c0-1.9 1.7-2 1.7-2s6.7-3.2 6.7-5.5S33 52.7 33 43.3s6-16.6 13.2-16.6c0 0 1-2.4 3.9-2.4 2.8 0 3.8 2.4 3.8 2.4 7.2 0 13.2 7.2 13.2 16.6s-1 11-1 13.3c0 2.3 6.7 5.5 6.7 5.5s1.7.1 1.7 2c0 1.8-2.1 2.1-2.1 2.1H50.1zm-7.2 2.3h14.5s-1 6.3-7.2 6.3-7.3-6.3-7.3-6.3z" style=""></path><ellipse class="stroke" cx="49.9" cy="49.9" rx="37.4" ry="36.9" style=""></ellipse></svg>
449
+ <span class="tooltiptext"><?php esc_html_e( 'Subscribe to notifications' ); ?></span>
450
+ </button>
451
+ </amp-web-push-widget>
452
+
453
+ <!-- An unsubscription widget -->
454
+ <amp-web-push-widget visibility="subscribed" layout="fixed" width="230" height="45">
455
+ <button class="unsubscribe has-background has-text-color" on="tap:amp-web-push.unsubscribe">
456
+ <svg class="onesignal-bell-svg" xmlns="http://www.w3.org/2000/svg" width="99.7" height="99.7" viewBox="0 0 99.7 99.7" style="filter: drop-shadow(0 2px 4px rgba(34,36,38,0.35));; -webkit-filter: drop-shadow(0 2px 4px rgba(34,36,38,0.35));;"><circle class="background" cx="49.9" cy="49.9" r="49.9" style=""></circle><path class="foreground" d="M50.1 66.2H27.7s-2-.2-2-2.1c0-1.9 1.7-2 1.7-2s6.7-3.2 6.7-5.5S33 52.7 33 43.3s6-16.6 13.2-16.6c0 0 1-2.4 3.9-2.4 2.8 0 3.8 2.4 3.8 2.4 7.2 0 13.2 7.2 13.2 16.6s-1 11-1 13.3c0 2.3 6.7 5.5 6.7 5.5s1.7.1 1.7 2c0 1.8-2.1 2.1-2.1 2.1H50.1zm-7.2 2.3h14.5s-1 6.3-7.2 6.3-7.3-6.3-7.3-6.3z" style=""></path><ellipse class="stroke" cx="49.9" cy="49.9" rx="37.4" ry="36.9" style=""></ellipse></svg>
457
+ <span class="tooltiptext"><?php esc_html_e( 'Your\'e subscribed to notifications' ); ?></span>
458
+ </button>
459
+ </amp-web-push-widget>
460
+ <?php
461
+ }
462
  }
 
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: 2.2.4
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: 2.2.5
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: 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
5
  Requires at least: 3.8
6
  Tested up to: 5.9
7
- Stable tag: 2.2.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -23,7 +23,7 @@ You can configure notification delivery at preset intervals, create user segment
23
  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!
24
 
25
  = Company =
26
- OneSignal is trusted by over 1,400,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.
27
 
28
  = Features =
29
  * **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,10 @@ HTTPS Setup Video: [youtube https://www.youtube.com/watch?v=BeTZ2KgytC0]
67
 
68
  == Changelog ==
69
 
 
 
 
 
70
  = 2.2.4 =
71
 
72
  - Update tested up to tag (5.9)
4
  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
5
  Requires at least: 3.8
6
  Tested up to: 5.9
7
+ Stable tag: 2.2.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
23
  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!
24
 
25
  = Company =
26
+ OneSignal is trusted by over 1,500,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.
27
 
28
  = Features =
29
  * **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
 
68
  == Changelog ==
69
 
70
+ = 2.2.5 =
71
+
72
+ - Adds AMP Support. Now works with the official AMP Wordpress Plugin.
73
+
74
  = 2.2.4 =
75
 
76
  - Update tested up to tag (5.9)