Last active
August 27, 2018 22:47
-
-
Save westonruter/7b0705ae9ce8dcf3e1a8de28eb7b34b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Everything registered here will be concatenated into a single script that is | |
* served via /?wp_service_worker=1 which is installed as the service worker. | |
*/ | |
add_action( 'wp_front_service_worker', function( WP_Service_Workers $sw ) { | |
$sw->register_script( | |
'static-file', | |
plugin_dir_url( __FILE__ ) . 'example.js', | |
array( 'main-site-id' ) // Dependency declared so this script will be output after the following. | |
); | |
$sw->register_script( | |
'main-site-id', | |
function() { | |
return sprintf( 'const mainSiteId = %s;', wp_json_encode( get_main_site_id() ) ); | |
} | |
); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment