From 6a42985af092d4abdc3f4585864cb8e08f9c7e5d Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 21 Apr 2022 20:59:25 +0530 Subject: [PATCH 1/5] Add active_callback for maskable icon setting * Hide the maskable icon setting if site icon is not set --- wp-includes/class-wp-customize-manager.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index 368d2b8cc..cc01b5fcc 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -35,10 +35,13 @@ function pwa_customize_register_site_icon_maskable( WP_Customize_Manager $wp_cus $wp_customize->add_control( 'site_icon_maskable', array( - 'type' => 'checkbox', - 'section' => 'title_tagline', - 'label' => __( 'Maskable icon', 'pwa' ), - 'priority' => $site_icon_control->priority + 1, + 'type' => 'checkbox', + 'section' => 'title_tagline', + 'label' => __( 'Maskable icon', 'pwa' ), + 'priority' => $site_icon_control->priority + 1, + 'active_callback' => function() use ( $wp_customize ) { + return (bool) $wp_customize->get_setting( 'site_icon' )->value(); + }, ) ); } From 7f748062515854f3ec0bfd5d54e4e63ae066c69a Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Thu, 21 Apr 2022 20:59:53 +0530 Subject: [PATCH 2/5] Update logic to bind site icon setting with maskable icon's * Set maskable icon value to false if site icon is not set. --- wp-admin/js/customize-controls-site-icon-pwa.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wp-admin/js/customize-controls-site-icon-pwa.js b/wp-admin/js/customize-controls-site-icon-pwa.js index 7c00bd94b..8405bbd76 100644 --- a/wp-admin/js/customize-controls-site-icon-pwa.js +++ b/wp-admin/js/customize-controls-site-icon-pwa.js @@ -31,6 +31,13 @@ wp.customize( // Update active state whenever the site_icon setting changes. siteIconSetting.bind(updateActive); + // Change the site_icon_maskable if site_icon is not set. + siteIconSetting.bind((newSiteIconValue) => { + if (!newSiteIconValue) { + siteIconMaskableSetting(false); + } + }); + /** * Validate site icons for its presence and size. */ From 4136f52d26f20cff7822e44a7127052758f9e30b Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 22 Apr 2022 17:39:26 -0700 Subject: [PATCH 3/5] Opt to fully control siteIconMaskable.active value client-side --- wp-admin/js/customize-controls-site-icon-pwa.js | 3 +++ wp-includes/class-wp-customize-manager.php | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wp-admin/js/customize-controls-site-icon-pwa.js b/wp-admin/js/customize-controls-site-icon-pwa.js index 8405bbd76..03876669a 100644 --- a/wp-admin/js/customize-controls-site-icon-pwa.js +++ b/wp-admin/js/customize-controls-site-icon-pwa.js @@ -18,6 +18,9 @@ wp.customize( ); }; + // Force the value to always correspond to whether the site icon is present, disregarding server control. + siteIconMaskableControl.active.validate = hasSiteIcon; + /** * Toggle site icon maskable active state based on whether the site icon is set. */ diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index cc01b5fcc..368d2b8cc 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -35,13 +35,10 @@ function pwa_customize_register_site_icon_maskable( WP_Customize_Manager $wp_cus $wp_customize->add_control( 'site_icon_maskable', array( - 'type' => 'checkbox', - 'section' => 'title_tagline', - 'label' => __( 'Maskable icon', 'pwa' ), - 'priority' => $site_icon_control->priority + 1, - 'active_callback' => function() use ( $wp_customize ) { - return (bool) $wp_customize->get_setting( 'site_icon' )->value(); - }, + 'type' => 'checkbox', + 'section' => 'title_tagline', + 'label' => __( 'Maskable icon', 'pwa' ), + 'priority' => $site_icon_control->priority + 1, ) ); } From cee31952bfdd0354fa4df982baa67fd51779dd06 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 22 Apr 2022 17:41:19 -0700 Subject: [PATCH 4/5] Revert "Opt to fully control siteIconMaskable.active value client-side" This reverts commit 4136f52d26f20cff7822e44a7127052758f9e30b. --- wp-admin/js/customize-controls-site-icon-pwa.js | 3 --- wp-includes/class-wp-customize-manager.php | 11 +++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wp-admin/js/customize-controls-site-icon-pwa.js b/wp-admin/js/customize-controls-site-icon-pwa.js index 03876669a..8405bbd76 100644 --- a/wp-admin/js/customize-controls-site-icon-pwa.js +++ b/wp-admin/js/customize-controls-site-icon-pwa.js @@ -18,9 +18,6 @@ wp.customize( ); }; - // Force the value to always correspond to whether the site icon is present, disregarding server control. - siteIconMaskableControl.active.validate = hasSiteIcon; - /** * Toggle site icon maskable active state based on whether the site icon is set. */ diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index 368d2b8cc..cc01b5fcc 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -35,10 +35,13 @@ function pwa_customize_register_site_icon_maskable( WP_Customize_Manager $wp_cus $wp_customize->add_control( 'site_icon_maskable', array( - 'type' => 'checkbox', - 'section' => 'title_tagline', - 'label' => __( 'Maskable icon', 'pwa' ), - 'priority' => $site_icon_control->priority + 1, + 'type' => 'checkbox', + 'section' => 'title_tagline', + 'label' => __( 'Maskable icon', 'pwa' ), + 'priority' => $site_icon_control->priority + 1, + 'active_callback' => function() use ( $wp_customize ) { + return (bool) $wp_customize->get_setting( 'site_icon' )->value(); + }, ) ); } From d19d86e8a54ac9d23ac77873d5b963424b0b345a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 22 Apr 2022 17:59:14 -0700 Subject: [PATCH 5/5] Split up 'any maskable' into separate icon entries --- tests/test-class-wp-web-app-manifest.php | 49 ++++++++++++++++++----- wp-includes/class-wp-web-app-manifest.php | 14 ++++--- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/tests/test-class-wp-web-app-manifest.php b/tests/test-class-wp-web-app-manifest.php index 4d554ebad..31235ee47 100644 --- a/tests/test-class-wp-web-app-manifest.php +++ b/tests/test-class-wp-web-app-manifest.php @@ -245,6 +245,7 @@ public function test_get_manifest() { $this->mock_site_icon(); $blogname = 'PWA & Test "First" and \'second\' and “third”'; update_option( 'blogname', $blogname ); + update_option( 'site_icon_maskable', false ); $actual_manifest = $this->instance->get_manifest(); // Verify that there are now entities. @@ -264,16 +265,41 @@ public function test_get_manifest() { $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 ); + $purposes = array(); + foreach ( $actual_manifest['icons'] as $icon ) { + if ( ! isset( $purposes[ $icon['purpose'] ] ) ) { + $purposes[ $icon['purpose'] ] = 0; + } else { + $purposes[ $icon['purpose'] ]++; + } + } + $this->assertEquals( + array( + 'any' => 1, + ), + $purposes + ); + + // Make sure maskable is properly checked. update_option( 'site_icon_maskable', true ); - $actual_manifest = $this->instance->get_manifest(); - $expected_manifest['icons'] = array_map( - function ( $icon ) { - $icon['purpose'] = 'any maskable'; - return $icon; - }, - $expected_manifest['icons'] + $actual_manifest = $this->instance->get_manifest(); + $purposes = array(); + foreach ( $actual_manifest['icons'] as $icon ) { + if ( ! isset( $purposes[ $icon['purpose'] ] ) ) { + $purposes[ $icon['purpose'] ] = 0; + } else { + $purposes[ $icon['purpose'] ]++; + } + } + $this->assertEquals( + array( + 'any' => 1, + 'maskable' => 1, + ), + $purposes ); - $this->assertEquals( $expected_manifest, $actual_manifest ); // Check that long names do not automatically copy to short name. $blogname = str_repeat( 'x', 13 ); @@ -482,9 +508,10 @@ public function test_get_icons() { $expected_icons = array(); foreach ( $this->instance->default_manifest_icon_sizes as $size ) { $expected_icons[] = array( - 'src' => $this->expected_site_icon_img_url, - 'sizes' => sprintf( '%1$dx%1$d', $size ), - 'type' => self::MIME_TYPE, + 'src' => $this->expected_site_icon_img_url, + 'sizes' => sprintf( '%1$dx%1$d', $size ), + 'type' => self::MIME_TYPE, + 'purpose' => 'any', ); } $this->assertEquals( $expected_icons, $this->instance->get_icons() ); diff --git a/wp-includes/class-wp-web-app-manifest.php b/wp-includes/class-wp-web-app-manifest.php index e76e82f0c..ddbee7aac 100644 --- a/wp-includes/class-wp-web-app-manifest.php +++ b/wp-includes/class-wp-web-app-manifest.php @@ -504,16 +504,18 @@ public function get_icons() { $src = get_site_icon_url( $size ); if ( $src ) { $icon = array( - 'src' => $src, - 'sizes' => sprintf( '%1$dx%1$d', $size ), - 'type' => $mime_type, + 'purpose' => 'any', + 'src' => $src, + 'sizes' => sprintf( '%1$dx%1$d', $size ), + 'type' => $mime_type, ); + $icons[] = $icon; + if ( $maskable ) { - $icon['purpose'] = 'any maskable'; + $icon['purpose'] = 'maskable'; + $icons[] = $icon; } - - $icons[] = $icon; } } return $icons;