Skip to content

Commit 6fe9530

Browse files
authored
Merge pull request #45 from SuperPWA/branch-1.8.1
Branch 1.8.1
2 parents 1f9a570 + aed2c01 commit 6fe9530

9 files changed

Lines changed: 146 additions & 21 deletions

File tree

3rd-party/onesignal.php

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @function superpwa_onesignal_sw() Import OneSignal service worker in SuperPWA
1212
* @function superpwa_onesignal_activation() OneSignal activation todo
1313
* @function superpwa_onesignal_deactivation() OneSignal deactivation todo
14+
* @function superpwa_onesignal_admin_notices() Admin notices for OneSignal compatibility
1415
*/
1516

1617
// Exit if accessed directly
@@ -19,14 +20,22 @@
1920
// If OneSignal is installed and active
2021
if ( class_exists( 'OneSignal' ) ) {
2122

22-
// Add gcm_sender_id to SuperPWA manifest
23-
add_filter( 'superpwa_manifest', 'superpwa_onesignal_add_gcm_sender_id' );
24-
25-
// Change service worker filename to match OneSignal's service worker
26-
add_filter( 'superpwa_sw_filename', 'superpwa_onesignal_sw_filename' );
27-
28-
// Import OneSignal service worker in SuperPWA
29-
add_filter( 'superpwa_sw_template', 'superpwa_onesignal_sw' );
23+
// Filter manifest and service worker for singe websites and not for multisites.
24+
if ( ! is_multisite() ) {
25+
26+
// Add gcm_sender_id to SuperPWA manifest
27+
add_filter( 'superpwa_manifest', 'superpwa_onesignal_add_gcm_sender_id' );
28+
29+
// Change service worker filename to match OneSignal's service worker
30+
add_filter( 'superpwa_sw_filename', 'superpwa_onesignal_sw_filename' );
31+
32+
// Import OneSignal service worker in SuperPWA
33+
add_filter( 'superpwa_sw_template', 'superpwa_onesignal_sw' );
34+
}
35+
36+
// Show admin notice.
37+
add_action( 'admin_notices', 'superpwa_onesignal_admin_notices', 9 );
38+
add_action( 'network_admin_notices', 'superpwa_onesignal_admin_notices', 9 );
3039
}
3140

