-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Site Logo]: Add option to remove/clear logo from the block #34820
Changes from all commits
0112f94
6e1ef4b
9e88ec2
5e19c9b
a22c507
49e7e78
af1194a
50cf885
0140ba0
22fd747
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' ); | ||
} | ||
|
@@ -160,3 +160,32 @@ 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. | ||
*/ | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea adding this to avoid accidentally causing a loop of hooks. ✅ Tested that with this code in the Gutenberg plugin, by execution time For testing I added the following and inspected by
The results were: In Gutenberg plugin:
In Core:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gutenberg's build process is getting in the way here: because This means that the unprefixed Core hooks for the site logo block are not removed, and end up running with You can verify this with the following steps
Without changing the build process, we could make the relevant function names in this file different from core, and that would work around the issue... something like function gutenberg_delete_site_logo_on_remove_custom_logo( $old_value, $value ) { ...
function gutenberg_delete_site_logo_on_remove_theme_mods() { ...
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' );
// Remove the custom 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' );
}
add_action( 'delete_option_site_logo', '_delete_custom_logo_on_remove_site_logo' ); It's a little strange, as those functions will become prefixed with Another option would be to remove Because this file is included on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That explains how I missed it 😱 Thank you for checking this! I went with the first suggestion to rename the hooks in Gutenberg and unhook/rehook both. I'm a bit torn since I agree it's a little strange, but I think doing so actually makes the hook duplication clearer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That fixed the issue, thanks! |
||
// 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' ); | ||
|
||
// 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' ); | ||
|
||
// Remove the custom logo. | ||
remove_theme_mod( 'custom_logo' ); | ||
|
||
// Restore update and delete actions. | ||
// 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' ); | ||
|
||
// 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' ); | ||
Comment on lines
+188
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we should revert 0140ba0 and work around the issue with Gutenberg's build process in a different way. I'll open a PR to do this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix here: #36195 |
||
} | ||
add_action( 'delete_option_site_logo', '_delete_custom_logo_on_remove_site_logo' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't ideal because it means that, when these changes are merged into Core, that Core will have a function prefixed with
_gutenberg
.