Super Progressive Web Apps - Version 1.6

Version Description

  • Date: 23.April.2018
  • New Feature: WordPress Multisite Network Compatibility. One of the most requested features for SuperPWA is now here! Thanks @juslintek for doing a major share of the heavy lifting.
  • New Feature: Added description to the manifest. You can now include a brief description of what your app is about.
  • Enhancement: Moved manifest to the very top of wp_head for better compatibility with some browsers.
  • Enhancement: Improved the file and folder naming, organization, and inline documentation for better readability.
  • Enhancement: Force https:// on all assets and dependencies solving the problem of http:// URLs in manifest and service worker once and for all.
  • Enhancement: Relative URL for manifest for out of the box compatibility with CDN's.
  • Enhancement: Removed forcing of trailing slash on manifest and service worker URLs for better compatibility.
Download this release

Release Info

Developer arunbasillal
Plugin Icon 128x128 Super Progressive Web Apps
Version 1.6
Comparing to
See all releases

Code changes from version 1.5 to 1.6

3rd-party/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden
3rd-party/onesignal.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * OneSignal integration
4
+ *
5
+ * @since 1.6
6
+ * @function superpwa_onesignal_manifest_notice_check() Check if OneSignal integration notice should be displayed or not.
7
+ * @function superpwa_onesignal_get_gcm_sender_id() Extract gcm_sender_id from OneSignal settings
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( ! defined('ABSPATH') ) exit;
12
+
13
+ /**
14
+ * Check if OneSignal integration notice should be displayed or not.
15
+ *
16
+ * @return Bool True if notice should be displayed. False otherwise.
17
+ * @since 1.5
18
+ */
19
+ function superpwa_onesignal_manifest_notice_check() {
20
+
21
+ // No notice needed if OneSignal is not installed or there is no gcm_sender_id
22
+ if ( ! superpwa_onesignal_get_gcm_sender_id() ) {
23
+ return false;
24
+ }
25
+
26
+ // Get OneSignal settins
27
+ $onesignal_wp_settings = get_option( 'OneSignalWPSetting' );
28
+
29
+ // No notice needed if OneSignal custom manifest is enabled and the manifest is the SuperPWA manifest
30
+ if (
31
+ ( isset( $onesignal_wp_settings["use_custom_manifest"] ) ) && ( $onesignal_wp_settings["use_custom_manifest"] == 1 ) &&
32
+ ( isset( $onesignal_wp_settings["custom_manifest_url"] ) ) && ( strcasecmp( trim( $onesignal_wp_settings["custom_manifest_url"] ), superpwa_manifest( 'src' ) ) == 0 )
33
+ ) {
34
+ return false;
35
+ }
36
+
37
+ // Display notice for every other case
38
+ return true;
39
+ }
40
+
41
+ /**
42
+ * Extract gcm_sender_id from OneSignal settings
43
+ *
44
+ * @link https://wordpress.org/plugins/onesignal-free-web-push-notifications/
45
+ *
46
+ * @return (String|Bool) gcm_sender_id of OneSignal if OneSignal is installed, false otherwise
47
+ * @since 1.5
48
+ */
49
+ function superpwa_onesignal_get_gcm_sender_id() {
50
+
51
+ // If OneSignal is installed and active
52
+ if ( class_exists( 'OneSignal' ) ) {
53
+
54
+ // This is the gcm_sender_id of OneSignal, same for all installs.
55
+ return '482941778795';
56
+ }
57
+
58
+ return false;
59
+ }
README.MD ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Super Progressive Web Apps
2
+ <p>
3
+ <a href="https://twitter.com/intent/follow?screen_name=superpwa">
4
+ <img src="https://img.shields.io/twitter/follow/superpwa.svg?style=social&logo=twitter" alt="follow SuperPWA on Twitter">
5
+ </a>
6
+ <a href="https://github.com/SuperPWA/Super-Progressive-Web-Apps">
7
+ <img src="https://img.shields.io/github/stars/SuperPWA/Super-Progressive-Web-Apps.svg?style=social&logo=github&label=SuperPWA" alt="Star Super Progressive Web Apps">
8
+ </a>
9
+
10
+
11
+ </p>
12
+ <p>
13
+ <a href="https://superpwa.com">
14
+ <img src="https://lighthouse-badge.appspot.com?score=100" alt="LightHouse Score">
15
+ </a>
16
+ <a href="https://wordpress.org/plugins/super-progressive-web-apps/">
17
+ <img src="https://img.shields.io/wordpress/plugin/dt/super-progressive-web-apps.svg?style=plastic" alt="Super Progressive Web Apps Downloads">
18
+ </a>
19
+ <a href="https://wordpress.org/plugins/super-progressive-web-apps/">
20
+ <img src="https://img.shields.io/wordpress/plugin/r/super-progressive-web-apps.svg?style=plastic" alt="Super Progressive Web Apps Rating">
21
+ </a>
22
+ <a href="https://wordpress.org/plugins/super-progressive-web-apps/">
23
+ <img src="https://img.shields.io/wordpress/plugin/v/super-progressive-web-apps.svg?style=plastic" alt="Super Progressive Web Apps Version">
24
+ </a>
25
+ <a href="https://wordpress.org/plugins/super-progressive-web-apps/">
26
+ <img src="https://img.shields.io/wordpress/v/super-progressive-web-apps.svg?style=plastic" alt="Super Progressive Web Apps Version">
27
+ </a>
28
+ </p>
29
+
30
+ ## Welcome to the Super PWA GitHub repository
31
+ > <a href="https://superpwa.com">SuperPWA</a> helps you convert your WordPress website into a Progressive Web App.
32
+
33
+ 🔗 Demo : <a href="https://superpwa.com/?utm=GitHub">superpwa.com</a>
34
+
35
+ ## What is Progressive Web Apps
36
+ Progressive Web Apps (PWA) is a new technology that creates a middle ground between a website and a mobile app. They are installed on the phone like a normal app (web app) and can be accessed from the home screen.
37
+
38
+ Users can come back to your website by launching the app from their home screen and interact with your website through an app-like interface. Your return visitors will experience almost-instant loading times and enjoy the great performance benefits of your PWA!
39
+
40
+ <a href="https://superpwa.com">Super Progressive Web Apps</a> makes it easy for you to convert your WordPress website into a Progressive Web App easily!
41
+
42
+ ## Installation
43
+ Once SuperPWA is installed, users browsing your website from a supported mobile device will see a "Add To Home Screen" notice (from the bottom of the screen) and will be able to 'install your website' on the home screen of their device. Every page visited is stored locally on their device and will be available to read even when they are offline!
44
+
45
+ SuperPWA is easy to configure, it takes less than a minute to set-up your Progressive Web App! SuperPWA does a clean uninstall, by removing every database entry and file that it creates. In fact, none of the default settings are saved to the database until you manually save it the first time. Go ahead and give it a try.
46
+
47
+ ### Progressive Web App Minimum Requirments
48
+ - [x] Progressive Web Apps require that your WordPress website is served from a secure origin i.e. your website should be HTTPS and not HTTP. If your website isn’t HTTPS, please contact your host about it. You can also ask us [Support Forums](https://wordpress.org/support/plugin/super-progressive-web-apps) if you need help.
49
+
50
+ #### What's in the box
51
+
52
+ Here are the current features of Super Progressive Web Apps:
53
+
54
+ * Generate a manifest for your website and add it to the head of your website.
55
+ * Set the application icon for your Progressive Web App.
56
+ * Set the background color for the splash screen of your Progressive Web App.
57
+ * Your website will show the "Add to home screen" notice when accessed in a supported browser.
58
+ * Aggressive caching of pages using CacheStorage API.
59
+ * Pages once cached are served even if the user is offline.
60
+ * Set custom offline page: Select the page you want the user to see when a page that isn't in the cache is accessed and the user is offline.
61
+ * New in version 1.2: Support for theme-color.
62
+ * New in version 1.2: Now you can edit the Application Name and Application Short name.
63
+ * New in version 1.2: Set the start page of your PWA.
64
+ * New in version 1.2: Set Accelerated Mobile Pages (AMP) version of the start page. Supported plugins: AMP for WordPress, AMP for WP, Better AMP, AMP Supremacy, WP AMP.
65
+ * New in version 1.3: Added support for high-quality splash screen. You can now set the 512x512 icon for the splash screen of your Progressive Web App.
66
+ * New in version 1.3: Super Progressive Web Apps now accounts for content updates and will update the cache as you update the website.
67
+ * New in version 1.3: Improved in-browser service worker update handling.
68
+ * New in version 1.4: You can now set the default orientation of your PWA. Choose from "any" (Follow Device Orientation), "Portrait" and "Landscape".
69
+ * New in version 1.4: You can now set the theme_color property in the manifest.
70
+ * New in version 1.5: OneSignal integration for Push notifications.
71
+ * New in version 1.6: WordPress Multisite Network compatibility.
72
+
73
+ #### Upcoming features:
74
+ * Offline Indicator Notice.
75
+
76
+ ### Device and Browser Support For PWA
77
+ | <img src="https://user-images.githubusercontent.com/1215767/34348387-a2e64588-ea4d-11e7-8267-a43365103afe.png" alt="Chrome" width="16px" height="16px" /> Chrome | <img src="https://user-images.githubusercontent.com/1215767/34348383-9e7ed492-ea4d-11e7-910c-03b39d52f496.png" alt="Firefox" width="16px" height="16px" /> Firefox | <img src="https://user-images.githubusercontent.com/1215767/34348394-a981f892-ea4d-11e7-9156-d128d58386b9.png" alt="Safari" width="16px" height="16px" /> Safari | <img src="https://user-images.githubusercontent.com/1215767/34348380-93e77ae8-ea4d-11e7-8696-9a989ddbbbf5.png" alt="Edge" width="16px" height="16px" /> Edge | Opera Mini | Samsung Internet | Brave |
78
+ | :---------: | :---------: | :---------: | :---------: | :---------: | :---------: | :---------: |
79
+ | Yes | Yes | Partially | Beta | No | Yes | Yes |
80
+ | 57+ | 57+ | 11.3+ | 17 ships | - | 6.2+ | 1.0.44+
81
+
82
+ Progressive web apps need browsers that support manifests and service workers. Currently Google Chrome (version 57+), Chrome for Android (62), Mozilla Firefox (57), Firefox for Android (58) are the major browsers that support PWA.
83
+
84
+ The list is fast growing and is likely to be supported in most major browsers by the end of this year.
85
+
86
+ ### Why Build Progressive Web Apps?
87
+ [![Why Build Progressive Web Apps](http://i3.ytimg.com/vi/1QILz1lAzWY/maxresdefault.jpg)](https://www.youtube.com/embed/1QILz1lAzWY)
88
+
89
+ ### How To Convert Your WordPress Website Into A Progressive Web App
90
+
91
+ #### WordPress Installation
92
+
93
+ * Visit WordPress Admin > **Plugins** > **Add New**
94
+ * Search for **Super Progressive Web Apps**
95
+ * Click "**Install Now**" and then "**Activate**" Super Progressive Web Apps
96
+
97
+ #### To install manually:
98
+
99
+ * Upload super-progressive-web-apps folder to the /wp-content/plugins/ directory on your server
100
+ * Go to WordPress Admin > **Plugins**
101
+ * Activate **Super Progressive Web Apps** plugin from the list.
102
+
103
+ #### Customizing Your Progressive Web App
104
+
105
+ Your Progressive Web App should be ready to test with the default settings upon activation. You can customize it further and make it truly your own.
106
+
107
+ * Go to WordPress Admin > **Settings** > "**SuperPWA**"
108
+ * Set a Background Color for the splash screen to be shown when your PWA is opened on a mobile device.
109
+ * Set the Application Icon. This will be the icon of your PWA when it is added to the homescreen in a mobile device. The icon must be a PNG image and exactly 192 x 192 pixels in size.
110
+ * Set the Offline Page. This page will be displayed if the user is offline and the page he requested is not cached already. Ideally you should create a dedicated WordPress page and set it here. Within the page you create, you could add a note that reads, "It looks like you are offline and the page you requested is not available right now. Please check back again once you are online.".
111
+ * Click "Save Settings".
112
+
113
+ #### Testing Your Progressive Web App
114
+
115
+ * Open a supported browser in a supported device (for eg: Chrome for Android (62 or higher) in an Android Phone)
116
+ * Enter your website and wait till it fully loads
117
+ * You should see a pop-up that has your Application Icon and a button that reads "ADD TO HOME SCREEN".
118
+ * Click on it and your PWA will be added to your home screen. Wait for the install to complete.
119
+ * Go to your home screen and open your PWA. Browse into a few pages if you like. Close the App.
120
+ * Disconnect from the internet and now open your PWA again. You should be able to see all the pages that you previously browsed.
121
+ * Try visiting a page that you did not visit before. You should see the page you set as your "Offline Page" in the settings of SuperPWA.
122
+
123
+
124
+ ### About us
125
+ > We are a duo who got excited about the idea. Our mission is simple: Help you build an awesome PWA that your users would want to have on their home screen. When we first heard about PWA we wanted to learn everything about it. We have spent countless hours learning and wants to share it with the world. Please give us your constructive feedback and support.
126
+
127
+ ## Support
128
+ This is a developer's portal for Super Progressive Web Apps and should not be used for support. Please visit the
129
+ [Support Forums](https://wordpress.org/support/plugin/super-progressive-web-apps).
130
+
131
+ ## Reporting bugs
132
+ If you ever get stuck, we are here to watch your back! [Open a New Support Topic](https://wordpress.org/support/plugin/super-progressive-web-apps) ticket if you have a question or need a feature. We are super excited to hear your feedback and we want to genuinely help you build the best Progressive Web App for your WordPress website!
133
+
134
+ ## Contributions
135
+ Anyone is welcome to contribute to Super PWA to make it SUPER.
136
+
137
+ There are various ways you can contribute:
138
+
139
+ * [Raise an issue](https://github.com/SuperPWA/Super-Progressive-Web-Apps/issues) on GitHub.
140
+ * Engage with us on Social Media
141
+ * Follow us on [Twitter](https://twitter.com/SuperPWA)
142
+ * Like us on [Facebook](https://www.facebook.com/SuperPWA)
143
+ * Send us a Pull Request with your bug fixes and/or new features.
144
+ * Provide feedback and [suggestions on enhancements](https://github.com/SuperPWA/Super-Progressive-Web-Apps/issues?direction=desc&labels=Enhancement&page=1&sort=created&state=open).
145
+ * ##### Share via Social Media's
146
+ * [Share on Twitter](https://twitter.com/home?status=Super%20Progressive%20Web%20Apps%20helps%20to%20convert%20your%20WordPress%20website%20into%20PWA%20%23SuperPWA%20https%3A//github.com/SuperPWA/Super-Progressive-Web-Apps/%20%40SuperPWA)
147
+ * [Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A//github.com/SuperPWA/Super-Progressive-Web-Apps/)
148
+ * [Share on Google Plus](https://plus.google.com/share?url=https%3A//github.com/SuperPWA/Super-Progressive-Web-Apps/)
149
+ * [Share on LinkedIn](https://www.linkedin.com/shareArticle?mini=true&url=https%3A//github.com/SuperPWA/Super-Progressive-Web-Apps/&title=Super%20Progressive%20Web%20Apps&summary=Super%20Progressive%20Web%20Apps%20helps%20to%20convert%20your%20WordPress%20website%20into%20PWA%20%23SuperPWA&source=GitHub)
150
+
151
+ **[⬆ back to top](#super-progressive-web-apps)**
152
+ <img src="https://ga-beacon.appspot.com/UA-115873914-2/GitHub_Readme?pixel"/>
admin/admin-setup.php CHANGED
@@ -6,11 +6,14 @@
6
  * @function superpwa_add_menu_links() Add admin menu pages
7
  * @function superpwa_register_settings Register Settings
8
  * @function superpwa_validater_and_sanitizer() Validate And Sanitize User Input Before Its Saved To Database
9
- * @function superpwa_get_settings() Get settings from database
 
 
 
10
  */
11
 
12
  // Exit if accessed directly
13
- if ( ! defined('ABSPATH') ) exit;
14
 
15
  /**
16
  * Add admin menu pages
@@ -19,8 +22,7 @@ if ( ! defined('ABSPATH') ) exit;
19
  * @refer https://developer.wordpress.org/plugins/administration-menus/
20
  */
21
  function superpwa_add_menu_links() {
22
-
23
- add_options_page( __('Super Progressive Web Apps','super-progressive-web-apps'), __('SuperPWA','super-progressive-web-apps'), 'manage_options', 'superpwa','superpwa_admin_interface_render' );
24
  }
25
  add_action( 'admin_menu', 'superpwa_add_menu_links' );
26
 
@@ -64,6 +66,15 @@ function superpwa_register_settings() {
64
  'superpwa_basic_settings_section' // Settings Section ID
65
  );
66
 
 
 
 
 
 
 
 
 
 
67
  // Application Icon
68
  add_settings_field(
69
  'superpwa_icons', // ID
@@ -146,9 +157,9 @@ function superpwa_register_settings() {
146
 
147
  // Service Worker status
148
  add_settings_field(
149
- 'superpwa_sw_status', // ID
150
  __('Service Worker', 'super-progressive-web-apps'), // Title
151
- 'superpwa_sw_status_cb', // CB
152
  'superpwa_pwa_status_section', // Page slug
153
  'superpwa_pwa_status_section' // Settings Section ID
154
  );
@@ -157,7 +168,7 @@ function superpwa_register_settings() {
157
  add_settings_field(
158
  'superpwa_https_status', // ID
159
  __('HTTPS', 'super-progressive-web-apps'), // Title
160
- 'superpwa_https_status_cb', // CB
161
  'superpwa_pwa_status_section', // Page slug
162
  'superpwa_pwa_status_section' // Settings Section ID
163
  );
@@ -167,15 +178,20 @@ add_action( 'admin_init', 'superpwa_register_settings' );
167
  /**
168
  * Validate and sanitize user input before its saved to database
169
  *
170
- * @since 1.0
 
 
171
  */
172
  function superpwa_validater_and_sanitizer( $settings ) {
173
 
174
  // Sanitize Application Name
175
- $settings['app_name'] = sanitize_text_field($settings['app_name']) == '' ? get_bloginfo('name') : sanitize_text_field($settings['app_name']);
176
 
177
  // Sanitize Application Short Name
178
- $settings['app_short_name'] = sanitize_text_field($settings['app_short_name']) == '' ? get_bloginfo('name') : sanitize_text_field($settings['app_short_name']);
 
 
 
179
 
180
  // Sanitize hex color input for background_color
181
  $settings['background_color'] = preg_match( '/#([a-f0-9]{3}){1,2}\b/i', $settings['background_color'] ) ? sanitize_text_field( $settings['background_color'] ) : '#D5E0EB';
@@ -184,10 +200,10 @@ function superpwa_validater_and_sanitizer( $settings ) {
184
  $settings['theme_color'] = preg_match( '/#([a-f0-9]{3}){1,2}\b/i', $settings['theme_color'] ) ? sanitize_text_field( $settings['theme_color'] ) : '#D5E0EB';
185
 
186
  // Sanitize application icon
187
- $settings['icon'] = sanitize_text_field( $settings['icon'] ) == '' ? SUPERPWA_PATH_SRC . 'public/images/logo.png' : sanitize_text_field( $settings['icon'] );
188
 
189
  // Sanitize splash screen icon
190
- $settings['splash_icon'] = sanitize_text_field( $settings['splash_icon'] );
191
 
192
  return $settings;
193
  }
@@ -201,8 +217,9 @@ function superpwa_validater_and_sanitizer( $settings ) {
201
  function superpwa_get_settings() {
202
 
203
  $defaults = array(
204
- 'app_name' => get_bloginfo('name'),
205
- 'app_short_name' => get_bloginfo('name'),
 
206
  'icon' => SUPERPWA_PATH_SRC . 'public/images/logo.png',
207
  'splash_icon' => SUPERPWA_PATH_SRC . 'public/images/logo-512x512.png',
208
  'background_color' => '#D5E0EB',
@@ -213,7 +230,7 @@ function superpwa_get_settings() {
213
  'orientation' => 1,
214
  );
215
 
216
- $settings = get_option('superpwa_settings', $defaults);
217
 
218
  return $settings;
219
  }
@@ -240,4 +257,64 @@ function superpwa_enqueue_css_js( $hook ) {
240
  // Main JS
241
  wp_enqueue_script( 'superpwa-main-js', SUPERPWA_PATH_SRC . 'admin/js/main.js', array( 'wp-color-picker' ), SUPERPWA_VERSION, true );
242
  }
243
- add_action( 'admin_enqueue_scripts', 'superpwa_enqueue_css_js' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  * @function superpwa_add_menu_links() Add admin menu pages
7
  * @function superpwa_register_settings Register Settings
8
  * @function superpwa_validater_and_sanitizer() Validate And Sanitize User Input Before Its Saved To Database
9
+ * @function superpwa_get_settings() Get settings from database
10
+ * @function superpwa_after_save_settings_todo() Todo list after saving admin options
11
+ * @function superpwa_footer_text() Admin footer text
12
+ * @function superpwa_footer_version() Admin footer version
13
  */
14
 
15
  // Exit if accessed directly
16
+ if ( ! defined( 'ABSPATH' ) ) exit;
17
 
18
  /**
19
  * Add admin menu pages
22
  * @refer https://developer.wordpress.org/plugins/administration-menus/
23
  */
24
  function superpwa_add_menu_links() {
25
+ add_options_page( __( 'Super Progressive Web Apps', 'super-progressive-web-apps' ), __( 'SuperPWA', 'super-progressive-web-apps' ), 'manage_options', 'superpwa','superpwa_admin_interface_render' );
 
26
  }
27
  add_action( 'admin_menu', 'superpwa_add_menu_links' );
28
 
66
  'superpwa_basic_settings_section' // Settings Section ID
67
  );
68
 
69
+ // Description
70
+ add_settings_field(
71
+ 'superpwa_description', // ID
72
+ __( 'Description', 'super-progressive-web-apps' ), // Title
73
+ 'superpwa_description_cb', // CB
74
+ 'superpwa_basic_settings_section', // Page slug
75
+ 'superpwa_basic_settings_section' // Settings Section ID
76
+ );
77
+
78
  // Application Icon
79
  add_settings_field(
80
  'superpwa_icons', // ID
157
 
158
  // Service Worker status
159
  add_settings_field(
160
+ 'superpwa_sw_status', // ID
161
  __('Service Worker', 'super-progressive-web-apps'), // Title
162
+ 'superpwa_sw_status_cb', // CB
163
  'superpwa_pwa_status_section', // Page slug
164
  'superpwa_pwa_status_section' // Settings Section ID
165
  );
168
  add_settings_field(
169
  'superpwa_https_status', // ID
170
  __('HTTPS', 'super-progressive-web-apps'), // Title
171
+ 'superpwa_https_status_cb', // CB
172
  'superpwa_pwa_status_section', // Page slug
173
  'superpwa_pwa_status_section' // Settings Section ID
174
  );
178
  /**
179
  * Validate and sanitize user input before its saved to database
180
  *
181
+ * @since 1.0
182
+ * @since 1.3 Added splash_icon
183
+ * @since 1.6 Added description
184
  */
185
  function superpwa_validater_and_sanitizer( $settings ) {
186
 
187
  // Sanitize Application Name
188
+ $settings['app_name'] = sanitize_text_field( $settings['app_name'] ) == '' ? get_bloginfo( 'name' ) : sanitize_text_field( $settings['app_name'] );
189
 
190
  // Sanitize Application Short Name
191
+ $settings['app_short_name'] = sanitize_text_field( $settings['app_short_name'] ) == '' ? get_bloginfo( 'name' ) : sanitize_text_field( $settings['app_short_name'] );
192
+
193
+ // Sanitize description
194
+ $settings['description'] = sanitize_text_field( $settings['description'] );
195
 
196
  // Sanitize hex color input for background_color
197
  $settings['background_color'] = preg_match( '/#([a-f0-9]{3}){1,2}\b/i', $settings['background_color'] ) ? sanitize_text_field( $settings['background_color'] ) : '#D5E0EB';
200
  $settings['theme_color'] = preg_match( '/#([a-f0-9]{3}){1,2}\b/i', $settings['theme_color'] ) ? sanitize_text_field( $settings['theme_color'] ) : '#D5E0EB';
201
 
202
  // Sanitize application icon
203
+ $settings['icon'] = sanitize_text_field( $settings['icon'] ) == '' ? superpwa_httpsify( SUPERPWA_PATH_SRC . 'public/images/logo.png' ) : sanitize_text_field( superpwa_httpsify( $settings['icon'] ) );
204
 
205
  // Sanitize splash screen icon
206
+ $settings['splash_icon'] = sanitize_text_field( superpwa_httpsify( $settings['splash_icon'] ) );
207
 
208
  return $settings;
209
  }
217
  function superpwa_get_settings() {
218
 
219
  $defaults = array(
220
+ 'app_name' => get_bloginfo( 'name' ),
221
+ 'app_short_name' => get_bloginfo( 'name' ),
222
+ 'description' => get_bloginfo( 'description' ),
223
  'icon' => SUPERPWA_PATH_SRC . 'public/images/logo.png',
224
  'splash_icon' => SUPERPWA_PATH_SRC . 'public/images/logo-512x512.png',
225
  'background_color' => '#D5E0EB',
230
  'orientation' => 1,
231
  );
232
 
233
+ $settings = get_option( 'superpwa_settings', $defaults );
234
 
235
  return $settings;
236
  }
257
  // Main JS
258
  wp_enqueue_script( 'superpwa-main-js', SUPERPWA_PATH_SRC . 'admin/js/main.js', array( 'wp-color-picker' ), SUPERPWA_VERSION, true );
259
  }
260
+ add_action( 'admin_enqueue_scripts', 'superpwa_enqueue_css_js' );
261
+
262
+ /**
263
+ * Todo list after saving admin options
264
+ *
265
+ * Regenerate manifest
266
+ * Regenerate service worker
267
+ *
268
+ * @since 1.0
269
+ */
270
+ function superpwa_after_save_settings_todo() {
271
+
272
+ // Regenerate manifest
273
+ superpwa_generate_manifest();
274
+
275
+ // Regenerate service worker
276
+ superpwa_generate_sw();
277
+ }
278
+ add_action( 'add_option_superpwa_settings', 'superpwa_after_save_settings_todo' );
279
+ add_action( 'update_option_superpwa_settings', 'superpwa_after_save_settings_todo' );
280
+
281
+ /**
282
+ * Admin footer text
283
+ *
284
+ * A function to add footer text to the settings page of the plugin.
285
+ * @since 1.2
286
+ * @refer https://codex.wordpress.org/Function_Reference/get_current_screen
287
+ */
288
+ function superpwa_footer_text( $default ) {
289
+
290
+ // Retun default on non-plugin pages
291
+ $screen = get_current_screen();
292
+ if ( $screen->id !== "settings_page_superpwa" ) {
293
+ return $default;
294
+ }
295
+
296
+ $superpwa_footer_text = sprintf( __( 'If you like SuperPWA, please <a href="%s" target="_blank">make a donation</a> or leave a <a href="%s" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> rating to support continued development. Thanks a bunch!', 'super-progressive-web-apps' ),
297
+ 'https://millionclues.com/donate/',
298
+ 'https://wordpress.org/support/plugin/super-progressive-web-apps/reviews/?rate=5#new-post'
299
+ );
300
+
301
+ return $superpwa_footer_text;
302
+ }
303
+ add_filter( 'admin_footer_text', 'superpwa_footer_text' );
304
+
305
+ /**
306
+ * Admin footer version
307
+ *
308
+ * @since 1.0
309
+ */
310
+ function superpwa_footer_version( $default ) {
311
+
312
+ // Retun default on non-plugin pages
313
+ $screen = get_current_screen();
314
+ if ( $screen->id !== "settings_page_superpwa" ) {
315
+ return $default;
316
+ }
317
+
318
+ return 'SuperPWA ' . SUPERPWA_VERSION;
319
+ }
320
+ add_filter( 'update_footer', 'superpwa_footer_version', 11 );
admin/admin-ui-render.php CHANGED
@@ -5,6 +5,7 @@
5
  * @since 1.0
6
  * @function superpwa_app_name_cb() Application Name
7
  * @function superpwa_app_short_name_cb() Application Short Name
 
8
  * @function superpwa_background_color_cb() Splash Screen Background Color
9
  * @function superpwa_theme_color_cb() Theme Color
10
  * @function superpwa_app_icon_cb() Application Icon
@@ -55,7 +56,30 @@ function superpwa_app_short_name_cb() {
55
  <input type="text" name="superpwa_settings[app_short_name]" class="regular-text" value="<?php if ( isset( $settings['app_short_name'] ) && ( ! empty($settings['app_short_name']) ) ) echo esc_attr($settings['app_short_name']); ?>"/>
56
 
57
  <p class="description" id="tagline-description">
58
- <?php _e('Used when there is insufficient space to display the full name of the application.', 'super-progressive-web-apps'); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  </p>
60
 
61
  </fieldset>
@@ -220,7 +244,7 @@ function superpwa_offline_page_cb() {
220
  </label>
221
 
222
  <p class="description" id="tagline-description">
223
- <?php printf( __( 'Offline page is displayed when the device is offline and the requested page is not already cached. Current offline page is <code>%s</code>', 'super-progressive-web-apps' ), get_permalink($settings['offline_page']) ? trailingslashit(get_permalink($settings['offline_page'])) : trailingslashit(get_bloginfo( 'wpurl' )) ); ?>
224
  </p>
225
 
226
  <?php
@@ -265,9 +289,9 @@ function superpwa_orientation_cb() {
265
  */
266
  function superpwa_manifest_status_cb() {
267
 
268
- if ( superpwa_get_contents( SUPERPWA_MANIFEST_ABS ) ) {
269
 
270
- printf( '<p><span class="dashicons dashicons-yes" style="color: #46b450;"></span> ' . __( 'Manifest generated successfully. You can <a href="%s" target="_blank">see it here &rarr;</a>.', 'super-progressive-web-apps' ) . '</p>', SUPERPWA_MANIFEST_SRC );
271
  } else {
272
 
273
  echo '<p><span class="dashicons dashicons-no-alt" style="color: #dc3232;"></span> ' . __('Manifest generation failed. Check if WordPress can write to your root folder (the same folder with wp-config.php).', 'super-progressive-web-apps') . '</p>';
@@ -281,7 +305,7 @@ function superpwa_manifest_status_cb() {
281
  */
282
  function superpwa_sw_status_cb() {
283
 
284
- if ( superpwa_get_contents( SUPERPWA_SW_ABS ) ) {
285
 
286
  printf( '<p><span class="dashicons dashicons-yes" style="color: #46b450;"></span> ' . __( 'Service worker generated successfully.', 'super-progressive-web-apps' ) . '</p>' );
287
  } else {
@@ -336,7 +360,7 @@ function superpwa_admin_interface_render () {
336
  echo '<div class="notice notice-error"><p>' .
337
  sprintf(
338
  __( '<strong>To integrate with OneSignal:</strong> Enable <strong>Use my own manifest.json</strong> and set <code>%s</code><br>as <strong>Custom manifest.json URL</strong> in <a href="%s" target="_blank">OneSignal Configuration > Advanced Settings &rarr;</a>', 'super-progressive-web-apps' ),
339
- SUPERPWA_MANIFEST_SRC,
340
  admin_url( 'admin.php?page=onesignal-push#configuration' )
341
  ) .
342
  '</p></div>';
5
  * @since 1.0
6
  * @function superpwa_app_name_cb() Application Name
7
  * @function superpwa_app_short_name_cb() Application Short Name
8
+ * @function superpwa_description_cb() Description
9
  * @function superpwa_background_color_cb() Splash Screen Background Color
10
  * @function superpwa_theme_color_cb() Theme Color
11
  * @function superpwa_app_icon_cb() Application Icon
56
  <input type="text" name="superpwa_settings[app_short_name]" class="regular-text" value="<?php if ( isset( $settings['app_short_name'] ) && ( ! empty($settings['app_short_name']) ) ) echo esc_attr($settings['app_short_name']); ?>"/>
57
 
58
  <p class="description" id="tagline-description">
59
+ <?php _e('Used when there is insufficient space to display the full name of the application. <code>12</code> characters or less.', 'super-progressive-web-apps'); ?>
60
+ </p>
61
+
62
+ </fieldset>
63
+
64
+ <?php
65
+ }
66
+
67
+ /**
68
+ * Description
69
+ *
70
+ * @since 1.6
71
+ */
72
+ function superpwa_description_cb() {
73
+
74
+ // Get Settings
75
+ $settings = superpwa_get_settings(); ?>
76
+
77
+ <fieldset>
78
+
79
+ <input type="text" name="superpwa_settings[description]" class="regular-text" value="<?php if ( isset( $settings['description'] ) && ( ! empty( $settings['description'] ) ) ) echo esc_attr( $settings['description'] ); ?>"/>
80
+
81
+ <p class="description" id="tagline-description">
82
+ <?php _e( 'A brief description of what your app is about.', 'super-progressive-web-apps' ); ?>
83
  </p>
84
 
85
  </fieldset>
244
  </label>
245
 
246
  <p class="description" id="tagline-description">
247
+ <?php printf( __( 'Offline page is displayed when the device is offline and the requested page is not already cached. Current offline page is <code>%s</code>', 'super-progressive-web-apps' ), get_permalink($settings['offline_page']) ? get_permalink( $settings['offline_page'] ) : get_bloginfo( 'wpurl' ) ); ?>
248
  </p>
249
 
250
  <?php
289
  */
290
  function superpwa_manifest_status_cb() {
291
 
292
+ if ( superpwa_get_contents( superpwa_manifest( 'abs' ) ) ) {
293
 
294
+ printf( '<p><span class="dashicons dashicons-yes" style="color: #46b450;"></span> ' . __( 'Manifest generated successfully. You can <a href="%s" target="_blank">see it here &rarr;</a>.', 'super-progressive-web-apps' ) . '</p>', superpwa_manifest( 'src' ) );
295
  } else {
296
 
297
  echo '<p><span class="dashicons dashicons-no-alt" style="color: #dc3232;"></span> ' . __('Manifest generation failed. Check if WordPress can write to your root folder (the same folder with wp-config.php).', 'super-progressive-web-apps') . '</p>';
305
  */
306
  function superpwa_sw_status_cb() {
307
 
308
+ if ( superpwa_get_contents( superpwa_sw( 'abs' ) ) ) {
309
 
310
  printf( '<p><span class="dashicons dashicons-yes" style="color: #46b450;"></span> ' . __( 'Service worker generated successfully.', 'super-progressive-web-apps' ) . '</p>' );
311
  } else {
360
  echo '<div class="notice notice-error"><p>' .
361
  sprintf(
362
  __( '<strong>To integrate with OneSignal:</strong> Enable <strong>Use my own manifest.json</strong> and set <code>%s</code><br>as <strong>Custom manifest.json URL</strong> in <a href="%s" target="_blank">OneSignal Configuration > Advanced Settings &rarr;</a>', 'super-progressive-web-apps' ),
363
+ superpwa_manifest( 'src' ),
364
  admin_url( 'admin.php?page=onesignal-push#configuration' )
365
  ) .
366
  '</p></div>';
admin/basic-setup.php CHANGED
@@ -3,15 +3,15 @@
3
  * Basic setup functions for the plugin
4
  *
5
  * @since 1.0
 
6
  * @function superpwa_activate_plugin() Plugin activatation todo list
7
  * @function superpwa_admin_notice_activation() Admin notice on plugin activation
 
8
  * @function superpwa_upgrader() Plugin upgrade todo list
9
- * @function superpwa_deactivate_plugin Plugin deactivation todo list
10
  * @function superpwa_load_plugin_textdomain() Load plugin text domain
11
  * @function superpwa_settings_link() Print direct link to plugin settings in plugins list in admin
12
  * @function superpwa_plugin_row_meta() Add donate and other links to plugins list
13
- * @function superpwa_footer_text() Admin footer text
14
- * @function superpwa_footer_version() Admin footer version
15
  */
16
 
17
  // Exit if accessed directly
@@ -20,10 +20,18 @@ if ( ! defined('ABSPATH') ) exit;
20
  /**
21
  * Plugin activatation todo list
22
  *
23
- * This function runs when user activates the plugin. Used in register_activation_hook in the main plugin file.
24
- * @since 1.0
 
 
 
 
 
 
 
 
25
  */
26
- function superpwa_activate_plugin() {
27
 
28
  // Generate manifest with default options
29
  superpwa_generate_manifest();
@@ -31,14 +39,24 @@ function superpwa_activate_plugin() {
31
  // Generate service worker
32
  superpwa_generate_sw();
33
 
34
- // Set transient for activation notice
35
- set_transient( 'superpwa_admin_notice_activation', true, 5 );
 
 
 
 
 
 
 
 
 
36
  }
 
37
 
38
  /**
39
  * Admin notice on plugin activation
40
  *
41
- * @since 1.2
42
  */
43
  function superpwa_admin_notice_activation() {
44
 
@@ -47,7 +65,7 @@ function superpwa_admin_notice_activation() {
47
  return;
48
  }
49
 
50
- $superpwa_is_ready = is_ssl() && superpwa_get_contents( SUPERPWA_MANIFEST_ABS ) && superpwa_get_contents( SUPERPWA_SW_ABS ) && ( ! superpwa_onesignal_manifest_notice_check() ) ? 'Your app is ready with the default settings. ' : '';
51
 
52
  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( 'options-general.php?page=superpwa' ) ) . '</p></div>';
53
 
@@ -56,28 +74,77 @@ function superpwa_admin_notice_activation() {
56
  }
57
  add_action( 'admin_notices', 'superpwa_admin_notice_activation' );
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  /**
60
  * Plugin upgrade todo list
61
  *
62
- * @since 1.3.1
63
- * @since 1.4 Added orientation setting and theme_color to database when upgrading from pre 1.4 versions.
 
64
  */
65
  function superpwa_upgrader() {
66
 
67
- $current_ver = get_option('superpwa_version');
68
 
69
  // Return if we have already done this todo
70
- if ( $current_ver == SUPERPWA_VERSION )
71
  return;
 
72
 
73
- // Return if this is the first time the plugin is installed.
 
 
 
 
 
74
  if ( $current_ver === false ) {
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  add_option( 'superpwa_version', SUPERPWA_VERSION );
 
77
  return;
78
  }
79
 
80
- if ( $current_ver < 1.4 ) {
 
 
 
 
 
 
 
81
 
82
  // Get settings
83
  $settings = superpwa_get_settings();
@@ -100,28 +167,46 @@ function superpwa_upgrader() {
100
 
101
  // Add current version to database
102
  update_option( 'superpwa_version', SUPERPWA_VERSION );
 
 
 
103
  }
104
  add_action( 'admin_init', 'superpwa_upgrader' );
105
 
106
  /**
107
  * Plugin deactivation todo list
108
  *
109
- * Runs during deactivation. During uninstall uninstall.php is also executed
110
- * @since 1.0
 
 
 
 
 
 
111
  */
112
- function superpwa_deactivate_plugin() {
113
 
114
  // Delete manifest
115
  superpwa_delete_manifest();
116
 
117
  // Delete service worker
118
  superpwa_delete_sw();
 
 
 
 
 
 
 
 
119
  }
 
120
 
121
  /**
122
  * Load plugin text domain
123
  *
124
- * @since 1.0
125
  */
126
  function superpwa_load_plugin_textdomain() {
127
 
@@ -132,7 +217,7 @@ add_action( 'plugins_loaded', 'superpwa_load_plugin_textdomain' );
132
  /**
133
  * Print direct link to plugin settings in plugins list in admin
134
  *
135
- * @since 1.0
136
  */
137
  function superpwa_settings_link( $links ) {
138
 
@@ -148,58 +233,17 @@ add_filter( 'plugin_action_links_super-progressive-web-apps/superpwa.php', 'supe
148
  /**
149
  * Add donate and other links to plugins list
150
  *
151
- * @since 1.0
152
  */
153
  function superpwa_plugin_row_meta( $links, $file ) {
154
 
155
  if ( strpos( $file, 'superpwa.php' ) !== false ) {
156
  $new_links = array(
157
- 'demo' => '<a href="https://superpwa.com" target="_blank">Demo</a>',
158
  );
159
  $links = array_merge( $links, $new_links );
160
  }
161
 
162
  return $links;
163
  }
164
- // add_filter( 'plugin_row_meta', 'superpwa_plugin_row_meta', 10, 2 ); // Todo: To be added once demo website is ready
165
-
166
- /**
167
- * Admin footer text
168
- *
169
- * A function to add footer text to the settings page of the plugin.
170
- * @since 1.2
171
- * @refer https://codex.wordpress.org/Function_Reference/get_current_screen
172
- */
173
- function superpwa_footer_text( $default ) {
174
-
175
- // Retun default on non-plugin pages
176
- $screen = get_current_screen();
177
- if ( $screen->id !== "settings_page_superpwa" ) {
178
- return $default;
179
- }
180
-
181
- $superpwa_footer_text = sprintf( __( 'If you like our plugin, please <a href="%s" target="_blank">make a donation</a> or leave a <a href="%s" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> rating to support continued development. Thanks a bunch!', 'super-progressive-web-apps' ),
182
- 'https://millionclues.com/donate/',
183
- 'https://wordpress.org/support/plugin/super-progressive-web-apps/reviews/?rate=5#new-post'
184
- );
185
-
186
- return $superpwa_footer_text;
187
- }
188
- add_filter('admin_footer_text', 'superpwa_footer_text');
189
-
190
- /**
191
- * Admin footer version
192
- *
193
- * @since 1.0
194
- */
195
- function superpwa_footer_version($default) {
196
-
197
- // Retun default on non-plugin pages
198
- $screen = get_current_screen();
199
- if ( $screen->id !== "settings_page_superpwa" ) {
200
- return $default;
201
- }
202
-
203
- return 'SuperPWA ' . SUPERPWA_VERSION;
204
- }
205
- add_filter( 'update_footer', 'superpwa_footer_version', 11 );
3
  * Basic setup functions for the plugin
4
  *
5
  * @since 1.0
6
+ *
7
  * @function superpwa_activate_plugin() Plugin activatation todo list
8
  * @function superpwa_admin_notice_activation() Admin notice on plugin activation
9
+ * @function superpwa_network_admin_notice_activation() Admin notice on multisite network activation
10
  * @function superpwa_upgrader() Plugin upgrade todo list
11
+ * @function superpwa_deactivate_plugin() Plugin deactivation todo list
12
  * @function superpwa_load_plugin_textdomain() Load plugin text domain
13
  * @function superpwa_settings_link() Print direct link to plugin settings in plugins list in admin
14
  * @function superpwa_plugin_row_meta() Add donate and other links to plugins list
 
 
15
  */
16
 
17
  // Exit if accessed directly
20
  /**
21
  * Plugin activatation todo list
22
  *
23
+ * This function runs when user activates the plugin. Used in register_activation_hook()
24
+ * On multisites, during network activation, this is fired only for the main site.
25
+ * For the rest of the sites, superpwa_upgrader() handles generation of manifest and service worker.
26
+ *
27
+ * @param $network_active (Boolean) True if the plugin is network activated, false otherwise.
28
+ * @link https://www.alexgeorgiou.gr/network-activated-wordpress-plugins/ (Thanks Alex!)
29
+ *
30
+ * @since 1.0
31
+ * @since 1.6 register_activation_hook() moved to this file (basic-setup.php) from main plugin file (superpwa.php).
32
+ * @since 1.6 Added checks for multisite compatibility.
33
  */
34
+ function superpwa_activate_plugin( $network_active ) {
35
 
36
  // Generate manifest with default options
37
  superpwa_generate_manifest();
39
  // Generate service worker
40
  superpwa_generate_sw();
41
 
42
+ // Not network active i.e. plugin is activated on a single install (normal WordPress install) or a single site on a multisite network
43
+ if ( ! $network_active ) {
44
+
45
+ // Set transient for single site activation notice
46
+ set_transient( 'superpwa_admin_notice_activation', true, 5 );
47
+
48
+ return;
49
+ }
50
+
51
+ // If we are here, then plugin is network activated on a multisite. Set transient for activation notice on network admin.
52
+ set_transient( 'superpwa_network_admin_notice_activation', true, 5 );
53
  }
54
+ register_activation_hook( SUPERPWA_PATH_ABS . 'superpwa.php', 'superpwa_activate_plugin' );
55
 
56
  /**
57
  * Admin notice on plugin activation
58
  *
59
+ * @since 1.2
60
  */
61
  function superpwa_admin_notice_activation() {
62
 
65
  return;
66
  }
67
 
68
+ $superpwa_is_ready = is_ssl() && superpwa_get_contents( superpwa_manifest( 'abs' ) ) && superpwa_get_contents( superpwa_sw( 'abs' ) ) && ( ! superpwa_onesignal_manifest_notice_check() ) ? 'Your app is ready with the default settings. ' : '';
69
 
70
  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( 'options-general.php?page=superpwa' ) ) . '</p></div>';
71
 
74
  }
75
  add_action( 'admin_notices', 'superpwa_admin_notice_activation' );
76
 
77
+ /**
78
+ * Admin notice on multisite network activation
79
+ *
80
+ * @since 1.6
81
+ */
82
+ function superpwa_network_admin_notice_activation() {
83
+
84
+ // Return if transient is not set
85
+ if ( ! get_transient( 'superpwa_network_admin_notice_activation' ) ) {
86
+ return;
87
+ }
88
+
89
+ $superpwa_is_ready = is_ssl() && superpwa_get_contents( superpwa_manifest( 'abs' ) ) && superpwa_get_contents( superpwa_sw( 'abs' ) ) && ( ! superpwa_onesignal_manifest_notice_check() ) ? 'Your app is ready on the main website with the default settings. ' : '';
90
+
91
+ 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( 'options-general.php?page=superpwa' ) ) . '</p></div>';
92
+
93
+ // Delete transient
94
+ delete_transient( 'superpwa_network_admin_notice_activation' );
95
+ }
96
+ add_action( 'network_admin_notices', 'superpwa_network_admin_notice_activation' );
97
+
98
  /**
99
  * Plugin upgrade todo list
100
  *
101
+ * @since 1.3.1
102
+ * @since 1.4 Added orientation setting and theme_color to database when upgrading from pre 1.4 versions.
103
+ * @since 1.6 Added multisite compatibility.
104
  */
105
  function superpwa_upgrader() {
106
 
107
+ $current_ver = get_option( 'superpwa_version' );
108
 
109
  // Return if we have already done this todo
110
+ if ( version_compare( $current_ver, SUPERPWA_VERSION, '==' ) ) {
111
  return;
112
+ }
113
 
114
+ /**
115
+ * Return if this is the first time the plugin is installed.
116
+ *
117
+ * On a multisite, during network activation, the activation hook (and activation todo) is not fired.
118
+ * Manifest and service worker is generated the first time the wp-admin is loaded (when admin_init is fired).
119
+ */
120
  if ( $current_ver === false ) {
121
 
122
+ if ( is_multisite() ) {
123
+
124
+ // Generate manifestx
125
+ superpwa_generate_manifest();
126
+
127
+ // Generate service worker
128
+ superpwa_generate_sw();
129
+
130
+ // For multisites, save the activation status of current blog.
131
+ superpwa_multisite_activation_status( true );
132
+ }
133
+
134
+ // Save SuperPWA version to database.
135
  add_option( 'superpwa_version', SUPERPWA_VERSION );
136
+
137
  return;
138
  }
139
 
140
+ /**
141
+ * Add orientation and theme_color to database when upgrading from pre 1.4 versions
142
+ *
143
+ * Until 1.4, there was no UI for orientation and theme_color.
144
+ * In the manifest, orientation was hard coded as 'natural'.
145
+ * background_color had UI and this value was used for both background_color and theme_color in the manifest.
146
+ */
147
+ if ( version_compare( $current_ver, '1.4', '<' ) ) {
148
 
149
  // Get settings
150
  $settings = superpwa_get_settings();
167
 
168
  // Add current version to database
169
  update_option( 'superpwa_version', SUPERPWA_VERSION );
170
+
171
+ // For multisites, save the activation status of current blog.
172
+ superpwa_multisite_activation_status( true );
173
  }
174
  add_action( 'admin_init', 'superpwa_upgrader' );
175
 
176
  /**
177
  * Plugin deactivation todo list
178
  *
179
+ * Runs during deactivation.
180
+ * During uninstall uninstall.php is also executed.
181
+ *
182
+ * @param $network_active (Boolean) True if the plugin is network activated, false otherwise.
183
+ * @link https://www.alexgeorgiou.gr/network-activated-wordpress-plugins/ (Thanks Alex!)
184
+ *
185
+ * @since 1.0
186
+ * @since 1.6 register_deactivation_hook() moved to this file (basic-setup.php) from main plugin file (superpwa.php)
187
  */
188
+ function superpwa_deactivate_plugin( $network_active ) {
189
 
190
  // Delete manifest
191
  superpwa_delete_manifest();
192
 
193
  // Delete service worker
194
  superpwa_delete_sw();
195
+
196
+ // For multisites, save the de-activation status of current blog.
197
+ superpwa_multisite_activation_status( false );
198
+
199
+ // Run the network deactivator during network deactivation
200
+ if ( $network_active === true ) {
201
+ superpwa_multisite_network_deactivator();
202
+ }
203
  }
204
+ register_deactivation_hook( SUPERPWA_PATH_ABS . 'superpwa.php', 'superpwa_deactivate_plugin' );
205
 
206
  /**
207
  * Load plugin text domain
208
  *
209
+ * @since 1.0
210
  */
211
  function superpwa_load_plugin_textdomain() {
212
 
217
  /**
218
  * Print direct link to plugin settings in plugins list in admin
219
  *
220
+ * @since 1.0
221
  */
222
  function superpwa_settings_link( $links ) {
223
 
233
  /**
234
  * Add donate and other links to plugins list
235
  *
236
+ * @since 1.0
237
  */
238
  function superpwa_plugin_row_meta( $links, $file ) {
239
 
240
  if ( strpos( $file, 'superpwa.php' ) !== false ) {
241
  $new_links = array(
242
+ 'demo' => '<a href="https://superpwa.com" target="_blank">' . __( 'Demo', 'super-progressive-web-apps' ) . '</a>',
243
  );
244
  $links = array_merge( $links, $new_links );
245
  }
246
 
247
  return $links;
248
  }
249
+ add_filter( 'plugin_row_meta', 'superpwa_plugin_row_meta', 10, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/do.php DELETED
@@ -1,128 +0,0 @@
1
- <?php
2
- /**
3
- * Operations and common functions of SuperPWA
4
- *
5
- * @since 1.0
6
- * @function superpwa_after_save_settings_todo() Todo list after saving admin options
7
- * @function superpwa_is_amp() Check if any AMP plugin is installed
8
- * @function superpwa_get_start_url() Return Start Page URL
9
- * @function superpwa_onesignal_manifest_notice_check() Check if OneSignal integration notice should be displayed or not.
10
- */
11
-
12
- // Exit if accessed directly
13
- if ( ! defined('ABSPATH') ) exit;
14
-
15
- /**
16
- * Todo list after saving admin options
17
- *
18
- * Regenerate manifest
19
- * Regenerate service worker
20
- *
21
- * @since 1.0
22
- */
23
- function superpwa_after_save_settings_todo() {
24
-
25
- // Regenerate manifest
26
- superpwa_generate_manifest();
27
-
28
- // Regenerate service worker
29
- superpwa_generate_sw();
30
- }
31
- add_action( 'add_option_superpwa_settings', 'superpwa_after_save_settings_todo' );
32
- add_action( 'update_option_superpwa_settings', 'superpwa_after_save_settings_todo' );
33
-
34
- /**
35
- * Check if any AMP plugin is installed
36
- *
37
- * @return String|Bool AMP page url on success, false otherwise
38
- * @since 1.2
39
- */
40
- function superpwa_is_amp() {
41
-
42
- // AMP for WordPress - https://wordpress.org/plugins/amp
43
- if ( function_exists( 'amp_init' ) ) {
44
- return defined( 'AMP_QUERY_VAR' ) ? AMP_QUERY_VAR . '/' : 'amp/';
45
- }
46
-
47
- // AMP for WP - https://wordpress.org/plugins/accelerated-mobile-pages/
48
- if ( function_exists( 'ampforwp_generate_endpoint' ) ) {
49
- return defined( 'AMPFORWP_AMP_QUERY_VAR' ) ? AMPFORWP_AMP_QUERY_VAR . '/' : 'amp/';
50
- }
51
-
52
- // Better AMP � https://wordpress.org/plugins/better-amp/
53
- if ( class_exists( 'Better_AMP' ) ) {
54
- return 'amp/';
55
- }
56
-
57
- // AMP Supremacy - https://wordpress.org/plugins/amp-supremacy/
58
- if ( class_exists( 'AMP_Init' ) ) {
59
- return 'amp/';
60
- }
61
-
62
- // WP AMP - https://wordpress.org/plugins/wp-amp-ninja/
63
- if ( function_exists( 'wpamp_init' ) ) {
64
- return '?wpamp';
65
- }
66
-
67
- return false;
68
- }
69
-
70
- /**
71
- * Return Start Page URL
72
- *
73
- * @param $rel False by default. Set to true to return a relative URL (for use in manifest)
74
- * @return String URL to be set as the start_url in manifest and startPage in service worker
75
- *
76
- * @since 1.2
77
- * @since 1.3.1 Force HTTPS by replacing http:// with https://
78
- */
79
- function superpwa_get_start_url( $rel = false ) {
80
-
81
- // Get Settings
82
- $settings = superpwa_get_settings();
83
-
84
- // Start Page
85
- $start_url = get_permalink( $settings['start_url'] ) ? trailingslashit( get_permalink( $settings['start_url'] ) ) : trailingslashit( get_bloginfo( 'wpurl' ) );
86
-
87
- // Force HTTPS
88
- $start_url = str_replace( 'http://', 'https://', $start_url );
89
-
90
- if ( $rel === true ) {
91
-
92
- // Make start_url relative for manifest
93
- $start_url = parse_url( $start_url, PHP_URL_PATH );
94
- }
95
-
96
- // AMP URL
97
- $amp_url = superpwa_is_amp() !== false && ( isset( $settings['start_url_amp'] ) && $settings['start_url_amp'] == 1 ) ? superpwa_is_amp() : '';
98
-
99
- return $start_url . $amp_url;
100
- }
101
-
102
- /**
103
- * Check if OneSignal integration notice should be displayed or not.
104
- *
105
- * @return Bool True if notice should be displayed. False otherwise.
106
- * @since 1.5
107
- */
108
- function superpwa_onesignal_manifest_notice_check() {
109
-
110
- // No notice needed if OneSignal is not installed or there is no gcm_sender_id
111
- if ( ! superpwa_onesignal_get_gcm_sender_id() ) {
112
- return false;
113
- }
114
-
115
- // Get OneSignal settins
116
- $onesignal_wp_settings = get_option( 'OneSignalWPSetting' );
117
-
118
- // No notice needed if OneSignal custom manifest is enabled and the manifest is the SuperPWA manifest
119
- if (
120
- ( isset( $onesignal_wp_settings["use_custom_manifest"] ) ) && ( $onesignal_wp_settings["use_custom_manifest"] == 1 ) &&
121
- ( isset( $onesignal_wp_settings["custom_manifest_url"] ) ) && ( strcasecmp( trim( $onesignal_wp_settings["custom_manifest_url"] ), SUPERPWA_MANIFEST_SRC ) == 0 )
122
- ) {
123
- return false;
124
- }
125
-
126
- // Display notice for every other case
127
- return true;
128
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/loader.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
- /**
3
- * Loads the plugin files
4
- *
5
- * @since 1.0
6
- */
7
-
8
- // Exit if accessed directly
9
- if ( ! defined('ABSPATH') ) exit;
10
-
11
- // Load basic setup. Plugin list links, text domain, footer links etc.
12
- require_once( SUPERPWA_PATH_ABS . 'admin/basic-setup.php');
13
-
14
- // Load admin setup. Register menus and settings
15
- require_once( SUPERPWA_PATH_ABS . 'admin/admin-setup.php');
16
-
17
- // Render Admin UI
18
- require_once( SUPERPWA_PATH_ABS . 'admin/admin-ui-render.php');
19
-
20
- // Load Filesystem functions
21
- require_once( SUPERPWA_PATH_ABS . 'admin/filesystem.php');
22
-
23
- // Manifest Functions
24
- require_once( SUPERPWA_PATH_ABS . 'public/manifest.php');
25
-
26
- // Service Worker Functions
27
- require_once( SUPERPWA_PATH_ABS . 'public/sw.php');
28
-
29
- // Do plugin operations
30
- require_once( SUPERPWA_PATH_ABS . 'admin/do.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
functions/common.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Operations and common functions of SuperPWA
4
+ *
5
+ * @since 1.0
6
+ * @function superpwa_is_amp() Check if any AMP plugin is installed
7
+ * @function superpwa_get_start_url() Return Start Page URL
8
+ * @function superpwa_httpsify() Convert http URL to https
9
+ */
10
+
11
+ // Exit if accessed directly
12
+ if ( ! defined( 'ABSPATH' ) ) exit;
13
+
14
+ /**
15
+ * Check if any AMP plugin is installed
16
+ *
17
+ * @return String|Bool AMP page url on success, false otherwise
18
+ * @since 1.2
19
+ */
20
+ function superpwa_is_amp() {
21
+
22
+ // AMP for WordPress - https://wordpress.org/plugins/amp
23
+ if ( function_exists( 'amp_init' ) ) {
24
+ return defined( 'AMP_QUERY_VAR' ) ? AMP_QUERY_VAR . '/' : 'amp/';
25
+ }
26
+
27
+ // AMP for WP - https://wordpress.org/plugins/accelerated-mobile-pages/
28
+ if ( function_exists( 'ampforwp_generate_endpoint' ) ) {
29
+ return defined( 'AMPFORWP_AMP_QUERY_VAR' ) ? AMPFORWP_AMP_QUERY_VAR . '/' : 'amp/';
30
+ }
31
+
32
+ // Better AMP � https://wordpress.org/plugins/better-amp/
33
+ if ( class_exists( 'Better_AMP' ) ) {
34
+ return 'amp/';
35
+ }
36
+
37
+ // AMP Supremacy - https://wordpress.org/plugins/amp-supremacy/
38
+ if ( class_exists( 'AMP_Init' ) ) {
39
+ return 'amp/';
40
+ }
41
+
42
+ // WP AMP - https://wordpress.org/plugins/wp-amp-ninja/
43
+ if ( function_exists( 'wpamp_init' ) ) {
44
+ return '?wpamp';
45
+ }
46
+
47
+ return false;
48
+ }
49
+
50
+ /**
51
+ * Return Start Page URL
52
+ *
53
+ * @param $rel False by default. Set to true to return a relative URL (for use in manifest)
54
+ * @return String URL to be set as the start_url in manifest and startPage in service worker
55
+ *
56
+ * @since 1.2
57
+ * @since 1.3.1 Force HTTPS by replacing http:// with https://
58
+ * @since 1.6 Use superpwa_httpsify() to force HTTPS.
59
+ * @since 1.6 Removed forcing of trailing slash and added dot (.) to the beginning.
60
+ */
61
+ function superpwa_get_start_url( $rel = false ) {
62
+
63
+ // Get Settings
64
+ $settings = superpwa_get_settings();
65
+
66
+ // Start Page
67
+ $start_url = get_permalink( $settings['start_url'] ) ? get_permalink( $settings['start_url'] ) : get_bloginfo( 'wpurl' );
68
+
69
+ // Force HTTPS
70
+ $start_url = superpwa_httpsify( $start_url );
71
+
72
+ if ( $rel === true ) {
73
+
74
+ // Make start_url relative for manifest
75
+ $start_url = '.' . parse_url( $start_url, PHP_URL_PATH );
76
+ }
77
+
78
+ // AMP URL
79
+ if ( superpwa_is_amp() !== false && isset( $settings['start_url_amp'] ) && $settings['start_url_amp'] == 1 ) {
80
+ $start_url = trailingslashit( $start_url ) . superpwa_is_amp();
81
+ }
82
+
83
+ return $start_url;
84
+ }
85
+
86
+ /**
87
+ * Convert http URL to https
88
+ *
89
+ * @param $url String The URL to convert to https
90
+ * @return String Returns the converted URL
91
+ *
92
+ * @since 1.6
93
+ */
94
+ function superpwa_httpsify( $url ) {
95
+ return str_replace( 'http://', 'https://', $url );
96
+ }
{admin → functions}/filesystem.php RENAMED
File without changes
functions/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden
functions/multisite.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Functions for compatibility with WordPress multisites
4
+ *
5
+ * @since 1.6
6
+ *
7
+ * @function superpwa_multisite_filename_postfix() Filename postfix for multisites
8
+ * @function superpwa_multisite_activation_status() Save activation status for current blog id
9
+ * @function superpwa_multisite_network_deactivator() Handle multisite network deactivation
10
+ */
11
+
12
+ // Exit if accessed directly
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ /**
16
+ * Filename postfix for multisites
17
+ *
18
+ * @return (string) Returns the current blog ID on a multisite. An empty string otherwise
19
+ *
20
+ * @since 1.6
21
+ */
22
+ function superpwa_multisite_filename_postfix() {
23
+
24
+ // Return empty string if not a multisite
25
+ if ( ! is_multisite() ) {
26
+ return '';
27
+ }
28
+
29
+ return '-' . get_current_blog_id();
30
+ }
31
+
32
+ /**
33
+ * Save activation status for current blog id
34
+ *
35
+ * For clean multisite uninstall.
36
+ * Manifest and service worker are deleted during deactivation.
37
+ * Database settings are cleaned during uninstall
38
+ *
39
+ * @param (bool) $status True when plugin is activated, false when deactivated.
40
+ *
41
+ * @since 1.6
42
+ */
43
+ function superpwa_multisite_activation_status( $status ) {
44
+
45
+ // Only for multisites
46
+ if ( ! is_multisite() || ! isset( $status ) ) {
47
+ return;
48
+ }
49
+
50
+ // Get current list of sites where SuperPWA is activated.
51
+ $superpwa_sites = get_site_option( 'superpwa_active_sites', array() );
52
+
53
+ // Set the status for the current blog.
54
+ $superpwa_sites[ get_current_blog_id() ] = $status;
55
+
56
+ // Save it back to the database.
57
+ update_site_option( 'superpwa_active_sites', $superpwa_sites );
58
+ }
59
+
60
+ /**
61
+ * Handle multisite network deactivation
62
+ *
63
+ * Deletes manifest and service worker of all sub-sites.
64
+ * Sets the deactivation status for each site.
65
+ *
66
+ * Not used when wp_is_large_network() is true. Deleting that many files and db options will most likely time out.
67
+ * This also this gives the user an option to decide if SuperPWA should handle this by changing the defenition of wp_is_large_network.
68
+ * @link https://developer.wordpress.org/reference/functions/wp_is_large_network/
69
+ */
70
+ function superpwa_multisite_network_deactivator() {
71
+
72
+ // Do not run on large networks
73
+ if ( wp_is_large_network() ) {
74
+ return;
75
+ }
76
+
77
+ // Retrieve the list of blog ids where SuperPWA is active. (saved with blog_id as $key and activation_status as $value)
78
+ $superpwa_sites = get_site_option( 'superpwa_active_sites' );
79
+
80
+ // Loop through each active site.
81
+ foreach( $superpwa_sites as $blog_id => $actviation_status ) {
82
+
83
+ // Switch to each blog
84
+ switch_to_blog( $blog_id );
85
+
86
+ // Delete manifest
87
+ superpwa_delete_manifest();
88
+
89
+ // Delete service worker
90
+ superpwa_delete_sw();
91
+
92
+ /**
93
+ * Delete SuperPWA version info for current blog.
94
+ *
95
+ * This is required so that superpwa_upgrader() will run and create the manifest and service worker on next activation.
96
+ * Known edge case: Database upgrade that relies on the version number will fail if user deactivates and later activates after SuperPWA is updated.
97
+ */
98
+ delete_option( 'superpwa_version' );
99
+
100
+ // Save the de-activation status of current blog.
101
+ superpwa_multisite_activation_status( false );
102
+
103
+ // Return to main site
104
+ restore_current_blog();
105
+ }
106
+ }
languages/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden
loader.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Loads the plugin files
4
+ *
5
+ * @since 1.0
6
+ */
7
+
8
+ // Exit if accessed directly
9
+ if ( ! defined('ABSPATH') ) exit;
10
+
11
+ // Load admin
12
+ require_once( SUPERPWA_PATH_ABS . 'admin/basic-setup.php' );
13
+ require_once( SUPERPWA_PATH_ABS . 'admin/admin-setup.php' );
14
+ require_once( SUPERPWA_PATH_ABS . 'admin/admin-ui-render.php' );
15
+
16
+ // 3rd party compatibility
17
+ require_once( SUPERPWA_PATH_ABS . '3rd-party/onesignal.php' );
18
+
19
+ // Load functions
20
+ require_once( SUPERPWA_PATH_ABS . 'functions/common.php' );
21
+ require_once( SUPERPWA_PATH_ABS . 'functions/filesystem.php' );
22
+ require_once( SUPERPWA_PATH_ABS . 'functions/multisite.php' );
23
+
24
+ // Public folder
25
+ require_once( SUPERPWA_PATH_ABS . 'public/manifest.php' );
26
+ require_once( SUPERPWA_PATH_ABS . 'public/sw.php' );
public/images/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden
public/js/index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ // Silence is golden
public/manifest.php CHANGED
@@ -3,6 +3,7 @@
3
  * Manifest related functions of SuperPWA
4
  *
5
  * @since 1.0
 
6
  * @function superpwa_generate_manifest() Generate and write manifest
7
  * @function superpwa_add_manifest_to_wp_head() Add manifest to header (wp_head)
8
  * @function superpwa_register_service_worker() Register service worker in the footer (wp_footer)
@@ -10,11 +11,47 @@
10
  * @function superpwa_get_pwa_icons() Get PWA Icons
11
  * @function superpwa_get_scope() Get navigation scope of PWA
12
  * @function superpwa_get_orientation() Get orientation of PWA
13
- * @function superpwa_onesignal_get_gcm_sender_id() Extract gcm_sender_id from OneSignal settings
14
  */
15
 
16
  // Exit if accessed directly
17
- if ( ! defined('ABSPATH') ) exit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  /**
20
  * Generate and write manifest into WordPress root folder
@@ -24,34 +61,41 @@ if ( ! defined('ABSPATH') ) exit;
24
  * @since 1.3 Added support for 512x512 icon.
25
  * @since 1.4 Added orientation and scope.
26
  * @since 1.5 Added gcm_sender_id
 
27
  */
28
  function superpwa_generate_manifest() {
29
 
30
  // Get Settings
31
  $settings = superpwa_get_settings();
32
 
33
- $manifest = array(
34
- 'name' => $settings['app_name'],
35
- 'short_name' => $settings['app_short_name'],
36
- 'icons' => superpwa_get_pwa_icons(),
37
- 'background_color' => $settings['background_color'],
38
- 'theme_color' => $settings['theme_color'],
39
- 'display' => 'standalone',
40
- 'orientation' => superpwa_get_orientation(),
41
- 'start_url' => superpwa_get_start_url( true ),
42
- 'scope' => superpwa_get_scope(),
43
- );
 
 
 
 
 
44
 
45
  // gcm_sender_id
46
  if ( superpwa_onesignal_get_gcm_sender_id() !== false ) {
47
- $manifest['gcm_sender_id'] = superpwa_onesignal_get_gcm_sender_id();
48
  }
49
 
50
  // Delete manifest if it exists
51
  superpwa_delete_manifest();
52
 
53
- if ( ! superpwa_put_contents( SUPERPWA_MANIFEST_ABS, json_encode( $manifest ) ) )
54
  return false;
 
55
 
56
  return true;
57
  }
@@ -66,10 +110,10 @@ function superpwa_add_manifest_to_wp_head() {
66
  // Get Settings
67
  $settings = superpwa_get_settings();
68
 
69
- echo '<!-- Manifest added by SuperPWA -->' . PHP_EOL . '<link rel="manifest" href="'. SUPERPWA_MANIFEST_SRC . '">' . PHP_EOL;
70
  echo '<meta name="theme-color" content="'. $settings['theme_color'] .'">' . PHP_EOL;
71
  }
72
- add_action( 'wp_head', 'superpwa_add_manifest_to_wp_head', 2 );
73
 
74
  /**
75
  * Delete manifest
@@ -78,8 +122,7 @@ add_action( 'wp_head', 'superpwa_add_manifest_to_wp_head', 2 );
78
  * @since 1.0
79
  */
80
  function superpwa_delete_manifest() {
81
-
82
- return superpwa_delete( SUPERPWA_MANIFEST_ABS );
83
  }
84
 
85
  /**
@@ -101,11 +144,11 @@ function superpwa_get_pwa_icons() {
101
  );
102
 
103
  // Splash screen icon - Added since 1.3
104
- if ( @$settings['splash_icon'] != null ) {
105
 
106
  $icons_array[] = array(
107
  'src' => $settings['splash_icon'],
108
- 'sizes' => '512x512', // must be 192x192.
109
  'type' => 'image/png', // must be image/png
110
  );
111
  }
@@ -120,7 +163,6 @@ function superpwa_get_pwa_icons() {
120
  * @since 1.4
121
  */
122
  function superpwa_get_scope() {
123
-
124
  return parse_url( trailingslashit( get_bloginfo( 'wpurl' ) ), PHP_URL_PATH );
125
  }
126
 
@@ -154,28 +196,4 @@ function superpwa_get_orientation() {
154
  default:
155
  return 'any';
156
  }
157
- }
158
-
159
- /**
160
- * Extract gcm_sender_id from OneSignal settings
161
- *
162
- * @link https://wordpress.org/plugins/onesignal-free-web-push-notifications/
163
- *
164
- * @return String|Bool gcm_sender_id if it exists, false otherwise
165
- * @since 1.5
166
- */
167
- function superpwa_onesignal_get_gcm_sender_id() {
168
-
169
- // If OneSignal is installed and active
170
- if ( class_exists( 'OneSignal' ) ) {
171
-
172
- // Get OneSignal settins
173
- $onesignal_wp_settings = get_option( 'OneSignalWPSetting' );
174
-
175
- if ( isset( $onesignal_wp_settings['gcm_sender_id'] ) && ( $onesignal_wp_settings['gcm_sender_id'] != '' ) ) {
176
- return $onesignal_wp_settings['gcm_sender_id'];
177
- }
178
- }
179
-
180
- return false;
181
  }
3
  * Manifest related functions of SuperPWA
4
  *
5
  * @since 1.0
6
+ * @function superpwa_manifest() Manifest filename, absolute path and link
7
  * @function superpwa_generate_manifest() Generate and write manifest
8
  * @function superpwa_add_manifest_to_wp_head() Add manifest to header (wp_head)
9
  * @function superpwa_register_service_worker() Register service worker in the footer (wp_footer)
11
  * @function superpwa_get_pwa_icons() Get PWA Icons
12
  * @function superpwa_get_scope() Get navigation scope of PWA
13
  * @function superpwa_get_orientation() Get orientation of PWA
 
14
  */
15
 
16
  // Exit if accessed directly
17
+ if ( ! defined( 'ABSPATH' ) ) exit;
18
+
19
+ /**
20
+ * Manifest filename, absolute path and link
21
+ *
22
+ * For Multisite compatibility. Used to be constants defined in superpwa.php
23
+ * On a multisite, each sub-site needs a different manifest file.
24
+ *
25
+ * @param $arg filename for manifest filename (replaces SUPERPWA_MANIFEST_FILENAME)
26
+ * abs for absolute path to manifest (replaces SUPERPWA_MANIFEST_ABS)
27
+ * src for link to manifest (replaces SUPERPWA_MANIFEST_SRC). Default value
28
+ *
29
+ * @return String filename, absolute path or link to manifest.
30
+ * @since 1.6
31
+ */
32
+ function superpwa_manifest( $arg = 'src' ) {
33
+
34
+ $manifest_filename = 'superpwa-manifest' . superpwa_multisite_filename_postfix() . '.json';
35
+
36
+ switch( $arg ) {
37
+
38
+ // Name of Manifest file
39
+ case 'filename':
40
+ return $manifest_filename;
41
+ break;
42
+
43
+ // Absolute path to manifest
44
+ case 'abs':
45
+ return trailingslashit( ABSPATH ) . $manifest_filename;
46
+ break;
47
+
48
+ // Link to manifest
49
+ case 'src':
50
+ default:
51
+ return trailingslashit( network_home_url() ) . $manifest_filename;
52
+ break;
53
+ }
54
+ }
55
 
56
  /**
57
  * Generate and write manifest into WordPress root folder
61
  * @since 1.3 Added support for 512x512 icon.
62
  * @since 1.4 Added orientation and scope.
63
  * @since 1.5 Added gcm_sender_id
64
+ * @since 1.6 Added description
65
  */
66
  function superpwa_generate_manifest() {
67
 
68
  // Get Settings
69
  $settings = superpwa_get_settings();
70
 
71
+ $manifest = array();
72
+ $manifest['name'] = $settings['app_name'];
73
+ $manifest['short_name'] = $settings['app_short_name'];
74
+
75
+ // description
76
+ if ( isset( $settings['description'] ) && ! empty( $settings['description'] ) ) {
77
+ $manifest['description'] = $settings['description'];
78
+ }
79
+
80
+ $manifest['icons'] = superpwa_get_pwa_icons();
81
+ $manifest['background_color'] = $settings['background_color'];
82
+ $manifest['theme_color'] = $settings['theme_color'];
83
+ $manifest['display'] = 'standalone';
84
+ $manifest['orientation'] = superpwa_get_orientation();
85
+ $manifest['start_url'] = superpwa_get_start_url( true );
86
+ $manifest['scope'] = superpwa_get_scope();
87
 
88
  // gcm_sender_id
89
  if ( superpwa_onesignal_get_gcm_sender_id() !== false ) {
90
+ $manifest['gcm_sender_id'] = superpwa_onesignal_get_gcm_sender_id();
91
  }
92
 
93
  // Delete manifest if it exists
94
  superpwa_delete_manifest();
95
 
96
+ if ( ! superpwa_put_contents( superpwa_manifest( 'abs' ), json_encode( $manifest ) ) ) {
97
  return false;
98
+ }
99
 
100
  return true;
101
  }
110
  // Get Settings
111
  $settings = superpwa_get_settings();
112
 
113
+ echo '<!-- Manifest added by SuperPWA -->' . PHP_EOL . '<link rel="manifest" href="'. parse_url( superpwa_manifest( 'src' ), PHP_URL_PATH ) . '">' . PHP_EOL;
114
  echo '<meta name="theme-color" content="'. $settings['theme_color'] .'">' . PHP_EOL;
115
  }
116
+ add_action( 'wp_head', 'superpwa_add_manifest_to_wp_head', 0 );
117
 
118
  /**
119
  * Delete manifest
122
  * @since 1.0
123
  */
124
  function superpwa_delete_manifest() {
125
+ return superpwa_delete( superpwa_manifest( 'abs' ) );
 
126
  }
127
 
128
  /**
144
  );
145
 
146
  // Splash screen icon - Added since 1.3
147
+ if ( @$settings['splash_icon'] != '' ) {
148
 
149
  $icons_array[] = array(
150
  'src' => $settings['splash_icon'],
151
+ 'sizes' => '512x512', // must be 512x512.
152
  'type' => 'image/png', // must be image/png
153
  );
154
  }
163
  * @since 1.4
164
  */
165
  function superpwa_get_scope() {
 
166
  return parse_url( trailingslashit( get_bloginfo( 'wpurl' ) ), PHP_URL_PATH );
167
  }
168
 
196
  default:
197
  return 'any';
198
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  }
public/sw.php CHANGED
@@ -3,14 +3,52 @@
3
  * Service worker related functions of SuperPWA
4
  *
5
  * @since 1.0
 
6
  * @function superpwa_generate_sw() Generate and write service worker into sw.js
7
- * @function superpwa_sw_template() Service Worker Tempalte
8
  * @function superpwa_register_sw() Register service worker
9
- * @function superpwa_delete_sw() Delete Service Worker
10
  */
11
 
12
  // Exit if accessed directly
13
- if ( ! defined('ABSPATH') ) exit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  /**
16
  * Generate and write service worker into superpwa-sw.js
@@ -29,8 +67,9 @@ function superpwa_generate_sw() {
29
  // Delete service worker if it exists
30
  superpwa_delete_sw();
31
 
32
- if ( ! superpwa_put_contents( SUPERPWA_SW_ABS, $sw ) )
33
  return false;
 
34
 
35
  return true;
36
  }
@@ -52,12 +91,12 @@ function superpwa_sw_template() {
52
 
53
  /**
54
  * Service Worker of SuperPWA
55
- * https://wordpress.org/plugins/super-progressive-web-apps/
56
  */
57
 
58
  const cacheName = '<?php echo parse_url( get_bloginfo( 'wpurl' ), PHP_URL_HOST ) . '-superpwa-' . SUPERPWA_VERSION; ?>';
59
  const startPage = '<?php echo superpwa_get_start_url(); ?>';
60
- const offlinePage = '<?php echo get_permalink($settings['offline_page']) ? trailingslashit(get_permalink($settings['offline_page'])) : trailingslashit(get_bloginfo( 'wpurl' )); ?>';
61
  const fallbackImage = '<?php echo $settings['icon']; ?>';
62
  const filesToCache = [startPage, offlinePage, fallbackImage];
63
  const neverCacheUrls = [/\/wp-admin/,/\/wp-login/,/preview=true/];
@@ -161,9 +200,9 @@ function checkNeverCacheList(url) {
161
  */
162
  function superpwa_register_sw() {
163
 
164
- wp_enqueue_script('superpwa-register-sw', SUPERPWA_PATH_SRC . 'public/js/register-sw.js', array(), null, true );
165
- wp_localize_script('superpwa-register-sw', 'superpwa_sw', array(
166
- 'url' => SUPERPWA_SW_SRC,
167
  )
168
  );
169
  }
@@ -176,6 +215,5 @@ add_action( 'wp_enqueue_scripts', 'superpwa_register_sw' );
176
  * @since 1.0
177
  */
178
  function superpwa_delete_sw() {
179
-
180
- return superpwa_delete( SUPERPWA_SW_ABS );
181
  }
3
  * Service worker related functions of SuperPWA
4
  *
5
  * @since 1.0
6
+ * @function superpwa_sw() Service worker filename, absolute path and link
7
  * @function superpwa_generate_sw() Generate and write service worker into sw.js
8
+ * @function superpwa_sw_template() Service worker tempalte
9
  * @function superpwa_register_sw() Register service worker
10
+ * @function superpwa_delete_sw() Delete service worker
11
  */
12
 
13
  // Exit if accessed directly
14
+ if ( ! defined( 'ABSPATH' ) ) exit;
15
+
16
+ /**
17
+ * Service worker filename, absolute path and link
18
+ *
19
+ * For Multisite compatibility. Used to be constants defined in superpwa.php
20
+ * On a multisite, each sub-site needs a different service worker.
21
+ *
22
+ * @param $arg filename for service worker filename (replaces SUPERPWA_SW_FILENAME)
23
+ * abs for absolute path to service worker (replaces SUPERPWA_SW_ABS)
24
+ * src for link to service worker (replaces SUPERPWA_SW_SRC). Default value
25
+ *
26
+ * @return String filename, absolute path or link to manifest.
27
+ * @since 1.6
28
+ */
29
+ function superpwa_sw( $arg = 'src' ) {
30
+
31
+ $sw_filename = 'superpwa-sw' . superpwa_multisite_filename_postfix() . '.js';
32
+
33
+ switch( $arg ) {
34
+
35
+ // Name of service worker file
36
+ case 'filename':
37
+ return $sw_filename;
38
+ break;
39
+
40
+ // Absolute path to service worker. SW must be in the root folder
41
+ case 'abs':
42
+ return trailingslashit( ABSPATH ) . $sw_filename;
43
+ break;
44
+
45
+ // Link to service worker
46
+ case 'src':
47
+ default:
48
+ return trailingslashit( network_home_url() ) . $sw_filename;
49
+ break;
50
+ }
51
+ }
52
 
53
  /**
54
  * Generate and write service worker into superpwa-sw.js
67
  // Delete service worker if it exists
68
  superpwa_delete_sw();
69
 
70
+ if ( ! superpwa_put_contents( superpwa_sw( 'abs' ), $sw ) ) {
71
  return false;
72
+ }
73
 
74
  return true;
75
  }
91
 
92
  /**
93
  * Service Worker of SuperPWA
94
+ * To learn more and add one to your website, visit - https://superpwa.com
95
  */
96
 
97
  const cacheName = '<?php echo parse_url( get_bloginfo( 'wpurl' ), PHP_URL_HOST ) . '-superpwa-' . SUPERPWA_VERSION; ?>';
98
  const startPage = '<?php echo superpwa_get_start_url(); ?>';
99
+ const offlinePage = '<?php echo get_permalink( $settings['offline_page'] ) ? superpwa_httpsify( get_permalink( $settings['offline_page'] ) ) : superpwa_httpsify( get_bloginfo( 'wpurl' ) ); ?>';
100
  const fallbackImage = '<?php echo $settings['icon']; ?>';
101
  const filesToCache = [startPage, offlinePage, fallbackImage];
102
  const neverCacheUrls = [/\/wp-admin/,/\/wp-login/,/preview=true/];
200
  */
201
  function superpwa_register_sw() {
202
 
203
+ wp_enqueue_script( 'superpwa-register-sw', SUPERPWA_PATH_SRC . 'public/js/register-sw.js', array(), null, true );
204
+ wp_localize_script( 'superpwa-register-sw', 'superpwa_sw', array(
205
+ 'url' => superpwa_sw( 'src' ),
206
  )
207
  );
208
  }
215
  * @since 1.0
216
  */
217
  function superpwa_delete_sw() {
218
+ return superpwa_delete( superpwa_sw( 'abs' ) );
 
219
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: arunbasillal, josevarghese, superpwa
3
  Donate link: http://millionclues.com/donate/
4
  Tags: pwa, progressive web apps, manifest, web manifest, android app, chrome app, add to homescreen, mobile web
5
  Requires at least: 3.5.0
6
- Tested up to: 4.9.3
7
  Requires PHP: 5.3
8
  Stable tag: trunk
9
  License: GPLv2 or later
@@ -50,6 +50,7 @@ Here are the current features of Super Progressive Web Apps:
50
  * New in version 1.4: You can now set the default orientation of your PWA. Choose from "any" (Follow Device Orientation), "Portrait" and "Landscape".
51
  * New in version 1.4: You can now set the theme_color property in the manifest.
52
  * New in version 1.5: OneSignal integration for Push notifications.
 
53
 
54
  **Upcoming features:**
55
 
@@ -144,6 +145,16 @@ PWA's require browsers with support for service workers and for iOS devices, sup
144
 
145
  == Changelog ==
146
 
 
 
 
 
 
 
 
 
 
 
147
  = 1.5 =
148
  * Date: 18.March.2018
149
  * New Feature: OneSignal integration for Push notifications.
@@ -199,6 +210,15 @@ PWA's require browsers with support for service workers and for iOS devices, sup
199
 
200
  == Upgrade Notice ==
201
 
 
 
 
 
 
 
 
 
 
202
  = 1.5 =
203
  * New Feature: OneSignal integration for Push notifications.
204
  * Enhancement: Moved manifest to the top of wp_head for easier detection by browsers.
3
  Donate link: http://millionclues.com/donate/
4
  Tags: pwa, progressive web apps, manifest, web manifest, android app, chrome app, add to homescreen, mobile web
5
  Requires at least: 3.5.0
6
+ Tested up to: 4.9.5
7
  Requires PHP: 5.3
8
  Stable tag: trunk
9
  License: GPLv2 or later
50
  * New in version 1.4: You can now set the default orientation of your PWA. Choose from "any" (Follow Device Orientation), "Portrait" and "Landscape".
51
  * New in version 1.4: You can now set the theme_color property in the manifest.
52
  * New in version 1.5: OneSignal integration for Push notifications.
53
+ * New in version 1.6: WordPress Multisite Network compatibility.
54
 
55
  **Upcoming features:**
56
 
145
 
146
  == Changelog ==
147
 
148
+ = 1.6 =
149
+ * Date: 23.April.2018
150
+ * New Feature: WordPress Multisite Network Compatibility. One of the most requested features for SuperPWA is now here! Thanks [@juslintek](https://wordpress.org/support/topic/add-manifest-json-support-for-multisite/#post-9998629) for doing a major share of the heavy lifting.
151
+ * New Feature: Added description to the manifest. You can now include a brief description of what your app is about.
152
+ * Enhancement: Moved manifest to the very top of wp_head for better compatibility with some browsers.
153
+ * Enhancement: Improved the file and folder naming, organization, and inline documentation for better readability.
154
+ * Enhancement: Force https:// on all assets and dependencies solving the problem of http:// URLs in manifest and service worker once and for all.
155
+ * Enhancement: Relative URL for manifest for out of the box compatibility with CDN's.
156
+ * Enhancement: Removed forcing of trailing slash on manifest and service worker URLs for better compatibility.
157
+
158
  = 1.5 =
159
  * Date: 18.March.2018
160
  * New Feature: OneSignal integration for Push notifications.
210
 
211
  == Upgrade Notice ==
212
 
213
+ = 1.6 =
214
+ * New Feature: WordPress Multisite Network Compatibility. One of the most requested features for SuperPWA is now here! Thanks [@juslintek](https://wordpress.org/support/topic/add-manifest-json-support-for-multisite/#post-9998629) for doing a major share of the heavy lifting.
215
+ * New Feature: Added description to the manifest. You can now include a brief description of what your app is about.
216
+ * Enhancement: Moved manifest to the very top of wp_head for better compatibility with some browsers.
217
+ * Enhancement: Improved the file and folder naming, organization, and inline documentation for better readability.
218
+ * Enhancement: Force https:// on all assets and dependencies solving the problem of http:// URLs in manifest and service worker once and for all.
219
+ * Enhancement: Relative URL for manifest for out of the box compatibility with CDN's.
220
+ * Enhancement: Removed forcing of trailing slash on manifest and service worker URLs for better compatibility.
221
+
222
  = 1.5 =
223
  * New Feature: OneSignal integration for Push notifications.
224
  * Enhancement: Moved manifest to the top of wp_head for easier detection by browsers.
superpwa.php CHANGED
@@ -1,37 +1,38 @@
1
  <?php
2
  /**
3
  * Plugin Name: Super Progressive Web Apps
4
- * Plugin URI: https://superpwa.com/
5
  * Description: Convert your WordPress website into a Progressive Web App
6
  * Author: SuperPWA
7
- * Author URI: https://superpwa.com/
8
  * Contributors: Arun Basil Lal, Jose Varghese
9
- * Version: 1.5
10
  * Text Domain: super-progressive-web-apps
11
  * Domain Path: /languages
12
  * License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
13
  */
14
 
15
- /**
16
- * This plugin was developed using the WordPress starter plugin template by Arun Basil Lal <arunbasillal@gmail.com>
17
- * Please leave this credit and the directory structure intact for future developers who might read the code.
18
- * @Github https://github.com/arunbasillal/WordPress-Starter-Plugin
19
- */
20
-
21
  /**
22
  * ~ Directory Structure ~
23
  *
24
- * /admin/ - Plugin backend stuff.
 
 
 
 
 
25
  * /includes/ - External third party classes and libraries.
26
  * /languages/ - Translation files go here.
27
  * /public/ - Front end files go here.
28
  * index.php - Dummy file.
29
  * license.txt - GPL v2
30
- * superpwa.php - File containing plugin name and other version info for WordPress.
31
- * readme.txt - Readme for WordPress plugin repository. https://wordpress.org/plugins/files/2017/03/readme.txt
 
 
32
  * uninstall.php - Fired when the plugin is uninstalled.
33
  */
34
-
35
  /**
36
  * ~ Release TODO ~
37
  *
@@ -45,23 +46,13 @@ if ( ! defined('ABSPATH') ) exit;
45
  /**
46
  * Define constants
47
  *
48
- * @since 1.0
 
 
49
  */
50
- 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/superpwa/
51
- 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/superpwa/
52
- if ( ! defined('SUPERPWA_VERSION') ) define('SUPERPWA_VERSION', '1.5'); // Plugin version
53
- if ( ! defined('SUPERPWA_MANIFEST_FILENAME') ) define('SUPERPWA_MANIFEST_FILENAME', 'superpwa-manifest.json'); // Name of Manifest file
54
- if ( ! defined('SUPERPWA_MANIFEST_ABS') ) define('SUPERPWA_MANIFEST_ABS', trailingslashit( ABSPATH ) . SUPERPWA_MANIFEST_FILENAME); // Absolute path to manifest
55
- if ( ! defined('SUPERPWA_MANIFEST_SRC') ) define('SUPERPWA_MANIFEST_SRC', trailingslashit( get_bloginfo('wpurl') ) . SUPERPWA_MANIFEST_FILENAME); // Link to manifest
56
- if ( ! defined('SUPERPWA_SW_FILENAME') ) define('SUPERPWA_SW_FILENAME', 'superpwa-sw.js'); // Name of service worker file
57
- if ( ! defined('SUPERPWA_SW_ABS') ) define('SUPERPWA_SW_ABS', trailingslashit( ABSPATH ) . SUPERPWA_SW_FILENAME); // Absolute path to service worker. SW must be in the root folder
58
- if ( ! defined('SUPERPWA_SW_SRC') ) define('SUPERPWA_SW_SRC', trailingslashit( get_bloginfo('wpurl') ) . SUPERPWA_SW_FILENAME); // Link to service worker
59
 
60
  // Load everything
61
- require_once( SUPERPWA_PATH_ABS . 'admin/loader.php');
62
-
63
- // Register activation hook (this has to be in the main plugin file.)
64
- register_activation_hook( __FILE__, 'superpwa_activate_plugin' );
65
-
66
- // Register deactivatation hook
67
- register_deactivation_hook( __FILE__, 'superpwa_deactivate_plugin' );
1
  <?php
2
  /**
3
  * Plugin Name: Super Progressive Web Apps
4
+ * Plugin URI: https://superpwa.com
5
  * Description: Convert your WordPress website into a Progressive Web App
6
  * Author: SuperPWA
7
+ * Author URI: https://superpwa.com
8
  * Contributors: Arun Basil Lal, Jose Varghese
9
+ * Version: 1.6
10
  * Text Domain: super-progressive-web-apps
11
  * Domain Path: /languages
12
  * License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
13
  */
14
 
 
 
 
 
 
 
15
  /**
16
  * ~ Directory Structure ~
17
  *
18
+ * Based on the WordPress starter plugin template
19
+ * @link https://github.com/arunbasillal/WordPress-Starter-Plugin
20
+ *
21
+ * /3rd-party/ - Functions for compatibility with 3rd party plugins and hosts.
22
+ * /admin/ - Plugin backend.
23
+ * /functions/ - Functions and utilites.
24
  * /includes/ - External third party classes and libraries.
25
  * /languages/ - Translation files go here.
26
  * /public/ - Front end files go here.
27
  * index.php - Dummy file.
28
  * license.txt - GPL v2
29
+ * loader.php - Loads everything.
30
+ * superpwa.php - Main plugin file.
31
+ * README.MD - Readme for GitHub.
32
+ * readme.txt - Readme for WordPress plugin repository.
33
  * uninstall.php - Fired when the plugin is uninstalled.
34
  */
35
+
36
  /**
37
  * ~ Release TODO ~
38
  *
46
  /**
47
  * Define constants
48
  *
49
+ * @since 1.0
50
+ * @since 1.6 Depreciated constants for multisite compatibility: SUPERPWA_MANIFEST_FILENAME, SUPERPWA_MANIFEST_ABS, SUPERPWA_MANIFEST_SRC
51
+ * @since 1.6 Depreciated constants for multisite compatibility: SUPERPWA_SW_FILENAME, SUPERPWA_SW_ABS, SUPERPWA_SW_SRC
52
  */
53
+ if ( ! defined( 'SUPERPWA_VERSION' ) ) define( 'SUPERPWA_VERSION' , '1.6' ); // SuperPWA current version
54
+ 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/
55
+ 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/
 
 
 
 
 
 
56
 
57
  // Load everything
58
+ require_once( SUPERPWA_PATH_ABS . 'loader.php' );
 
 
 
 
 
 
uninstall.php CHANGED
@@ -3,21 +3,47 @@
3
  * Fired when the plugin is uninstalled.
4
  *
5
  * Everything in uninstall.php will be executed when user decides to delete the plugin.
6
- * @since 1.0
7
  */
8
 
9
-
10
  // Exit if accessed directly
11
- if ( ! defined('ABSPATH') ) exit;
12
 
13
  // If uninstall not called from WordPress, then die.
14
- if ( ! defined('WP_UNINSTALL_PLUGIN') ) die;
15
-
16
 
17
  /**
18
  * Delete database settings
19
  *
20
- * @since 1.0
21
  */
22
  delete_option( 'superpwa_settings' );
23
- delete_option( 'superpwa_version' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * Fired when the plugin is uninstalled.
4
  *
5
  * Everything in uninstall.php will be executed when user decides to delete the plugin.
6
+ * @since 1.0
7
  */
8
 
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) ) exit;
11
 
12
  // If uninstall not called from WordPress, then die.
13
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) die;
 
14
 
15
  /**
16
  * Delete database settings
17
  *
18
+ * @since 1.0
19
  */
20
  delete_option( 'superpwa_settings' );
21
+ delete_option( 'superpwa_version' );
22
+
23
+ /**
24
+ * Clean up for Multisites
25
+ *
26
+ * @since 1.6
27
+ */
28
+ if ( is_multisite() ) {
29
+
30
+ // Retrieve the list of blog ids where SuperPWA is active. (saved with blog_id as $key and activation_status as $value)
31
+ $superpwa_sites = get_site_option( 'superpwa_active_sites' );
32
+
33
+ // Loop through each active site.
34
+ foreach( $superpwa_sites as $blog_id => $actviation_status ) {
35
+
36
+ // Switch to each blog
37
+ switch_to_blog( $blog_id );
38
+
39
+ // Delete database settings for each site.
40
+ delete_option( 'superpwa_settings' );
41
+ delete_option( 'superpwa_version' );
42
+
43
+ // Return to main site
44
+ restore_current_blog();
45
+ }
46
+
47
+ // Delete the list of websites where SuperPWA was activated.
48
+ delete_site_option( 'superpwa_active_sites' );
49
+ }