@@ -243,27 +243,20 @@ public static function get_precached_script_cdn_urls() {
243
243
* Add hooks to install the service worker from AMP page.
244
244
*/
245
245
public static function add_install_hooks () {
246
- if ( ! amp_is_legacy () && amp_is_request () ) {
247
- add_action ( ' wp_footer ' , [ __CLASS__ , ' install_service_worker ' ] ) ;
248
-
249
- // Prevent validation error due to the script that installs the service worker on non-AMP pages.
250
- foreach ( [ ' wp_print_scripts ' , ' wp_print_footer_scripts ' ] as $ action ) {
251
- $ priority = has_action ( $ action , 'wp_print_service_workers ' );
252
- if ( false !== $ priority ) {
253
- remove_action ( $ action , ' wp_print_service_workers ' , $ priority );
254
- }
246
+ if ( ! amp_is_request () ) {
247
+ return ;
248
+ }
249
+
250
+ // Prevent validation error due to the script that installs the service worker on non-AMP pages.
251
+ foreach ( [ ' wp_print_scripts ' , 'wp_print_footer_scripts ' ] as $ action ) {
252
+ $ priority = has_action ( $ action , ' wp_print_service_workers ' );
253
+ if ( false !== $ priority ) {
254
+ remove_action ( $ action , ' wp_print_service_workers ' , $ priority );
255
255
}
256
256
}
257
257
258
- // Reader mode integration.
258
+ add_action ( ' wp_footer ' , [ __CLASS__ , ' install_service_worker ' ] );
259
259
add_action ( 'amp_post_template_footer ' , [ __CLASS__ , 'install_service_worker ' ] );
260
- add_filter (
261
- 'amp_post_template_data ' ,
262
- static function ( $ data ) {
263
- $ data ['amp_component_scripts ' ]['amp-install-serviceworker ' ] = true ;
264
- return $ data ;
265
- }
266
- );
267
260
}
268
261
269
262
/**
0 commit comments