3241
/**
@@ -93,9 +102,15 @@ function superpwa_onesignal_sw( $sw ) {
93102
* Regenerate SuperPWA service worker with the new filename.
94103
*
95104
* @since 1.8
105+
* @since 1.8.1 Excluded multisites. No OneSignal compatibility on multisites yet. In 1.8 onesignal.php was not loaded for multisites.
96106
*/
97107
function superpwa_onesignal_activation() {
98108

109+
// Do not do anything for multisites
110+
if ( is_multisite() ) {
111+
return;
112+
}
113+
99114
// Filter in gcm_sender_id to SuperPWA manifest
100115
add_filter( 'superpwa_manifest', 'superpwa_onesignal_add_gcm_sender_id' );
101116

@@ -124,9 +139,15 @@ function superpwa_onesignal_activation() {
124139
* Regenerate SuperPWA service worker.
125140
*
126141
* @since 1.8
142+
* @since 1.8.1 Excluded multisites. No OneSignal compatibility on multisites yet. In 1.8 onesignal.php was not loaded for multisites.
127143
*/
128144
function superpwa_onesignal_deactivation() {
129145

146+
// Do not do anything for multisites
147+
if ( is_multisite() ) {
148+
return;
149+
}
150+
130151
// Remove gcm_sender_id from SuperPWA manifest
131152
remove_filter( 'superpwa_manifest', 'superpwa_onesignal_add_gcm_sender_id' );
132153

@@ -145,4 +166,56 @@ function superpwa_onesignal_deactivation() {
145166
// Regenerate SuperPWA service worker
146167
superpwa_generate_sw();
147168
}
148-
add_action( 'deactivate_onesignal-free-web-push-notifications/onesignal.php', 'superpwa_onesignal_deactivation', 11 );
169+
add_action( 'deactivate_onesignal-free-web-push-notifications/onesignal.php', 'superpwa_onesignal_deactivation', 11 );
170+
171+
/**
172+
* Admin notices for OneSignal compatibility
173+
*
174+
* One Single installs, warn users to add SuperPWA manifest as custom manifest in OneSignal settings.
175+
* One multisites, warn users that SuperPWA and OneSignal cannot work together.
176+
*
177+
* @since 1.8.1
178+
*/
179+
function superpwa_onesignal_admin_notices() {
180+
181+
// Notices only for admins.
182+
if ( ! current_user_can( 'manage_options' ) ) {
183+
return;
184+
}
185+
186+
// Incompatibility notice for Multisites
187+
if ( is_multisite() ) {
188+
echo '<div class="notice notice-warning"><p>' .
189+
sprintf(
190+
__( '<strong>SuperPWA</strong> is not compatible with OneSignal on multisites yet. Disable one of these plugins until the compatibility is available.<br>Please refer to the <a href="%s" target="_blank">OneSignal integration documentation</a> for more info. ', 'super-progressive-web-apps' ),
191+
'https://superpwa.com/doc/setup-onesignal-with-superpwa/?utm_source=superpwa-plugin&utm_medium=onesignal-multisite-admin-notice#multisites'
192+
) . '</p></div>';
193+
194+
// Filter PWA status since PWA is not ready yet.
195+
add_filter( 'superpwa_is_pwa_ready', '__return_false' );
196+
197+
return;
198+
}
199+
200+
// Get OneSignal settings.
201+
$onesignal_wp_settings = get_option( 'OneSignalWPSetting' );
202+
203+
// Show notice if OneSignal custom manifest is disabled or if the custom manifest is not the SuperPWA manifest.
204+
if (
205+
! isset( $onesignal_wp_settings['use_custom_manifest'] ) ||
206+
! ( (int) $onesignal_wp_settings['use_custom_manifest'] === 1 ) ||
207+
! isset( $onesignal_wp_settings['custom_manifest_url'] ) ||
208+
! ( strcasecmp( trim( $onesignal_wp_settings['custom_manifest_url'] ), superpwa_manifest( 'src' ) ) === 0 )
209+
) {
210+
echo '<div class="notice notice-warning"><p>' .
211+
sprintf(
212+
__( '<strong>Action Required to integrate SuperPWA with OneSignal:</strong><br>1. Go to <a href="%s" target="_blank">OneSignal Configuration > Scroll down to Advanced Settings &rarr;</a><br>2. Enable <strong>Use my own manifest.json</strong><br>3. Set <code>%s</code>as <strong>Custom manifest.json URL</strong> and Save Settings.<br>Please refer the <a href="%s" target="_blank">OneSignal integration documentation</a> for more info. ', 'super-progressive-web-apps' ),
213+
admin_url( 'admin.php?page=onesignal-push#configuration' ),
214+
superpwa_manifest( 'src' ),
215+
'https://superpwa.com/doc/setup-onesignal-with-superpwa/?utm_source=superpwa-plugin&utm_medium=onesignal-admin-notice'
216+
) . '</p></div>';
217+
218+
// Filter PWA status since PWA is not ready yet.
219+
add_filter( 'superpwa_is_pwa_ready', '__return_false' );
220+
}
221+
}

admin/basic-setup.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function superpwa_admin_notices() {
6868
// Admin notice on plugin activation
6969
if ( get_transient( 'superpwa_admin_notice_activation' ) ) {
7070

71-
$superpwa_is_ready = is_ssl() && superpwa_get_contents( superpwa_manifest( 'abs' ) ) && superpwa_get_contents( superpwa_sw( 'abs' ) ) ? 'Your app is ready with the default settings. ' : '';
71+
$superpwa_is_ready = superpwa_is_pwa_ready() ? 'Your app is ready with the default settings. ' : '';
7272

7373
echo '<div class="updated notice is-dismissible"><p>' . sprintf( __( 'Thank you for installing <strong>Super Progressive Web Apps!</strong> '. $superpwa_is_ready .'<a href="%s">Customize your app &rarr;</a>', 'super-progressive-web-apps' ), admin_url( 'admin.php?page=superpwa' ) ) . '</p></div>';
7474

@@ -102,7 +102,7 @@ function superpwa_network_admin_notices() {
102102
// Network admin notice on multisite network activation
103103
if ( get_transient( 'superpwa_network_admin_notice_activation' ) ) {
104104

105-
$superpwa_is_ready = is_ssl() && superpwa_get_contents( superpwa_manifest( 'abs' ) ) && superpwa_get_contents( superpwa_sw( 'abs' ) ) ? 'Your app is ready on the main website with the default settings. ' : '';
105+
$superpwa_is_ready = superpwa_is_pwa_ready() ? 'Your app is ready on the main website with the default settings. ' : '';
106106

107107
echo '<div class="updated notice is-dismissible"><p>' . sprintf( __( 'Thank you for installing <strong>Super Progressive Web Apps!</strong> '. $superpwa_is_ready .'<a href="%s">Customize your app &rarr;</a><br/>Note: manifest and service worker for the individual websites will be generated on the first visit to the respective WordPress admin.', 'super-progressive-web-apps' ), admin_url( 'admin.php?page=superpwa' ) ) . '</p></div>';
108108

@@ -113,7 +113,7 @@ function superpwa_network_admin_notices() {
113113
// Network admin notice on plugin upgrade
114114
if ( get_transient( 'superpwa_admin_notice_upgrade_complete' ) ) {
115115

116-
echo '<div class="updated notice is-dismissible"><p>' . sprintf( __( '<strong>SuperPWA</strong>: Successfully updated to version %s. Thank you! <a href="%s" target="_blank">Discover new features and read the story &rarr;</a>', 'super-progressive-web-apps' ), SUPERPWA_VERSION, 'https://superpwa.com/category/release-notes/latest/?utm_source=superpwa-plugin&utm_medium=update-success-notice-mu' ) . '</p></div>';
116+
echo '<div class="updated notice is-dismissible"><p>' . sprintf( __( '<strong>SuperPWA</strong>: Successfully updated to version %s. Thank you! <a href="%s" target="_blank">Discover new features and read the story &rarr;</a>', 'super-progressive-web-apps' ), SUPERPWA_VERSION, 'https://superpwa.com/category/release-notes/latest/?utm_source=superpwa-plugin&utm_medium=update-success-notice-multisite' ) . '</p></div>';
117117

118118
// Delete transient
119119
delete_transient( 'superpwa_admin_notice_upgrade_complete' );

functions/common.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @function superpwa_is_amp() Check if any AMP plugin is installed
88
* @function superpwa_get_start_url() Return Start Page URL
99
* @function superpwa_httpsify() Convert http URL to https
10+
* @function superpwa_is_pwa_ready() Check if PWA is ready
1011
*/
1112

1213
// Exit if accessed directly
@@ -101,4 +102,28 @@ function superpwa_get_start_url( $rel = false ) {
101102
*/
102103
function superpwa_httpsify( $url ) {
103104
return str_replace( 'http://', 'https://', $url );
105+
}
106+
107+
/**
108+
* Check if PWA is ready
109+
*
110+
* Check for HTTPS.
111+
* Check if manifest is generated.
112+
* Check if service worker is generated.
113+
*
114+
* @return (bool) True if PWA is ready. False otherwise
115+
*
116+
* @since 1.8.1
117+
*/
118+
function superpwa_is_pwa_ready() {
119+
120+
if (
121+
is_ssl() &&
122+
superpwa_get_contents( superpwa_manifest( 'abs' ) ) &&
123+
superpwa_get_contents( superpwa_sw( 'abs' ) )
124+
) {
125+
return apply_filters( 'superpwa_is_pwa_ready', true );
126+
}
127+
128+
return false;
104129
}

languages/super-progressive-web-apps.pot

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,36 @@
22
# This file is distributed under the same license as the Super Progressive Web Apps package.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: Super Progressive Web Apps 1.8\n"
5+
"Project-Id-Version: Super Progressive Web Apps 1.8.1\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/super-progressive-"
77
"web-apps\n"
8-
"POT-Creation-Date: 2018-05-30 17:29:08+00:00\n"
8+
"POT-Creation-Date: 2018-06-05 11:24:28+00:00\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
1212
"PO-Revision-Date: 2018-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <LL@li.org>\n"
1515

16-
#. #-#-#-#-# super-progressive-web-apps.pot (Super Progressive Web Apps 1.8) #-#-#-#-#
16+
#: 3rd-party/onesignal.php:190
17+
msgid ""
18+
"<strong>SuperPWA</strong> is not compatible with OneSignal on multisites "
19+
"yet. Disable one of these plugins until the compatibility is available."
20+
"<br>Please refer to the <a href=\"%s\" target=\"_blank\">OneSignal "
21+
"integration documentation</a> for more info. "
22+
msgstr ""
23+
24+
#: 3rd-party/onesignal.php:212
25+
msgid ""
26+
"<strong>Action Required to integrate SuperPWA with OneSignal:</strong><br>1. "
27+
"Go to <a href=\"%s\" target=\"_blank\">OneSignal Configuration > Scroll down "
28+
"to Advanced Settings &rarr;</a><br>2. Enable <strong>Use my own manifest."
29+
"json</strong><br>3. Set <code>%s</code>as <strong>Custom manifest.json URL</"
30+
"strong> and Save Settings.<br>Please refer the <a href=\"%s\" target=\"_blank"
31+
"\">OneSignal integration documentation</a> for more info. "
32+
msgstr ""
33+
34+
#. #-#-#-#-# super-progressive-web-apps.pot (Super Progressive Web Apps 1.8.1) #-#-#-#-#
1735
#. Plugin Name of the plugin/theme
1836
#: addons/utm-tracking.php:35 admin/admin-ui-setup.php:28
1937
#: admin/admin-ui-setup.php:31 admin/admin-ui-setup.php:34
@@ -293,7 +311,7 @@ msgid ""
293311
"contact your host to add a SSL certificate to your domain."
294312
msgstr ""
295313

296-
#. #-#-#-#-# super-progressive-web-apps.pot (Super Progressive Web Apps 1.8) #-#-#-#-#
314+
#. #-#-#-#-# super-progressive-web-apps.pot (Super Progressive Web Apps 1.8.1) #-#-#-#-#
297315
#. Author of the plugin/theme
298316
#: admin/admin-ui-setup.php:28
299317
msgid "SuperPWA"

loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
require_once( SUPERPWA_PATH_ABS . 'admin/admin-ui-render-addons.php' );
1616

1717
// 3rd party compatibility
18-
if ( ! is_multisite() ) require_once( SUPERPWA_PATH_ABS . '3rd-party/onesignal.php' );
18+
require_once( SUPERPWA_PATH_ABS . '3rd-party/onesignal.php' );
1919

2020
// Load functions
2121
require_once( SUPERPWA_PATH_ABS . 'functions/common.php' );

public/manifest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function superpwa_add_manifest_to_wp_head() {
120120

121121
$tags = apply_filters( 'superpwa_wp_head_tags', $tags );
122122

123-
$tags .= '<!-- / SuperPWA.com -->' . PHP_EOL . PHP_EOL;
123+
$tags .= '<!-- / SuperPWA.com -->' . PHP_EOL;
124124

125125
echo $tags;
126126
}

public/sw.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function superpwa_sw_template() {
140140

141141
// Return if the current request url is in the never cache list
142142
if ( ! neverCacheUrls.every(checkNeverCacheList, e.request.url) ) {
143-
console.log('SuperPWA: Current page is excluded from cache');
143+
console.log( 'SuperPWA: Current request is excluded from cache.' );
144144
return;
145145
}
146146

readme.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ Feel free to get in touch if you have any questions.
176176

177177
== Changelog ==
178178

179+
= 1.8.1 =
180+
* Date: [05.June.2018](https://superpwa.com/push-notifications-are-here-again/?utm_source=wordpress.org&utm_medium=changelog#1.8.1)
181+
* Enhancement: Added an admin notice with [instructions for OneSignal integration](https://superpwa.com/doc/setup-onesignal-with-superpwa/?utm_source=wordpress.org&utm_medium=changelog).
182+
* Enhancement: Updated console log message for URLs excluded from cache for better clarity.
183+
179184
= 1.8 =
180185
* Date: [31.May.2018](https://superpwa.com/push-notifications-are-here-again/?utm_source=wordpress.org&utm_medium=changelog)
181186
* Tested with WordPress 4.9.6.
@@ -266,6 +271,10 @@ Feel free to get in touch if you have any questions.
266271

267272
== Upgrade Notice ==
268273

274+
= 1.8.1 =
275+
* Enhancement: Added an admin notice with instructions for OneSignal integration.
276+
* Enhancement: Updated console log message for URLs excluded from cache for better clarity.
277+
269278
= 1.8 =
270279
* Tested with WordPress 4.9.6.
271280
* New Add-On: Apple Touch Icons. Set the Application Icon and Splash Screen Icon as Apple Touch Icons for compatibility with iOS devices.

superpwa.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Author: SuperPWA
77
* Author URI: https://superpwa.com/?utm_source=superpwa-plugin&utm_medium=author-uri
88
* Contributors: Arun Basil Lal, Jose Varghese
9-
* Version: 1.8
9+
* Version: 1.8.1
1010
* Text Domain: super-progressive-web-apps
1111
* Domain Path: /languages
1212
* License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@@ -43,7 +43,7 @@
4343
* @since 1.6 Depreciated constants for multisite compatibility: SUPERPWA_MANIFEST_FILENAME, SUPERPWA_MANIFEST_ABS, SUPERPWA_MANIFEST_SRC
4444
* @since 1.6 Depreciated constants for multisite compatibility: SUPERPWA_SW_FILENAME, SUPERPWA_SW_ABS, SUPERPWA_SW_SRC
4545
*/
46-
if ( ! defined( 'SUPERPWA_VERSION' ) ) define( 'SUPERPWA_VERSION' , '1.8' ); // SuperPWA current version
46+
if ( ! defined( 'SUPERPWA_VERSION' ) ) define( 'SUPERPWA_VERSION' , '1.8.1' ); // SuperPWA current version
4747
if ( ! defined( 'SUPERPWA_PATH_ABS' ) ) define( 'SUPERPWA_PATH_ABS' , plugin_dir_path( __FILE__ ) ); // Absolute path to the plugin directory. eg - /var/www/html/wp-content/plugins/super-progressive-web-apps/
4848
if ( ! defined( 'SUPERPWA_PATH_SRC' ) ) define( 'SUPERPWA_PATH_SRC' , plugin_dir_url( __FILE__ ) ); // Link to the plugin folder. eg - http://example.com/wp/wp-content/plugins/super-progressive-web-apps/
4949

0 commit comments

Comments
 (0)