Skip to content

Commit

Permalink
Add deprecation warning in user console when service worker is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
thelovekesh committed Mar 1, 2022
1 parent 2942877 commit 087ed7a
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
20 changes: 20 additions & 0 deletions integrations/class-wp-service-worker-admin-assets-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions integrations/class-wp-service-worker-custom-header-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions integrations/class-wp-service-worker-custom-logo-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions integrations/class-wp-service-worker-fonts-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions integrations/class-wp-service-worker-scripts-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions integrations/class-wp-service-worker-site-icon-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions integrations/class-wp-service-worker-styles-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down

0 comments on commit 087ed7a

Please sign in to comment.