Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate integrations #713

Merged
merged 9 commits into from
Mar 4, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Class representing the admin assets service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
thelovekesh marked this conversation as resolved.
Show resolved Hide resolved
*/
final class WP_Service_Worker_Admin_Assets_Integration extends WP_Service_Worker_Base_Integration {

Expand Down
2 changes: 2 additions & 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,8 @@
* Base class representing a service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
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,8 @@
* Class representing the Custom Background service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
final class WP_Service_Worker_Custom_Background_Integration extends WP_Service_Worker_Base_Integration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Class representing the Custom Header service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
final class WP_Service_Worker_Custom_Header_Integration extends WP_Service_Worker_Base_Integration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Class representing the Custom Logo service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
final class WP_Service_Worker_Custom_Logo_Integration extends WP_Service_Worker_Base_Integration {

Expand Down
2 changes: 2 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,8 @@
* Class representing the Fonts service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
final class WP_Service_Worker_Fonts_Integration extends WP_Service_Worker_Base_Integration {

Expand Down
2 changes: 2 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,8 @@
* Class representing the Scripts service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
final class WP_Service_Worker_Scripts_Integration extends WP_Service_Worker_Base_Integration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Class representing the Site Icon service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
final class WP_Service_Worker_Site_Icon_Integration extends WP_Service_Worker_Base_Integration {

Expand Down
2 changes: 2 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,8 @@
* Class representing the Styles service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
final class WP_Service_Worker_Styles_Integration extends WP_Service_Worker_Base_Integration {

Expand Down
2 changes: 2 additions & 0 deletions integrations/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*
* @param WP_Service_Worker_Scripts $scripts Instance to register service worker behavior with.
*/
function pwa_register_service_worker_integrations( WP_Service_Worker_Scripts $scripts ) {
Expand Down
8 changes: 8 additions & 0 deletions integrations/interface-wp-service-worker-integration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Interface representing a service worker integration.
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*/
interface WP_Service_Worker_Integration {

Expand All @@ -17,6 +19,8 @@ interface WP_Service_Worker_Integration {
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
thelovekesh marked this conversation as resolved.
Show resolved Hide resolved
*
* @return int Either WP_Service_Workers::SCOPE_FRONT, WP_Service_Workers::SCOPE_ADMIN, or
* WP_Service_Workers::SCOPE_ALL.
*/
Expand All @@ -27,6 +31,8 @@ public function get_scope();
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*
* @return int Hook priority. A higher number means a lower priority.
*/
public function get_priority();
Expand All @@ -36,6 +42,8 @@ public function get_priority();
*
* @since 0.2
*
* @deprecated 0.7 Integrations will be removed in the future versions.
*
* @param WP_Service_Worker_Scripts $scripts Instance to register service worker behavior with.
*/
public function register( WP_Service_Worker_Scripts $scripts );
Expand Down
55 changes: 55 additions & 0 deletions pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,61 @@ function pwa_load_service_worker_integrations( WP_Service_Worker_Scripts $script
}
add_action( 'wp_default_service_workers', 'pwa_load_service_worker_integrations', -1 );

/**
* Add Integrations deprecation notice in user's console
*
* @since 0.7
*/
function pwa_deprecate_service_worker_integrations() {
// Bail if not supported by theme.
$theme_support = get_theme_support( 'service_worker' );
if ( ! $theme_support ) {
return;
}

$integrations = array(
'wp-site-icon' => 'WP_Service_Worker_Site_Icon_Integration',
'wp-custom-logo' => 'WP_Service_Worker_Custom_Logo_Integration',
'wp-custom-header' => 'WP_Service_Worker_Custom_Header_Integration',
'wp-custom-background' => 'WP_Service_Worker_Custom_Background_Integration',
'wp-scripts' => 'WP_Service_Worker_Scripts_Integration',
'wp-styles' => 'WP_Service_Worker_Styles_Integration',
'wp-fonts' => 'WP_Service_Worker_Fonts_Integration',
'wp-admin-assets' => 'WP_Service_Worker_Admin_Assets_Integration',
);

// Filter active integrations if granular theme support array is provided.
if ( is_array( $theme_support ) && isset( $theme_support[0] ) && is_array( $theme_support[0] ) ) {
$integrations = array_intersect_key(
$integrations,
array_filter( $theme_support[0] )
);
}

$message = array();
foreach ( $integrations as $integration => $class ) {
$message[] = sprintf(
/* translators: 1: Integration name */
__( 'The %s integration in the PWA plugin is deprecated and no longer being considered for WordPress core inclusion.', 'pwa' ),
strtoupper( str_replace( '-', ' ', $integration ) )
);
}

?>
<script type="text/javascript" defer>
<?php
foreach ( $message as $message ) {
printf(
'console.warn( "%s" );',
esc_js( $message )
);
}
?>
</script>
<?php
}
add_action( 'wp_footer', 'pwa_deprecate_service_worker_integrations', 1000 );
thelovekesh marked this conversation as resolved.
Show resolved Hide resolved

$wp_web_app_manifest = new WP_Web_App_Manifest();
$wp_web_app_manifest->init();

Expand Down