diff --git a/integrations/class-wp-service-worker-admin-assets-integration.php b/integrations/class-wp-service-worker-admin-assets-integration.php index fb36e5c78..8c19d3d65 100644 --- a/integrations/class-wp-service-worker-admin-assets-integration.php +++ b/integrations/class-wp-service-worker-admin-assets-integration.php @@ -9,6 +9,7 @@ * Class representing the admin assets service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ final class WP_Service_Worker_Admin_Assets_Integration extends WP_Service_Worker_Base_Integration { @@ -44,6 +45,26 @@ public function register( WP_Service_Worker_Scripts $scripts ) { unset( $options['url'] ); $scripts->precaching_routes()->register( $url, $options ); } + + // Add deprecation warning in user's console when service worker is installed. + $scripts->register( + __CLASS__ . '-deprecation', + array( + 'src' => static function () { + return sprintf( + 'console.warn( %s );', + wp_json_encode( + sprintf( + /* translators: %1$s: integration class name, %2$s: issue url */ + __( 'The %1$s integration in the PWA plugin is no longer being considered WordPress core merge. See %2$s', 'pwa' ), + __CLASS__, + 'https://github.com/GoogleChromeLabs/pwa-wp/issues/403' + ) + ) + ); + }, + ) + ); } /** diff --git a/integrations/class-wp-service-worker-base-integration.php b/integrations/class-wp-service-worker-base-integration.php index 3de96ea0d..a814594e5 100644 --- a/integrations/class-wp-service-worker-base-integration.php +++ b/integrations/class-wp-service-worker-base-integration.php @@ -9,6 +9,7 @@ * Base class representing a service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ abstract class WP_Service_Worker_Base_Integration implements WP_Service_Worker_Integration { diff --git a/integrations/class-wp-service-worker-custom-background-integration.php b/integrations/class-wp-service-worker-custom-background-integration.php index b0595152f..7577ea331 100644 --- a/integrations/class-wp-service-worker-custom-background-integration.php +++ b/integrations/class-wp-service-worker-custom-background-integration.php @@ -9,6 +9,7 @@ * Class representing the Custom Background service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ final class WP_Service_Worker_Custom_Background_Integration extends WP_Service_Worker_Base_Integration { @@ -31,6 +32,26 @@ public function register( WP_Service_Worker_Scripts $scripts ) { $revision = md5( file_get_contents( $file ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown } $scripts->precaching_routes()->register( $url, compact( 'revision' ) ); + + // Add deprecation warning in user's console when service worker is installed. + $scripts->register( + __CLASS__ . '-deprecation', + array( + 'src' => static function () { + return sprintf( + 'console.warn( %s );', + wp_json_encode( + sprintf( + /* translators: %1$s: integration class name, %2$s: issue url */ + __( 'The %1$s integration in the PWA plugin is no longer being considered WordPress core merge. See %2$s', 'pwa' ), + __CLASS__, + 'https://github.com/GoogleChromeLabs/pwa-wp/issues/403' + ) + ) + ); + }, + ) + ); } /** diff --git a/integrations/class-wp-service-worker-custom-header-integration.php b/integrations/class-wp-service-worker-custom-header-integration.php index 06fedcd79..02b771b8c 100644 --- a/integrations/class-wp-service-worker-custom-header-integration.php +++ b/integrations/class-wp-service-worker-custom-header-integration.php @@ -9,6 +9,7 @@ * Class representing the Custom Header service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ final class WP_Service_Worker_Custom_Header_Integration extends WP_Service_Worker_Base_Integration { @@ -70,6 +71,26 @@ public function register( WP_Service_Worker_Scripts $scripts ) { } $scripts->precaching_routes()->register( $header_image, compact( 'revision' ) ); } + + // Add deprecation warning in user's console when service worker is installed. + $scripts->register( + __CLASS__ . '-deprecation', + array( + 'src' => static function () { + return sprintf( + 'console.warn( %s );', + wp_json_encode( + sprintf( + /* translators: %1$s: integration class name, %2$s: issue url */ + __( 'The %1$s integration in the PWA plugin is no longer being considered WordPress core merge. See %2$s', 'pwa' ), + __CLASS__, + 'https://github.com/GoogleChromeLabs/pwa-wp/issues/403' + ) + ) + ); + }, + ) + ); } /** diff --git a/integrations/class-wp-service-worker-custom-logo-integration.php b/integrations/class-wp-service-worker-custom-logo-integration.php index ea72d3c4c..78cda1b98 100644 --- a/integrations/class-wp-service-worker-custom-logo-integration.php +++ b/integrations/class-wp-service-worker-custom-logo-integration.php @@ -9,6 +9,7 @@ * Class representing the Custom Logo service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ final class WP_Service_Worker_Custom_Logo_Integration extends WP_Service_Worker_Base_Integration { @@ -38,6 +39,26 @@ public function register( WP_Service_Worker_Scripts $scripts ) { foreach ( array_unique( $image_urls ) as $image_url ) { $scripts->precaching_routes()->register( $image_url, array( 'revision' => $attachment->post_modified ) ); } + + // Add deprecation warning in user's console when service worker is installed. + $scripts->register( + __CLASS__ . '-deprecation', + array( + 'src' => static function () { + return sprintf( + 'console.warn( %s );', + wp_json_encode( + sprintf( + /* translators: %1$s: integration class name, %2$s: issue url */ + __( 'The %1$s integration in the PWA plugin is no longer being considered WordPress core merge. See %2$s', 'pwa' ), + __CLASS__, + 'https://github.com/GoogleChromeLabs/pwa-wp/issues/403' + ) + ) + ); + }, + ) + ); } /** diff --git a/integrations/class-wp-service-worker-fonts-integration.php b/integrations/class-wp-service-worker-fonts-integration.php index eaa90b87f..97ea9b9ef 100644 --- a/integrations/class-wp-service-worker-fonts-integration.php +++ b/integrations/class-wp-service-worker-fonts-integration.php @@ -9,6 +9,7 @@ * Class representing the Fonts service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ final class WP_Service_Worker_Fonts_Integration extends WP_Service_Worker_Base_Integration { @@ -47,6 +48,26 @@ public function register( WP_Service_Worker_Scripts $scripts ) { ), ) ); + + // Add deprecation warning in user's console when service worker is installed. + $scripts->register( + __CLASS__ . '-deprecation', + array( + 'src' => static function () { + return sprintf( + 'console.warn( %s );', + wp_json_encode( + sprintf( + /* translators: %1$s: integration class name, %2$s: issue url */ + __( 'The %1$s integration in the PWA plugin is no longer being considered WordPress core merge. See %2$s', 'pwa' ), + __CLASS__, + 'https://github.com/GoogleChromeLabs/pwa-wp/issues/403' + ) + ) + ); + }, + ) + ); } /** diff --git a/integrations/class-wp-service-worker-scripts-integration.php b/integrations/class-wp-service-worker-scripts-integration.php index 1fe6ab4ab..ce55b8b0f 100644 --- a/integrations/class-wp-service-worker-scripts-integration.php +++ b/integrations/class-wp-service-worker-scripts-integration.php @@ -9,6 +9,7 @@ * Class representing the Scripts service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ final class WP_Service_Worker_Scripts_Integration extends WP_Service_Worker_Base_Integration { @@ -101,6 +102,26 @@ public function register( WP_Service_Worker_Scripts $scripts ) { $scripts->precaching_routes()->register_emoji_script(); wp_scripts()->to_do = $original_to_do; // Restore original scripts to do. + + // Add deprecation warning in user's console when service worker is installed. + $scripts->register( + __CLASS__ . '-deprecation', + array( + 'src' => static function () { + return sprintf( + 'console.warn( %s );', + wp_json_encode( + sprintf( + /* translators: %1$s: integration class name, %2$s: issue url */ + __( 'The %1$s integration in the PWA plugin is no longer being considered WordPress core merge. See %2$s', 'pwa' ), + __CLASS__, + 'https://github.com/GoogleChromeLabs/pwa-wp/issues/403' + ) + ) + ); + }, + ) + ); } /** diff --git a/integrations/class-wp-service-worker-site-icon-integration.php b/integrations/class-wp-service-worker-site-icon-integration.php index 93928bfdc..4716c7f5a 100644 --- a/integrations/class-wp-service-worker-site-icon-integration.php +++ b/integrations/class-wp-service-worker-site-icon-integration.php @@ -9,6 +9,7 @@ * Class representing the Site Icon service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ final class WP_Service_Worker_Site_Icon_Integration extends WP_Service_Worker_Base_Integration { @@ -43,6 +44,26 @@ public function register( WP_Service_Worker_Scripts $scripts ) { foreach ( $image_urls as $image_url ) { $scripts->precaching_routes()->register( $image_url, array( 'revision' => $attachment->post_modified ) ); } + + // Add deprecation warning in user's console when service worker is installed. + $scripts->register( + __CLASS__ . '-deprecation', + array( + 'src' => static function () { + return sprintf( + 'console.warn( %s );', + wp_json_encode( + sprintf( + /* translators: %1$s: integration class name, %2$s: issue url */ + __( 'The %1$s integration in the PWA plugin is no longer being considered WordPress core merge. See %2$s', 'pwa' ), + __CLASS__, + 'https://github.com/GoogleChromeLabs/pwa-wp/issues/403' + ) + ) + ); + }, + ) + ); } /** diff --git a/integrations/class-wp-service-worker-styles-integration.php b/integrations/class-wp-service-worker-styles-integration.php index 33cdf0544..a037969c8 100644 --- a/integrations/class-wp-service-worker-styles-integration.php +++ b/integrations/class-wp-service-worker-styles-integration.php @@ -9,6 +9,7 @@ * Class representing the Styles service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ final class WP_Service_Worker_Styles_Integration extends WP_Service_Worker_Base_Integration { @@ -98,6 +99,26 @@ public function register( WP_Service_Worker_Scripts $scripts ) { } } wp_styles()->to_do = $original_to_do; // Restore original styles to do. + + // Add deprecation warning in user's console when service worker is installed. + $scripts->register( + __CLASS__ . '-deprecation', + array( + 'src' => static function () { + return sprintf( + 'console.warn( %s );', + wp_json_encode( + sprintf( + /* translators: %1$s: integration class name, %2$s: issue url */ + __( 'The %1$s integration in the PWA plugin is no longer being considered WordPress core merge. See %2$s', 'pwa' ), + __CLASS__, + 'https://github.com/GoogleChromeLabs/pwa-wp/issues/403' + ) + ) + ); + }, + ) + ); } /** diff --git a/integrations/functions.php b/integrations/functions.php index 3b41ba95f..62ad8bded 100644 --- a/integrations/functions.php +++ b/integrations/functions.php @@ -29,6 +29,7 @@ * ); * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. * * @param WP_Service_Worker_Scripts $scripts Instance to register service worker behavior with. */ diff --git a/integrations/interface-wp-service-worker-integration.php b/integrations/interface-wp-service-worker-integration.php index 18f3b12f3..9f1a7f8f1 100644 --- a/integrations/interface-wp-service-worker-integration.php +++ b/integrations/interface-wp-service-worker-integration.php @@ -9,6 +9,7 @@ * Interface representing a service worker integration. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. */ interface WP_Service_Worker_Integration { @@ -16,6 +17,7 @@ interface WP_Service_Worker_Integration { * Gets the scope this integration applies to. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. * * @return int Either WP_Service_Workers::SCOPE_FRONT, WP_Service_Workers::SCOPE_ADMIN, or * WP_Service_Workers::SCOPE_ALL. @@ -26,6 +28,7 @@ public function get_scope(); * Gets the priority this integration should be hooked into the service worker action with. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. * * @return int Hook priority. A higher number means a lower priority. */ @@ -35,6 +38,7 @@ public function get_priority(); * Registers the integration functionality. * * @since 0.2 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. * * @param WP_Service_Worker_Scripts $scripts Instance to register service worker behavior with. */ diff --git a/pwa.php b/pwa.php index d8f0d69eb..e7368dfac 100644 --- a/pwa.php +++ b/pwa.php @@ -271,25 +271,6 @@ function _pwa_deactivate_plugin() { register_deactivation_hook( PWA_PLUGIN_FILE, '_pwa_deactivate_plugin' ); -/** - * Load service worker integrations. - * - * @since 0.2.0 - * - * @param WP_Service_Worker_Scripts $scripts Instance to register service worker behavior with. - */ -function pwa_load_service_worker_integrations( WP_Service_Worker_Scripts $scripts ) { - if ( ! current_theme_supports( 'service_worker' ) ) { - return; - } - - /** WordPress Service Worker Integration Functions */ - require_once PWA_PLUGIN_DIR . '/integrations/functions.php'; - - pwa_register_service_worker_integrations( $scripts ); -} -add_action( 'wp_default_service_workers', 'pwa_load_service_worker_integrations', -1 ); - $wp_web_app_manifest = new WP_Web_App_Manifest(); $wp_web_app_manifest->init(); diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 15d9511de..4af845261 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -85,3 +85,23 @@ function wp_disable_script_concatenation() { } // phpcs:enable } + +/** + * Load service worker integrations. + * + * @since 0.2.0 + * @deprecated 0.7 Integrations will not be proposed for WordPress core merge. + * + * @param WP_Service_Worker_Scripts $scripts Instance to register service worker behavior with. + */ +function pwa_load_service_worker_integrations( WP_Service_Worker_Scripts $scripts ) { + if ( ! current_theme_supports( 'service_worker' ) ) { + return; + } + + /** WordPress Service Worker Integration Functions */ + require_once PWA_PLUGIN_DIR . '/integrations/functions.php'; + + pwa_register_service_worker_integrations( $scripts ); +} +add_action( 'wp_default_service_workers', 'pwa_load_service_worker_integrations', -1 );