diff --git a/pwa.php b/pwa.php index 5b909da62..dccd69fe7 100644 --- a/pwa.php +++ b/pwa.php @@ -275,3 +275,4 @@ function _pwa_deactivate_plugin() { $wp_web_app_manifest->init(); require_once PWA_PLUGIN_DIR . '/wp-admin/options-reading-offline-browsing.php'; +require_once PWA_PLUGIN_DIR . '/wp-admin/options-web-app-manifest-display.php'; diff --git a/tests/test-class-wp-web-app-manifest.php b/tests/test-class-wp-web-app-manifest.php index 6575f5bf4..f779ceeed 100644 --- a/tests/test-class-wp-web-app-manifest.php +++ b/tests/test-class-wp-web-app-manifest.php @@ -266,6 +266,14 @@ public function test_get_manifest() { ); $this->assertEquals( $expected_manifest, $actual_manifest ); + // Update display. + update_option( 'web_app_manifest_display', 'standalone' ); + + $actual_manifest = $this->instance->get_manifest(); + $expected_manifest['display'] = 'standalone'; + + $this->assertEquals( $expected_manifest, $actual_manifest ); + // Check that icon purpose is `any maskable` if site icon is maskable. $actual_manifest = $this->instance->get_manifest(); $this->assertEquals( $expected_manifest, $actual_manifest ); diff --git a/wp-admin/options-web-app-manifest-display.php b/wp-admin/options-web-app-manifest-display.php new file mode 100644 index 000000000..7cd1acb88 --- /dev/null +++ b/wp-admin/options-web-app-manifest-display.php @@ -0,0 +1,71 @@ + 'string', + 'sanitize_callback' => 'sanitize_text_field', + ) + ); +} +add_action( 'init', __NAMESPACE__ . '\register_web_app_manifest_display_setting' ); + +/** + * Register web app manifest display setting field. + */ +function add_web_app_manifest_display_setting_field() { + add_settings_field( + 'web_app_manifest_display', + __( 'Display', 'pwa' ), + __NAMESPACE__ . '\render_web_app_manifest_display_setting_field', + 'reading' + ); +} +add_action( 'admin_init', __NAMESPACE__ . '\add_web_app_manifest_display_setting_field' ); + +/** + * Render web app manifest display setting field. + */ +function render_web_app_manifest_display_setting_field() { + // See: . + $allowed_values = array( 'fullscreen', 'standalone', 'minimal-ui', 'browser' ); + + ?> +
+ + + + + + +

+ MDN documentation for more information.', 'pwa' ), + array( 'a' => array_fill_keys( array( 'href', 'rel', 'target' ), true ) ) + ); + ?> +

+
+ html_entity_decode( get_bloginfo( 'name' ), ENT_QUOTES, 'utf-8' ), 'start_url' => home_url( '/' ), - 'display' => 'minimal-ui', + 'display' => get_option( 'web_app_manifest_display', 'minimal-ui' ), 'dir' => is_rtl() ? 'rtl' : 'ltr', );