From a208677342178c74dcdb6e872951fd9c2e267819 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 24 Jan 2019 18:27:47 -0500 Subject: [PATCH 1/6] Move functions related to theme output into wp-includes/template.php. --- wp-includes/service-workers.php | 37 --------------------------------- wp-includes/template.php | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/wp-includes/service-workers.php b/wp-includes/service-workers.php index 186f50ae3..9c409bb5b 100644 --- a/wp-includes/service-workers.php +++ b/wp-includes/service-workers.php @@ -399,40 +399,3 @@ function wp_service_worker_skip_waiting() { */ return (bool) apply_filters( 'wp_service_worker_skip_waiting', true ); } - -/** - * Get service worker error messages. - * - * @return array Array of error messages: default, comment. - */ -function wp_service_worker_get_error_messages() { - return apply_filters( - 'wp_service_worker_error_messages', - array( - 'default' => __( 'Please check your internet connection, and try again.', 'pwa' ), - 'error' => __( 'Something prevented the page from being rendered. Please try again.', 'pwa' ), - 'comment' => __( 'Your comment will be submitted once you are back online!', 'pwa' ), - ) - ); -} - -/** - * Display service worker error details template. - * - * @param string $output Error details template output. - */ -function wp_service_worker_error_details_template( $output = '' ) { - if ( empty( $output ) ) { - $output = '
' . esc_html__( 'More Details', 'pwa' ) . '{{{error_details_iframe}}}
'; - } - echo ''; // WPCS: XSS OK. - echo wp_kses_post( $output ); - echo ''; // WPCS: XSS OK. -} - -/** - * Display service worker error message template tag. - */ -function wp_service_worker_error_message_placeholder() { - echo '

'; // WPCS: XSS OK. -} diff --git a/wp-includes/template.php b/wp-includes/template.php index 1ef947c5c..ee32bfe55 100644 --- a/wp-includes/template.php +++ b/wp-includes/template.php @@ -128,3 +128,40 @@ function get_500_template() { return pwa_get_query_template( 'offline', $templates ); } + +/** + * Get service worker error messages. + * + * @return array Array of error messages: default, comment. + */ +function wp_service_worker_get_error_messages() { + return apply_filters( + 'wp_service_worker_error_messages', + array( + 'default' => __( 'Please check your internet connection, and try again.', 'pwa' ), + 'error' => __( 'Something prevented the page from being rendered. Please try again.', 'pwa' ), + 'comment' => __( 'Your comment will be submitted once you are back online!', 'pwa' ), + ) + ); +} + +/** + * Display service worker error details template. + * + * @param string $output Error details template output. + */ +function wp_service_worker_error_details_template( $output = '' ) { + if ( empty( $output ) ) { + $output = '
' . esc_html__( 'More Details', 'pwa' ) . '{{{error_details_iframe}}}
'; + } + echo ''; // WPCS: XSS OK. + echo wp_kses_post( $output ); + echo ''; // WPCS: XSS OK. +} + +/** + * Display service worker error message template tag. + */ +function wp_service_worker_error_message_placeholder() { + echo '

'; // WPCS: XSS OK. +} From 34a2ed43a21e812e6dd21767174233bedddd439d Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 24 Jan 2019 18:40:53 -0500 Subject: [PATCH 2/6] Move functions related to integrations into separate file and hide all integrations behind a feature flag. --- pwa.php | 48 +++++++---- wp-includes/default-filters.php | 1 - wp-includes/service-worker-integrations.php | 91 +++++++++++++++++++++ wp-includes/service-workers.php | 80 ------------------ 4 files changed, 123 insertions(+), 97 deletions(-) create mode 100644 wp-includes/service-worker-integrations.php diff --git a/pwa.php b/pwa.php index 49e0c860b..09ecba139 100644 --- a/pwa.php +++ b/pwa.php @@ -86,22 +86,6 @@ function _pwa_incorrect_plugin_slug_admin_notice() { require_once PWA_PLUGIN_DIR . '/wp-includes/components/class-wp-service-worker-caching-routes-component.php'; require_once PWA_PLUGIN_DIR . '/wp-includes/components/class-wp-service-worker-caching-routes.php'; -/** WP_Service_Worker_Integration Interface */ -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/interface-wp-service-worker-integration.php'; - -/** WP_Service_Worker_Base_Integration Class */ -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-base-integration.php'; - -/** WP_Service_Worker_Integration Implementation Classes */ -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-site-icon-integration.php'; -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-logo-integration.php'; -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-header-integration.php'; -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-background-integration.php'; -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-scripts-integration.php'; -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-styles-integration.php'; -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-fonts-integration.php'; -require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-admin-assets-integration.php'; - /** WordPress Service Worker Functions */ require_once PWA_PLUGIN_DIR . '/wp-includes/service-workers.php'; @@ -132,6 +116,38 @@ function _pwa_incorrect_plugin_slug_admin_notice() { /** Hooks to add for when accessing admin. */ require_once PWA_PLUGIN_DIR . '/wp-admin/admin.php'; +/** + * Filters whether service worker integrations should be enabled. + * + * As these are experimental, they are kept separate from the service worker core code and hidden behind a feature flag. + * + * Instead of using this filter, you can also use a constant `WP_SERVICE_WORKER_INTEGRATIONS_ENABLED`. + * + * @since 0.2 + * + * @param bool $enabled Whether or not service worker integrations are enabled. + */ +if ( apply_filters( 'wp_service_worker_integrations_enabled', defined( 'WP_SERVICE_WORKER_INTEGRATIONS_ENABLED' ) && WP_SERVICE_WORKER_INTEGRATIONS_ENABLED ) ) { + /** WP_Service_Worker_Integration Interface */ + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/interface-wp-service-worker-integration.php'; + + /** WP_Service_Worker_Base_Integration Class */ + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-base-integration.php'; + + /** WP_Service_Worker_Integration Implementation Classes */ + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-site-icon-integration.php'; + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-logo-integration.php'; + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-header-integration.php'; + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-background-integration.php'; + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-scripts-integration.php'; + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-styles-integration.php'; + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-fonts-integration.php'; + require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-admin-assets-integration.php'; + + /** WordPress Service Worker Integration Functions */ + require_once PWA_PLUGIN_DIR . '/wp-includes/service-worker-integrations.php'; +} + $wp_web_app_manifest = new WP_Web_App_Manifest(); $wp_web_app_manifest->init(); diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 9f62e46b9..6e8ab9578 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -21,7 +21,6 @@ add_action( 'wp_head', 'wp_add_error_template_no_robots' ); add_filter( 'pre_get_document_title', 'WP_Service_Worker_Navigation_Routing_Component::filter_title_for_streaming_header' ); add_action( 'error_head', 'wp_add_error_template_no_robots' ); -add_action( 'wp_default_service_workers', 'wp_default_service_workers' ); add_action( 'admin_init', 'wp_disable_script_concatenation' ); diff --git a/wp-includes/service-worker-integrations.php b/wp-includes/service-worker-integrations.php new file mode 100644 index 000000000..43e5733e3 --- /dev/null +++ b/wp-includes/service-worker-integrations.php @@ -0,0 +1,91 @@ +base_url = site_url(); + $scripts->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : ''; + $scripts->default_version = get_bloginfo( 'version' ); + + $integrations = array( + 'wp-site-icon' => new WP_Service_Worker_Site_Icon_Integration(), + 'wp-custom-logo' => new WP_Service_Worker_Custom_Logo_Integration(), + 'wp-custom-header' => new WP_Service_Worker_Custom_Header_Integration(), + 'wp-custom-background' => new WP_Service_Worker_Custom_Background_Integration(), + 'wp-scripts' => new WP_Service_Worker_Scripts_Integration(), + 'wp-styles' => new WP_Service_Worker_Styles_Integration(), + 'wp-fonts' => new WP_Service_Worker_Fonts_Integration(), + ); + + if ( ! SCRIPT_DEBUG ) { + $integrations['wp-admin-assets'] = new WP_Service_Worker_Admin_Assets_Integration(); + } + + /** + * Filters the service worker integrations to initialize. + * + * @since 0.2 + * + * @param array $integrations Array of $slug => $integration pairs, where $integration is an instance + * of a class that implements the WP_Service_Worker_Integration interface. + */ + $integrations = apply_filters( 'wp_service_worker_integrations', $integrations ); + + foreach ( $integrations as $slug => $integration ) { + if ( ! $integration instanceof WP_Service_Worker_Integration ) { + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: 1: integration slug, 2: interface name */ + esc_html__( 'The integration with slug %1$s does not implement the %2$s interface.', 'pwa' ), + esc_html( $slug ), + 'WP_Service_Worker_Integration' + ), + '0.2' + ); + continue; + } + + $scope = $integration->get_scope(); + $priority = $integration->get_priority(); + switch ( $scope ) { + case WP_Service_Workers::SCOPE_FRONT: + add_action( 'wp_front_service_worker', array( $integration, 'register' ), $priority, 1 ); + break; + case WP_Service_Workers::SCOPE_ADMIN: + add_action( 'wp_admin_service_worker', array( $integration, 'register' ), $priority, 1 ); + break; + case WP_Service_Workers::SCOPE_ALL: + add_action( 'wp_front_service_worker', array( $integration, 'register' ), $priority, 1 ); + add_action( 'wp_admin_service_worker', array( $integration, 'register' ), $priority, 1 ); + break; + default: + $valid_scopes = array( WP_Service_Workers::SCOPE_FRONT, WP_Service_Workers::SCOPE_ADMIN, WP_Service_Workers::SCOPE_ALL ); + _doing_it_wrong( + __FUNCTION__, + sprintf( + /* translators: 1: integration slug, 2: a comma-separated list of valid scopes */ + esc_html__( 'Scope for integration %1$s must be one out of %2$s.', 'pwa' ), + esc_html( $slug ), + esc_html( implode( ', ', $valid_scopes ) ) + ), + '0.1' + ); + } + } +} +add_action( 'wp_default_service_workers', 'wp_default_service_workers' ); diff --git a/wp-includes/service-workers.php b/wp-includes/service-workers.php index 9c409bb5b..c4efedcd5 100644 --- a/wp-includes/service-workers.php +++ b/wp-includes/service-workers.php @@ -231,86 +231,6 @@ function wp_service_worker_json_encode( $data ) { return wp_json_encode( $data, 128 | 64 /* JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES */ ); } -/** - * Registers all default service workers. - * - * @since 0.2 - * - * @param WP_Service_Worker_Scripts $scripts Instance to register service worker behavior with. - */ -function wp_default_service_workers( $scripts ) { - $scripts->base_url = site_url(); - $scripts->content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : ''; - $scripts->default_version = get_bloginfo( 'version' ); - - $integrations = array( - 'wp-site-icon' => new WP_Service_Worker_Site_Icon_Integration(), - 'wp-custom-logo' => new WP_Service_Worker_Custom_Logo_Integration(), - 'wp-custom-header' => new WP_Service_Worker_Custom_Header_Integration(), - 'wp-custom-background' => new WP_Service_Worker_Custom_Background_Integration(), - 'wp-scripts' => new WP_Service_Worker_Scripts_Integration(), - 'wp-styles' => new WP_Service_Worker_Styles_Integration(), - 'wp-fonts' => new WP_Service_Worker_Fonts_Integration(), - ); - - if ( ! SCRIPT_DEBUG ) { - $integrations['wp-admin-assets'] = new WP_Service_Worker_Admin_Assets_Integration(); - } - - /** - * Filters the service worker integrations to initialize. - * - * @since 0.2 - * - * @param array $integrations Array of $slug => $integration pairs, where $integration is an instance - * of a class that implements the WP_Service_Worker_Integration interface. - */ - $integrations = apply_filters( 'wp_service_worker_integrations', $integrations ); - - foreach ( $integrations as $slug => $integration ) { - if ( ! $integration instanceof WP_Service_Worker_Integration ) { - _doing_it_wrong( - __FUNCTION__, - sprintf( - /* translators: 1: integration slug, 2: interface name */ - esc_html__( 'The integration with slug %1$s does not implement the %2$s interface.', 'pwa' ), - esc_html( $slug ), - 'WP_Service_Worker_Integration' - ), - '0.2' - ); - continue; - } - - $scope = $integration->get_scope(); - $priority = $integration->get_priority(); - switch ( $scope ) { - case WP_Service_Workers::SCOPE_FRONT: - add_action( 'wp_front_service_worker', array( $integration, 'register' ), $priority, 1 ); - break; - case WP_Service_Workers::SCOPE_ADMIN: - add_action( 'wp_admin_service_worker', array( $integration, 'register' ), $priority, 1 ); - break; - case WP_Service_Workers::SCOPE_ALL: - add_action( 'wp_front_service_worker', array( $integration, 'register' ), $priority, 1 ); - add_action( 'wp_admin_service_worker', array( $integration, 'register' ), $priority, 1 ); - break; - default: - $valid_scopes = array( WP_Service_Workers::SCOPE_FRONT, WP_Service_Workers::SCOPE_ADMIN, WP_Service_Workers::SCOPE_ALL ); - _doing_it_wrong( - __FUNCTION__, - sprintf( - /* translators: 1: integration slug, 2: a comma-separated list of valid scopes */ - esc_html__( 'Scope for integration %1$s must be one out of %2$s.', 'pwa' ), - esc_html( $slug ), - esc_html( implode( ', ', $valid_scopes ) ) - ), - '0.1' - ); - } - } -} - /** * Disables concatenating scripts to leverage caching the assets via Service Worker instead. */ From 69b73afc65b5476e0da68fe6a1af2317c80e48cc Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 24 Jan 2019 18:51:36 -0500 Subject: [PATCH 3/6] Update documentation for separate service worker integrations. --- readme.md | 36 ++++++++++++++++++++++++++++-------- readme.txt | 20 ++++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index 94a2b87ce..a8e8e7f4c 100644 --- a/readme.md +++ b/readme.md @@ -4,15 +4,15 @@ ![Banner](wp-assets/banner-1544x500.png) WordPress feature plugin to bring Progressive Web App (PWA) capabilities to Core -**Contributors:** [xwp](https://profiles.wordpress.org/xwp), [google](https://profiles.wordpress.org/google), [automattic](https://profiles.wordpress.org/automattic) -**Tags:** [pwa](https://wordpress.org/plugins/tags/pwa), [progressive web apps](https://wordpress.org/plugins/tags/progressive-web-apps), [service workers](https://wordpress.org/plugins/tags/service-workers), [web app manifest](https://wordpress.org/plugins/tags/web-app-manifest), [https](https://wordpress.org/plugins/tags/https) -**Requires at least:** 4.9 -**Tested up to:** 4.9 -**Stable tag:** 0.1.0 -**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) -**Requires PHP:** 5.2 +**Contributors:** [xwp](https://profiles.wordpress.org/xwp), [google](https://profiles.wordpress.org/google), [automattic](https://profiles.wordpress.org/automattic) +**Tags:** [pwa](https://wordpress.org/plugins/tags/pwa), [progressive web apps](https://wordpress.org/plugins/tags/progressive-web-apps), [service workers](https://wordpress.org/plugins/tags/service-workers), [web app manifest](https://wordpress.org/plugins/tags/web-app-manifest), [https](https://wordpress.org/plugins/tags/https) +**Requires at least:** 4.9 +**Tested up to:** 4.9 +**Stable tag:** 0.1.0 +**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) +**Requires PHP:** 5.2 -[![Build Status](https://travis-ci.org/xwp/pwa-wp.svg?branch=master)](https://travis-ci.org/xwp/pwa-wp) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com) +[![Build Status](https://travis-ci.org/xwp/pwa-wp.svg?branch=master)](https://travis-ci.org/xwp/pwa-wp) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com) ## Description ## @@ -150,6 +150,25 @@ add_action( 'wp_admin_service_worker', 'register_baz_service_worker_script' ); See [labeled GitHub issues](https://github.com/xwp/pwa-wp/issues?q=label%3Aservice-workers) and see WordPress core tracking ticket [#36995](https://core.trac.wordpress.org/ticket/36995). +### Integrations +The plugin bundles several experimental integrations that are kept separate from the service worker core code. These integrations act as examples and proof-of-concept to achieve certain goals. While all of them are generally applicable and recommended to truly benefit from service workers, they are not crucial for the core API. + +All these integrations are hidden behind a feature flag. To enable them, you can either set a constant `WP_SERVICE_WORKER_INTEGRATIONS_ENABLED` in your `wp-config.php` and set it to true, or add a one-liner must-use plugin: + +
+
+
 ### Caching ###
 Service Workers in the feature plugin are using [Workbox](https://developers.google.com/web/tools/workbox/) to power a higher-level PHP abstraction for themes and plugins to indicate the routes and the caching strategies in a declarative way. Since only one handler can be used per one route then conflicts are also detected and reported in console when using debug mode.
 
@@ -243,6 +262,7 @@ In case of submitting a comment and being offline (failing to fetch) the request
 Here is a list of all available actions and filters added by the feature plugin.
 
 **Filters:**
+- `wp_service_worker_integrations_enabled`: Filters whether the experimental integrations should be enabled.
 - `wp_service_worker_integrations`: Filters the service worker integrations to initialize.
   - Has one argument: `$integrations` which is an array of `$slug` => `$integration pairs, where $integration is an instance of a class that implements the WP_Service_Worker_Integration interface.`
 - `wp_service_worker_skip_waiting`: Filters whether the service worker should update automatically when a new version is available.
diff --git a/readme.txt b/readme.txt
index cb6c6275d..caab2dc0a 100644
--- a/readme.txt
+++ b/readme.txt
@@ -149,6 +149,25 @@ add_action( 'wp_admin_service_worker', 'register_baz_service_worker_script' );
 
 See [labeled GitHub issues](https://github.com/xwp/pwa-wp/issues?q=label%3Aservice-workers) and see WordPress core tracking ticket [#36995](https://core.trac.wordpress.org/ticket/36995).
 
+= Integrations =
+The plugin bundles several experimental integrations that are kept separate from the service worker core code. These integrations act as examples and proof-of-concept to achieve certain goals. While all of them are generally applicable and recommended to truly benefit from service workers, they are not crucial for the core API.
+
+All these integrations are hidden behind a feature flag. To enable them, you can either set a constant `WP_SERVICE_WORKER_INTEGRATIONS_ENABLED` in your `wp-config.php` and set it to true, or add a one-liner must-use plugin:
+
+
+
+
 = Caching =
 Service Workers in the feature plugin are using [Workbox](https://developers.google.com/web/tools/workbox/) to power a higher-level PHP abstraction for themes and plugins to indicate the routes and the caching strategies in a declarative way. Since only one handler can be used per one route then conflicts are also detected and reported in console when using debug mode.
 
@@ -243,6 +262,7 @@ In case of submitting a comment and being offline (failing to fetch) the request
 Here is a list of all available actions and filters added by the feature plugin.
 
 **Filters:**
+- `wp_service_worker_integrations_enabled`: Filters whether the experimental integrations should be enabled.
 - `wp_service_worker_integrations`: Filters the service worker integrations to initialize.
   - Has one argument: `$integrations` which is an array of `$slug` => `$integration pairs, where $integration is an instance of a class that implements the WP_Service_Worker_Integration interface.`
 - `wp_service_worker_skip_waiting`: Filters whether the service worker should update automatically when a new version is available.

From 789ba76c6f50af84af8902c4f283c75f3831e8bb Mon Sep 17 00:00:00 2001
From: Felix Arntz 
Date: Fri, 25 Jan 2019 19:11:11 -0500
Subject: [PATCH 4/6] Move integrations code out of wp-includes to indicate it
 is separate from the core.

---
 ...ervice-worker-admin-assets-integration.php |  0
 ...ass-wp-service-worker-base-integration.php |  0
 ...e-worker-custom-background-integration.php |  0
 ...rvice-worker-custom-header-integration.php |  0
 ...service-worker-custom-logo-integration.php |  0
 ...ss-wp-service-worker-fonts-integration.php |  0
 ...-wp-service-worker-scripts-integration.php |  0
 ...p-service-worker-site-icon-integration.php |  0
 ...s-wp-service-worker-styles-integration.php |  0
 .../functions.php                             |  0
 ...nterface-wp-service-worker-integration.php |  0
 pwa.php                                       | 22 +++++++++----------
 wp-includes/class-wp-service-workers.php      |  9 --------
 13 files changed, 11 insertions(+), 20 deletions(-)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-admin-assets-integration.php (100%)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-base-integration.php (100%)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-custom-background-integration.php (100%)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-custom-header-integration.php (100%)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-custom-logo-integration.php (100%)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-fonts-integration.php (100%)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-scripts-integration.php (100%)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-site-icon-integration.php (100%)
 rename {wp-includes/integrations => integrations}/class-wp-service-worker-styles-integration.php (100%)
 rename wp-includes/service-worker-integrations.php => integrations/functions.php (100%)
 rename {wp-includes/integrations => integrations}/interface-wp-service-worker-integration.php (100%)

diff --git a/wp-includes/integrations/class-wp-service-worker-admin-assets-integration.php b/integrations/class-wp-service-worker-admin-assets-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-admin-assets-integration.php
rename to integrations/class-wp-service-worker-admin-assets-integration.php
diff --git a/wp-includes/integrations/class-wp-service-worker-base-integration.php b/integrations/class-wp-service-worker-base-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-base-integration.php
rename to integrations/class-wp-service-worker-base-integration.php
diff --git a/wp-includes/integrations/class-wp-service-worker-custom-background-integration.php b/integrations/class-wp-service-worker-custom-background-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-custom-background-integration.php
rename to integrations/class-wp-service-worker-custom-background-integration.php
diff --git a/wp-includes/integrations/class-wp-service-worker-custom-header-integration.php b/integrations/class-wp-service-worker-custom-header-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-custom-header-integration.php
rename to integrations/class-wp-service-worker-custom-header-integration.php
diff --git a/wp-includes/integrations/class-wp-service-worker-custom-logo-integration.php b/integrations/class-wp-service-worker-custom-logo-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-custom-logo-integration.php
rename to integrations/class-wp-service-worker-custom-logo-integration.php
diff --git a/wp-includes/integrations/class-wp-service-worker-fonts-integration.php b/integrations/class-wp-service-worker-fonts-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-fonts-integration.php
rename to integrations/class-wp-service-worker-fonts-integration.php
diff --git a/wp-includes/integrations/class-wp-service-worker-scripts-integration.php b/integrations/class-wp-service-worker-scripts-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-scripts-integration.php
rename to integrations/class-wp-service-worker-scripts-integration.php
diff --git a/wp-includes/integrations/class-wp-service-worker-site-icon-integration.php b/integrations/class-wp-service-worker-site-icon-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-site-icon-integration.php
rename to integrations/class-wp-service-worker-site-icon-integration.php
diff --git a/wp-includes/integrations/class-wp-service-worker-styles-integration.php b/integrations/class-wp-service-worker-styles-integration.php
similarity index 100%
rename from wp-includes/integrations/class-wp-service-worker-styles-integration.php
rename to integrations/class-wp-service-worker-styles-integration.php
diff --git a/wp-includes/service-worker-integrations.php b/integrations/functions.php
similarity index 100%
rename from wp-includes/service-worker-integrations.php
rename to integrations/functions.php
diff --git a/wp-includes/integrations/interface-wp-service-worker-integration.php b/integrations/interface-wp-service-worker-integration.php
similarity index 100%
rename from wp-includes/integrations/interface-wp-service-worker-integration.php
rename to integrations/interface-wp-service-worker-integration.php
diff --git a/pwa.php b/pwa.php
index 09ecba139..549a060a7 100644
--- a/pwa.php
+++ b/pwa.php
@@ -129,23 +129,23 @@ function _pwa_incorrect_plugin_slug_admin_notice() {
  */
 if ( apply_filters( 'wp_service_worker_integrations_enabled', defined( 'WP_SERVICE_WORKER_INTEGRATIONS_ENABLED' ) && WP_SERVICE_WORKER_INTEGRATIONS_ENABLED ) ) {
 	/** WP_Service_Worker_Integration Interface */
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/interface-wp-service-worker-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/interface-wp-service-worker-integration.php';
 
 	/** WP_Service_Worker_Base_Integration Class */
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-base-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-base-integration.php';
 
 	/** WP_Service_Worker_Integration Implementation Classes */
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-site-icon-integration.php';
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-logo-integration.php';
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-header-integration.php';
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-custom-background-integration.php';
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-scripts-integration.php';
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-styles-integration.php';
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-fonts-integration.php';
-	require_once PWA_PLUGIN_DIR . '/wp-includes/integrations/class-wp-service-worker-admin-assets-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-site-icon-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-custom-logo-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-custom-header-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-custom-background-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-scripts-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-styles-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-fonts-integration.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/class-wp-service-worker-admin-assets-integration.php';
 
 	/** WordPress Service Worker Integration Functions */
-	require_once PWA_PLUGIN_DIR . '/wp-includes/service-worker-integrations.php';
+	require_once PWA_PLUGIN_DIR . '/integrations/functions.php';
 }
 
 $wp_web_app_manifest = new WP_Web_App_Manifest();
diff --git a/wp-includes/class-wp-service-workers.php b/wp-includes/class-wp-service-workers.php
index 850c8cf08..864288c40 100644
--- a/wp-includes/class-wp-service-workers.php
+++ b/wp-includes/class-wp-service-workers.php
@@ -108,15 +108,6 @@ public function serve_request() {
 			/**
 			 * Fires before serving the frontend service worker, when its scripts should be registered, caching routes established, and assets precached.
 			 *
-			 * The following integrations are hooked into this action by default: 'wp-site-icon', 'wp-custom-logo', 'wp-custom-header', 'wp-custom-background',
-			 * 'wp-scripts', 'wp-styles', and 'wp-fonts'. This default behavior can be disabled with code such as the following, for disabling the
-			 * 'wp-custom-header' integration:
-			 *
-			 *     add_filter( 'wp_service_worker_integrations', function( $integrations ) {
-			 *         unset( $integrations['wp-custom-header'] );
-			 *         return $integrations;
-			 *     } );
-			 *
 			 * @since 0.2
 			 *
 			 * @param WP_Service_Worker_Scripts $scripts Instance to register service worker behavior with.

From cf473318e1bd2f3cc35859af8719463fc52f37c7 Mon Sep 17 00:00:00 2001
From: Weston Ruter 
Date: Fri, 25 Jan 2019 23:20:58 -0500
Subject: [PATCH 5/6] Re-generate markdown.md to restore trailing spaces

---
 readme.md | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/readme.md b/readme.md
index a8e8e7f4c..ca85e48a1 100644
--- a/readme.md
+++ b/readme.md
@@ -4,15 +4,15 @@
 ![Banner](wp-assets/banner-1544x500.png)
 WordPress feature plugin to bring Progressive Web App (PWA) capabilities to Core
 
-**Contributors:** [xwp](https://profiles.wordpress.org/xwp), [google](https://profiles.wordpress.org/google), [automattic](https://profiles.wordpress.org/automattic)
-**Tags:** [pwa](https://wordpress.org/plugins/tags/pwa), [progressive web apps](https://wordpress.org/plugins/tags/progressive-web-apps), [service workers](https://wordpress.org/plugins/tags/service-workers), [web app manifest](https://wordpress.org/plugins/tags/web-app-manifest), [https](https://wordpress.org/plugins/tags/https)
-**Requires at least:** 4.9
-**Tested up to:** 4.9
-**Stable tag:** 0.1.0
-**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
-**Requires PHP:** 5.2
+**Contributors:** [xwp](https://profiles.wordpress.org/xwp), [google](https://profiles.wordpress.org/google), [automattic](https://profiles.wordpress.org/automattic)  
+**Tags:** [pwa](https://wordpress.org/plugins/tags/pwa), [progressive web apps](https://wordpress.org/plugins/tags/progressive-web-apps), [service workers](https://wordpress.org/plugins/tags/service-workers), [web app manifest](https://wordpress.org/plugins/tags/web-app-manifest), [https](https://wordpress.org/plugins/tags/https)  
+**Requires at least:** 4.9  
+**Tested up to:** 4.9  
+**Stable tag:** 0.1.0  
+**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)  
+**Requires PHP:** 5.2  
 
-[![Build Status](https://travis-ci.org/xwp/pwa-wp.svg?branch=master)](https://travis-ci.org/xwp/pwa-wp) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com)
+[![Build Status](https://travis-ci.org/xwp/pwa-wp.svg?branch=master)](https://travis-ci.org/xwp/pwa-wp) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com) 
 
 ## Description ##
 
@@ -150,7 +150,7 @@ add_action( 'wp_admin_service_worker', 'register_baz_service_worker_script' );
 
 See [labeled GitHub issues](https://github.com/xwp/pwa-wp/issues?q=label%3Aservice-workers) and see WordPress core tracking ticket [#36995](https://core.trac.wordpress.org/ticket/36995).
 
-### Integrations
+### Integrations ###
 The plugin bundles several experimental integrations that are kept separate from the service worker core code. These integrations act as examples and proof-of-concept to achieve certain goals. While all of them are generally applicable and recommended to truly benefit from service workers, they are not crucial for the core API.
 
 All these integrations are hidden behind a feature flag. To enable them, you can either set a constant `WP_SERVICE_WORKER_INTEGRATIONS_ENABLED` in your `wp-config.php` and set it to true, or add a one-liner must-use plugin:

From e1d136a82016b491e74523ad9eb495e2e773fb87 Mon Sep 17 00:00:00 2001
From: Weston Ruter 
Date: Fri, 25 Jan 2019 23:29:14 -0500
Subject: [PATCH 6/6] Defer loading integrations until plugins_loaded action

---
 pwa.php | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/pwa.php b/pwa.php
index 549a060a7..b2856dc20 100644
--- a/pwa.php
+++ b/pwa.php
@@ -117,17 +117,25 @@ function _pwa_incorrect_plugin_slug_admin_notice() {
 require_once PWA_PLUGIN_DIR . '/wp-admin/admin.php';
 
 /**
- * Filters whether service worker integrations should be enabled.
+ * Load service worker integrations.
  *
- * As these are experimental, they are kept separate from the service worker core code and hidden behind a feature flag.
- *
- * Instead of using this filter, you can also use a constant `WP_SERVICE_WORKER_INTEGRATIONS_ENABLED`.
- *
- * @since 0.2
- *
- * @param bool $enabled Whether or not service worker integrations are enabled.
+ * @since 0.2.0
  */
-if ( apply_filters( 'wp_service_worker_integrations_enabled', defined( 'WP_SERVICE_WORKER_INTEGRATIONS_ENABLED' ) && WP_SERVICE_WORKER_INTEGRATIONS_ENABLED ) ) {
+function pwa_load_service_worker_integrations() {
+	/**
+	 * Filters whether service worker integrations should be enabled.
+	 *
+	 * As these are experimental, they are kept separate from the service worker core code and hidden behind a feature flag.
+	 *
+	 * Instead of using this filter, you can also use a constant `WP_SERVICE_WORKER_INTEGRATIONS_ENABLED`.
+	 *
+	 * @since 0.2
+	 *
+	 * @param bool $enabled Whether or not service worker integrations are enabled.
+	 */
+	if ( ! apply_filters( 'wp_service_worker_integrations_enabled', defined( 'WP_SERVICE_WORKER_INTEGRATIONS_ENABLED' ) && WP_SERVICE_WORKER_INTEGRATIONS_ENABLED ) ) {
+		return;
+	}
 	/** WP_Service_Worker_Integration Interface */
 	require_once PWA_PLUGIN_DIR . '/integrations/interface-wp-service-worker-integration.php';
 
@@ -147,6 +155,7 @@ function _pwa_incorrect_plugin_slug_admin_notice() {
 	/** WordPress Service Worker Integration Functions */
 	require_once PWA_PLUGIN_DIR . '/integrations/functions.php';
 }
+add_action( 'plugins_loaded', 'pwa_load_service_worker_integrations' );
 
 $wp_web_app_manifest = new WP_Web_App_Manifest();
 $wp_web_app_manifest->init();