Other plugins extend the manifest and the service worker through these hooks.
lh_web_application_manifest_json_filterfilters the manifest array (LH Share Target addsshare_targethere). Do not changeid: browsers identify an installed app by it.lh_web_application_import_scripts_handle_filter(script handles) andlh_web_application_import_scripts_src_filter(URLs) choose the scripts the worker imports withimportScripts(). LH Web Push Notifications and LH BuddyPress Live Content add their worker code this way.lh_web_application_pass_variables_actionprints variables into the worker before those imports, andlh_web_application_open_service_workerruns before anything is printed.lh_web_application_precache_static_urls_filterfilters the static URLs precached on install.lh_web_application_static_max_age_days(default 180; 0 keeps files indefinitely) sets how long an unused static file stays cached,lh_web_application_images_max_entries(default 150) caps the images cache, andlh_web_application_pages_max_entries(default 300) caps the saved-pages cache. The start URL and the offline page are never dropped.- Imported worker scripts can listen for the
periodicsyncevent with the tagupdate, which the main script registers to fire at most once a day where the browser supports it. Wrap the work inevent.waitUntil(), or the browser may stop the worker before it finishes. - The worker turns on navigation preload, so page requests carry the
Service-Worker-Navigation-Preloadheader. A worker script that adds its ownfetchhandler for navigations should useevent.preloadResponserather than fetching again. - Themes can style two body classes the main script sets.
standaloneis present when the site runs as an installed app.lh_web_application-navigatingis set only in an installed app (standalone or fullscreen display mode, or an iOS home screen app), since a browser tab shows its own loading indicator. It is added when a link to another page here is tapped, a form is submitted or the Navigation API reports a navigation. It is removed when the load finishes or fails, when a page is restored from the back/forward cache, when only the anchor changes, or after 30 seconds. Use it for a loading indicator; the plugin draws nothing itself. - In an installed app on iPhone and iPad the plugin adds a floating Back button,
#lh_web_application-back, in the bottom left corner. It shows only while the Navigation API says there is a page to go back to. It slides away (classlh_web_application-back_tucked) while the visitor scrolls down or types. The body getslh_web_application-has_backwhile it shows. Its built-in styles use the id, so a theme’s general button rules do not reach it. Recolour it with--lh-web-application-back-background,--lh-web-application-back-color,--lh-web-application-back-borderand--lh-web-application-back-size, or restyle it with a rule naming the id. Thelh_web_application_back_buttonfilter picks where it appears:ios(default; Android has a system back button),standalone(any installed app) ornone. - The plugin prints the only viewport tag on the page (
viewport-fit=cover) and removes the one core adds for block templates, soenv(safe-area-inset-*)works in an installed app. lh_web_application_return_ios_startup_idfilters the iOS startup image attachment.lh_web_application_apple_startup_sizesfilters the iOS startup image sizes. Each entry has the imagewidthandheightin pixels and themediaquery that picks it, so a new iPhone can be added without a release.lh_web_application_init_plugin: return false to stop the plugin loading without deactivating it.- The worker gets
admin_ajax_return_wp_nonce, the URL of thereturn_wp_nonceadmin-ajax action. It returns awp_restnonce for the visitor as a JSON string, which worker scripts send asX-WP-Noncebecause a service worker has no page to read one from. - The install sheet,
dialog#lh_web_application-install, is printed in the footer of every page and slides up from the bottom when opened. It is opened by the Install App menu item (with LH Javascript Menu Items active), by any element with adata-lh-web-application-installattribute (its value is reported as the trigger), and once by itself on a phone from the third visit for the audience chosen in the Install prompt setting. Its steps follow the device: the browser’s own install prompt where one is offered, Share then Add to Home Screen on iPhone and iPad, the browser menu on other Android browsers, File then Add to Dock in Safari on a Mac. Its styles use the id; recolour it with--lh-web-application-install-background,--lh-web-application-install-color,--lh-web-application-install-accentand--lh-web-application-install-accent-color. - Install sheet filters:
lh_web_application_install_prompt_audience(members,everyoneornone),lh_web_application_install_reason(the line under the heading),lh_web_application_install_prompt_visits(default 3),lh_web_application_install_prompt_snooze_days(default 30),lh_web_application_install_sheet_htmlandlh_web_application_install_sheet_css. Closing the sheet snoozes it in the browser and, for a signed-in member, in the user optionlh_web_application-install_snoozed_untilfor that site; installing the app snoozes it for five years. - The sheet fires
lh_web_application:install_shown,lh_web_application:install_dismissed,lh_web_application:install_acceptedandlh_web_application:app_installedonwindow, withdetail.trigger(menu,autoor the attribute’s value) anddetail.platform, for analytics plugins to record. The plugin records nothing itself. - The
shortcode shows its content only where the app can be installed (body classlh_web_application-prompt_stashed).