From a090aa6c10db7aac6c462ab3a224d6ff17b5cea8 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 14 May 2023 19:46:21 +0530 Subject: [PATCH 1/4] Add settings field in reading page for web app manifest diplay member --- wp-admin/options-web-app-manifest-display.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 wp-admin/options-web-app-manifest-display.php 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 ) ) + ); + ?> +

+
+ Date: Sun, 14 May 2023 19:46:59 +0530 Subject: [PATCH 2/4] Update main plugin file to include web app manifest display setting --- pwa.php | 1 + 1 file changed, 1 insertion(+) 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'; From 34861aa89627095f97c6495a49fe894395a63f3f Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 14 May 2023 19:48:10 +0530 Subject: [PATCH 3/4] Update get_manifest() to read display setting from `web_app_manifest_display` option --- wp-includes/class-wp-web-app-manifest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-includes/class-wp-web-app-manifest.php b/wp-includes/class-wp-web-app-manifest.php index c3045e737..d1759a495 100644 --- a/wp-includes/class-wp-web-app-manifest.php +++ b/wp-includes/class-wp-web-app-manifest.php @@ -203,7 +203,7 @@ public function get_manifest() { $manifest = array( 'name' => 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', ); From 39805fe14094379753afca7de8f7dff7a8846ac3 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Sun, 14 May 2023 20:07:59 +0530 Subject: [PATCH 4/4] Add tests for web app manifest display setting --- tests/test-class-wp-web-app-manifest.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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 );