From 0112f943ed957549e7b4b94929666c7c3b89d957 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Tue, 14 Sep 2021 11:32:13 -0700 Subject: [PATCH 01/10] Add button for removing Site Logo image from block --- packages/block-library/src/site-logo/edit.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index f28145b428adfd..c820967b5b239c 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -326,7 +326,7 @@ export default function LogoEdit( { const _siteLogo = siteSettings?.site_logo; const _readOnlyLogo = siteData?.site_logo; const _canUserEdit = canUser( 'update', 'settings' ); - const _siteLogoId = _siteLogo || _readOnlyLogo; + const _siteLogoId = _canUserEdit ? _siteLogo : _readOnlyLogo; const mediaItem = _siteLogoId && select( coreStore ).getMedia( _siteLogoId, { @@ -380,6 +380,11 @@ export default function LogoEdit( { setLogo( media.id ); }; + const onRemoveLogo = () => { + setLogo( null ); + setLogoUrl( undefined ); + }; + const onUploadError = ( message ) => { setError( message[ 2 ] ? message[ 2 ] : null ); }; @@ -393,6 +398,9 @@ export default function LogoEdit( { onSelect={ onSelectLogo } onError={ onUploadError } /> + + { __( 'Remove' ) } + ); From 6e1ef4bc8d1fffb82b94addc6b536b3a665001c0 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Wed, 15 Sep 2021 16:15:54 -0700 Subject: [PATCH 02/10] Try an icon instead of text button for Remove --- packages/block-library/src/site-logo/edit.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index c820967b5b239c..dd8c637a53d2dd 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -398,9 +398,7 @@ export default function LogoEdit( { onSelect={ onSelectLogo } onError={ onUploadError } /> - - { __( 'Remove' ) } - + ); From 9e88ec2dfdea7ad2d898c1474cb93e0c0eb3db92 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Wed, 15 Sep 2021 16:16:12 -0700 Subject: [PATCH 03/10] Delete custom logo when site logo is removed --- .../block-library/src/site-logo/index.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/block-library/src/site-logo/index.php b/packages/block-library/src/site-logo/index.php index ef24e73e1e2180..be24b671176b64 100644 --- a/packages/block-library/src/site-logo/index.php +++ b/packages/block-library/src/site-logo/index.php @@ -160,3 +160,25 @@ function _delete_site_logo_on_remove_custom_logo_on_setup_theme() { add_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); } add_action( 'setup_theme', '_delete_site_logo_on_remove_custom_logo_on_setup_theme', 11 ); + +/** + * Removes the custom_logo theme-mod when the site_logo option gets deleted. + * + * @param mixed $old_value The old option value. + * @param mixed $value The new option value. + * + * @return void + */ +function _delete_custom_logo_on_remove_site_logo() { + // Unhook update and delete actions for custom_logo to prevent a loop of hooks. + remove_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10 ); + remove_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); + + // Remove the custom logo + remove_theme_mod( 'custom_logo' ); + + // Restore update and delete actions. + add_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10, 2 ); + add_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); +} +add_action( 'delete_option_site_logo', '_delete_custom_logo_on_remove_site_logo' ); From 5e19c9b61df7fdbb57c44853a580ff455d17cf01 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Wed, 15 Sep 2021 16:40:18 -0700 Subject: [PATCH 04/10] Linting --- packages/block-library/src/site-logo/index.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/site-logo/index.php b/packages/block-library/src/site-logo/index.php index be24b671176b64..6c0646621c323a 100644 --- a/packages/block-library/src/site-logo/index.php +++ b/packages/block-library/src/site-logo/index.php @@ -163,18 +163,15 @@ function _delete_site_logo_on_remove_custom_logo_on_setup_theme() { /** * Removes the custom_logo theme-mod when the site_logo option gets deleted. - * - * @param mixed $old_value The old option value. - * @param mixed $value The new option value. - * - * @return void */ function _delete_custom_logo_on_remove_site_logo() { + $theme = get_option( 'stylesheet' ); + // Unhook update and delete actions for custom_logo to prevent a loop of hooks. remove_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10 ); remove_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); - // Remove the custom logo + // Remove the custom logo. remove_theme_mod( 'custom_logo' ); // Restore update and delete actions. From a22c50777b04197be3795f29905455ebb6b472a4 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Fri, 17 Sep 2021 15:47:39 -0700 Subject: [PATCH 05/10] Add label to remove logo button --- packages/block-library/src/site-logo/edit.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index dd8c637a53d2dd..01e986a9332f61 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -398,7 +398,11 @@ export default function LogoEdit( { onSelect={ onSelectLogo } onError={ onUploadError } /> - + ); From 49e7e78306510771247c8a408d57516dd38cd310 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Mon, 20 Sep 2021 11:01:38 -0700 Subject: [PATCH 06/10] Revert to text-based Remove button --- packages/block-library/src/site-logo/edit.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index 01e986a9332f61..c820967b5b239c 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -398,11 +398,9 @@ export default function LogoEdit( { onSelect={ onSelectLogo } onError={ onUploadError } /> - + + { __( 'Remove' ) } + ); From af1194a302ad604bf6411773839af272a0baa281 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Mon, 20 Sep 2021 11:14:39 -0700 Subject: [PATCH 07/10] Slightly increase spacing between Replace and Remove buttons --- packages/block-library/src/site-logo/edit.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index c820967b5b239c..89b2b426c01a43 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -18,6 +18,7 @@ import { Spinner, ToggleControl, ToolbarButton, + ToolbarGroup, Placeholder, } from '@wordpress/components'; import { useViewportMatch } from '@wordpress/compose'; @@ -398,9 +399,11 @@ export default function LogoEdit( { onSelect={ onSelectLogo } onError={ onUploadError } /> - - { __( 'Remove' ) } - + + + { __( 'Remove' ) } + + ); From 50cf885d6333f679cd1d3562b5fe2aba9e3bf754 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Wed, 22 Sep 2021 11:33:08 -0700 Subject: [PATCH 08/10] Change 'Remove' to 'Reset' to avoid confusion --- packages/block-library/src/site-logo/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index 89b2b426c01a43..ff6e93ee02a8d4 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -401,7 +401,7 @@ export default function LogoEdit( { /> - { __( 'Remove' ) } + { __( 'Reset' ) } From 0140ba09a38367bc02215db081b3fb83ff477e25 Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Fri, 24 Sep 2021 11:53:56 -0700 Subject: [PATCH 09/10] Unhook both Gutenberg and core hooks for deleting site logo --- packages/block-library/src/site-logo/index.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/site-logo/index.php b/packages/block-library/src/site-logo/index.php index 6c0646621c323a..7e67656779b839 100644 --- a/packages/block-library/src/site-logo/index.php +++ b/packages/block-library/src/site-logo/index.php @@ -132,7 +132,7 @@ function _sync_custom_logo_to_site_logo( $value ) { * @param array $old_value Previous theme mod settings. * @param array $value Updated theme mod settings. */ -function _delete_site_logo_on_remove_custom_logo( $old_value, $value ) { +function _gutenberg_delete_site_logo_on_remove_custom_logo( $old_value, $value ) { // If the custom_logo is being unset, it's being removed from theme mods. if ( isset( $old_value['custom_logo'] ) && ! isset( $value['custom_logo'] ) ) { delete_option( 'site_logo' ); @@ -142,7 +142,7 @@ function _delete_site_logo_on_remove_custom_logo( $old_value, $value ) { /** * Deletes the site logo when all theme mods are being removed. */ -function _delete_site_logo_on_remove_theme_mods() { +function _gutenberg_delete_site_logo_on_remove_theme_mods() { if ( false !== get_theme_support( 'custom-logo' ) ) { delete_option( 'site_logo' ); } @@ -168,6 +168,11 @@ function _delete_custom_logo_on_remove_site_logo() { $theme = get_option( 'stylesheet' ); // Unhook update and delete actions for custom_logo to prevent a loop of hooks. + // Gutenberg hooks + remove_action( "update_option_theme_mods_$theme", '_gutenberg_delete_site_logo_on_remove_custom_logo', 10 ); + remove_action( "delete_option_theme_mods_$theme", '_gutenberg_delete_site_logo_on_remove_theme_mods' ); + + // Core hooks remove_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10 ); remove_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); @@ -175,6 +180,11 @@ function _delete_custom_logo_on_remove_site_logo() { remove_theme_mod( 'custom_logo' ); // Restore update and delete actions. + // Gutenberg hooks + add_action( "update_option_theme_mods_$theme", '_gutenberg_delete_site_logo_on_remove_custom_logo', 10, 2 ); + add_action( "delete_option_theme_mods_$theme", '_gutenberg_delete_site_logo_on_remove_theme_mods' ); + + // Core hooks add_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10, 2 ); add_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); } From 22fd747a80c9cac0485d6e510c8f99990ddbf03e Mon Sep 17 00:00:00 2001 From: Staci Cooper Date: Fri, 24 Sep 2021 12:06:38 -0700 Subject: [PATCH 10/10] Update comments --- packages/block-library/src/site-logo/index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/site-logo/index.php b/packages/block-library/src/site-logo/index.php index 7e67656779b839..374260186e650f 100644 --- a/packages/block-library/src/site-logo/index.php +++ b/packages/block-library/src/site-logo/index.php @@ -168,11 +168,11 @@ function _delete_custom_logo_on_remove_site_logo() { $theme = get_option( 'stylesheet' ); // Unhook update and delete actions for custom_logo to prevent a loop of hooks. - // Gutenberg hooks + // Remove Gutenberg hooks. remove_action( "update_option_theme_mods_$theme", '_gutenberg_delete_site_logo_on_remove_custom_logo', 10 ); remove_action( "delete_option_theme_mods_$theme", '_gutenberg_delete_site_logo_on_remove_theme_mods' ); - // Core hooks + // Remove Core hooks. remove_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10 ); remove_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); @@ -180,11 +180,11 @@ function _delete_custom_logo_on_remove_site_logo() { remove_theme_mod( 'custom_logo' ); // Restore update and delete actions. - // Gutenberg hooks + // Restore Gutenberg hooks. add_action( "update_option_theme_mods_$theme", '_gutenberg_delete_site_logo_on_remove_custom_logo', 10, 2 ); add_action( "delete_option_theme_mods_$theme", '_gutenberg_delete_site_logo_on_remove_theme_mods' ); - // Core hooks + // Restore Core hooks. add_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10, 2 ); add_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); }