Skip to content

Commit

Permalink
Unhook both Gutenberg and core hooks for deleting site logo
Browse files Browse the repository at this point in the history
  • Loading branch information
stacimc committed Sep 24, 2021
1 parent 50cf885 commit 0140ba0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/block-library/src/site-logo/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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' );
}
Expand All @@ -168,13 +168,23 @@ 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' );
}
Expand Down

0 comments on commit 0140ba0

Please sign in to comment.