From 087ed7a84b97060c711121f7f44343fbe7c49d17 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Tue, 1 Mar 2022 07:59:36 +0530 Subject: [PATCH] Add deprecation warning in user console when service worker is installed --- ...ervice-worker-admin-assets-integration.php | 20 +++++++++++++++++++ ...e-worker-custom-background-integration.php | 20 +++++++++++++++++++ ...rvice-worker-custom-header-integration.php | 20 +++++++++++++++++++ ...service-worker-custom-logo-integration.php | 20 +++++++++++++++++++ ...ss-wp-service-worker-fonts-integration.php | 20 +++++++++++++++++++ ...-wp-service-worker-scripts-integration.php | 20 +++++++++++++++++++ ...p-service-worker-site-icon-integration.php | 20 +++++++++++++++++++ ...s-wp-service-worker-styles-integration.php | 20 +++++++++++++++++++ 8 files changed, 160 insertions(+) diff --git a/integrations/class-wp-service-worker-admin-assets-integration.php b/integrations/class-wp-service-worker-admin-assets-integration.php index 3300dba1e..baaccb463 100644 --- a/integrations/class-wp-service-worker-admin-assets-integration.php +++ b/integrations/class-wp-service-worker-admin-assets-integration.php @@ -46,6 +46,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-custom-background-integration.php b/integrations/class-wp-service-worker-custom-background-integration.php index b329354d1..db015f52f 100644 --- a/integrations/class-wp-service-worker-custom-background-integration.php +++ b/integrations/class-wp-service-worker-custom-background-integration.php @@ -33,6 +33,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 6b69d244e..1a0726c92 100644 --- a/integrations/class-wp-service-worker-custom-header-integration.php +++ b/integrations/class-wp-service-worker-custom-header-integration.php @@ -72,6 +72,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 c9b0b4ce6..23ecf4a38 100644 --- a/integrations/class-wp-service-worker-custom-logo-integration.php +++ b/integrations/class-wp-service-worker-custom-logo-integration.php @@ -40,6 +40,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 bf065c6ed..c488de7d3 100644 --- a/integrations/class-wp-service-worker-fonts-integration.php +++ b/integrations/class-wp-service-worker-fonts-integration.php @@ -49,6 +49,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 170546e6d..7e7802a25 100644 --- a/integrations/class-wp-service-worker-scripts-integration.php +++ b/integrations/class-wp-service-worker-scripts-integration.php @@ -103,6 +103,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 60ad6867b..3fedbf52d 100644 --- a/integrations/class-wp-service-worker-site-icon-integration.php +++ b/integrations/class-wp-service-worker-site-icon-integration.php @@ -45,6 +45,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 8bc3468cd..bd5bd6041 100644 --- a/integrations/class-wp-service-worker-styles-integration.php +++ b/integrations/class-wp-service-worker-styles-integration.php @@ -100,6 +100,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' + ) + ) + ); + }, + ) + ); } /**