From c3e0fb78de4ddacaf70f33f4bb5a7f45d029ea81 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Wed, 5 May 2021 10:52:05 -0500 Subject: [PATCH 1/4] Site Logo: Rename sitelogo to site_logo --- packages/block-library/src/site-logo/edit.js | 10 +++++----- packages/block-library/src/site-logo/index.php | 14 +++++++------- .../src/components/entities-saved-states/index.js | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index 9bd1d5eba276eb..3f9ed0c72e4a71 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -233,7 +233,7 @@ export default function LogoEdit( { const [ logoUrl, setLogoUrl ] = useState(); const [ error, setError ] = useState(); const ref = useRef(); - const { mediaItemData, sitelogo, url } = useSelect( ( select ) => { + const { mediaItemData, siteLogo, url } = useSelect( ( select ) => { const siteSettings = select( coreStore ).getEditedEntityRecord( 'root', 'site' @@ -241,14 +241,14 @@ export default function LogoEdit( { const mediaItem = select( coreStore ).getEntityRecord( 'root', 'media', - siteSettings.sitelogo + siteSettings.site_logo ); return { mediaItemData: mediaItem && { url: mediaItem.source_url, alt: mediaItem.alt_text, }, - sitelogo: siteSettings.sitelogo, + siteLogo: siteSettings.site_logo, url: siteSettings.url, }; }, [] ); @@ -256,7 +256,7 @@ export default function LogoEdit( { const { editEntityRecord } = useDispatch( coreStore ); const setLogo = ( newValue ) => editEntityRecord( 'root', 'site', undefined, { - sitelogo: newValue, + site_logo: newValue, } ); let alt = null; @@ -301,7 +301,7 @@ export default function LogoEdit( { const label = __( 'Site Logo' ); let logoImage; - if ( sitelogo === undefined ) { + if ( siteLogo === undefined ) { logoImage = ; } diff --git a/packages/block-library/src/site-logo/index.php b/packages/block-library/src/site-logo/index.php index f14feb0cb07a8f..db2d85d11de943 100644 --- a/packages/block-library/src/site-logo/index.php +++ b/packages/block-library/src/site-logo/index.php @@ -66,8 +66,8 @@ function register_block_core_site_logo() { * @return string The site logo if set. */ function override_custom_logo_theme_mod( $custom_logo ) { - $sitelogo = get_option( 'sitelogo' ); - return false === $sitelogo ? $custom_logo : $sitelogo; + $site_logo = get_option( 'site_logo' ); + return false === $site_logo ? $custom_logo : $site_logo; } /** @@ -81,9 +81,9 @@ function sync_site_logo_to_theme_mod( $custom_logo ) { // Delete the option when the custom logo does not exist or was removed. // This step ensures the option stays in sync. if ( empty( $custom_logo ) ) { - delete_option( 'sitelogo' ); + delete_option( 'site_logo' ); } else { - update_option( 'sitelogo', $custom_logo ); + update_option( 'site_logo', $custom_logo ); } return $custom_logo; } @@ -94,12 +94,12 @@ function sync_site_logo_to_theme_mod( $custom_logo ) { function register_block_core_site_logo_setting() { register_setting( 'general', - 'sitelogo', + 'site_logo', array( 'show_in_rest' => array( - 'name' => 'sitelogo', + 'name' => 'site_logo', ), - 'type' => 'string', + 'type' => 'integer', 'description' => __( 'Site logo.' ), ) ); diff --git a/packages/editor/src/components/entities-saved-states/index.js b/packages/editor/src/components/entities-saved-states/index.js index 32dc24a6c6e08f..af233aec56f264 100644 --- a/packages/editor/src/components/entities-saved-states/index.js +++ b/packages/editor/src/components/entities-saved-states/index.js @@ -22,7 +22,7 @@ import EntityTypeList from './entity-type-list'; const TRANSLATED_SITE_PROTPERTIES = { title: __( 'Title' ), description: __( 'Tagline' ), - sitelogo: __( 'Logo' ), + site_logo: __( 'Logo' ), show_on_front: __( 'Show on front' ), page_on_front: __( 'Page on front' ), }; From a75ca1499eeb855436b78dba0c3a00fca50196d7 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Wed, 5 May 2021 11:02:38 -0500 Subject: [PATCH 2/4] Set logo id as integer --- 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 3f9ed0c72e4a71..42c84cf67f7c4e 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -280,7 +280,7 @@ export default function LogoEdit( { return; } - setLogo( media.id.toString() ); + setLogo( media.id ); }; const onUploadError = ( message ) => { From 34ae3df4c86abaf15adb9d7d25f58f2b6fd3cfc5 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Wed, 5 May 2021 11:12:40 -0500 Subject: [PATCH 3/4] Use null for empty state values --- packages/block-library/src/site-logo/edit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/site-logo/edit.js b/packages/block-library/src/site-logo/edit.js index 42c84cf67f7c4e..cb777090ae9c3b 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -274,8 +274,8 @@ export default function LogoEdit( { if ( ! media.id && media.url ) { // This is a temporary blob image - setLogo( '' ); - setError(); + setLogo( null ); + setError( null ); setLogoUrl( media.url ); return; } From 65a9978939eb11ac8b81359370cb21f6d5c83d91 Mon Sep 17 00:00:00 2001 From: Grant Kinney Date: Wed, 5 May 2021 11:19:08 -0500 Subject: [PATCH 4/4] Use undefined for empty logo to prevent API request --- 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 cb777090ae9c3b..6e7dcf41671c98 100644 --- a/packages/block-library/src/site-logo/edit.js +++ b/packages/block-library/src/site-logo/edit.js @@ -274,7 +274,7 @@ export default function LogoEdit( { if ( ! media.id && media.url ) { // This is a temporary blob image - setLogo( null ); + setLogo( undefined ); setError( null ); setLogoUrl( media.url ); return;