Skip to content

Commit

Permalink
Merge pull request #713 from GoogleChromeLabs/add/deprecate-integrations
Browse files Browse the repository at this point in the history
Deprecate integrations
  • Loading branch information
westonruter authored Mar 4, 2022
2 parents 0f683ce + 56b3d8d commit f22026f
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 19 deletions.
21 changes: 21 additions & 0 deletions integrations/class-wp-service-worker-admin-assets-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions integrations/class-wp-service-worker-base-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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'
)
)
);
},
)
);
}

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

Expand Down Expand Up @@ -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'
)
)
);
},
)
);
}

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

Expand Down Expand Up @@ -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'
)
)
);
},
)
);
}

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

Expand Down Expand Up @@ -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'
)
)
);
},
)
);
}

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

Expand Down Expand Up @@ -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'
)
)
);
},
)
);
}

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

Expand Down Expand Up @@ -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'
)
)
);
},
)
);
}

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

Expand Down Expand Up @@ -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'
)
)
);
},
)
);
}

/**
Expand Down
1 change: 1 addition & 0 deletions integrations/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions integrations/interface-wp-service-worker-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
* 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 {

/**
* 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.
Expand 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.
*/
Expand All @@ -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.
*/
Expand Down
19 changes: 0 additions & 19 deletions pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
20 changes: 20 additions & 0 deletions wp-includes/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

0 comments on commit f22026f

Please sign in to comment.