Changeset 51422 for branches/5.8/src/wp-includes/blocks/site-logo.php
- Timestamp:
- 07/13/2021 05:13:48 PM (4 years ago)
- Location:
- branches/5.8
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/blocks/site-logo.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/5.8
-
branches/5.8/src/wp-includes/blocks/site-logo.php
r51091 r51422 15 15 function render_block_core_site_logo( $attributes ) { 16 16 $adjust_width_height_filter = function ( $image ) use ( $attributes ) { 17 if ( empty( $attributes['width'] ) ) {17 if ( empty( $attributes['width'] ) || empty( $image ) ) { 18 18 return $image; 19 19 } … … 112 112 * Updates the site_logo option when the custom_logo theme-mod gets updated. 113 113 * 114 * This function is hooked on "update_option_theme_mods_$theme" and not 115 * "pre_set_theme_mod_custom_logo" because by hooking in `update_option` 116 * the function accounts for remove_theme_mod() as well. 117 * 118 * @param mixed $old_value The old option value. 119 * @param mixed $value The new option value. 114 * @param mixed $value Attachment ID of the custom logo or an empty value. 115 * @return mixed 120 116 */ 121 function _sync_custom_logo_to_site_logo( $old_value, $value ) { 122 // Delete the option when the custom logo does not exist or was removed. 123 // This step ensures the option stays in sync. 124 if ( empty( $value['custom_logo'] ) ) { 117 function _sync_custom_logo_to_site_logo( $value ) { 118 if ( empty( $value ) ) { 125 119 delete_option( 'site_logo' ); 126 120 } else { 127 remove_action( 'update_option_site_logo', '_sync_site_logo_to_custom_logo' ); 128 update_option( 'site_logo', $value['custom_logo'] ); 129 add_action( 'update_option_site_logo', '_sync_site_logo_to_custom_logo', 10, 2 ); 121 update_option( 'site_logo', $value ); 122 } 123 124 return $value; 125 } 126 127 add_filter( 'pre_set_theme_mod_custom_logo', '_sync_custom_logo_to_site_logo' ); 128 129 /** 130 * Deletes the site_logo when the custom_logo theme mod is removed. 131 * 132 * @param array $old_value Previous theme mod settings. 133 * @param array $value Updated theme mod settings. 134 */ 135 function _delete_site_logo_on_remove_custom_logo( $old_value, $value ) { 136 // If the custom_logo is being unset, it's being removed from theme mods. 137 if ( isset( $old_value['custom_logo'] ) && ! isset( $value['custom_logo'] ) ) { 138 delete_option( 'site_logo' ); 130 139 } 131 140 } 132 141 133 142 /** 134 * Hooks `_sync_custom_logo_to_site_logo` in `update_option_theme_mods_$theme`. 143 * Deletes the site logo when all theme mods are being removed. 144 */ 145 function _delete_site_logo_on_remove_theme_mods() { 146 if ( false !== get_theme_support( 'custom-logo' ) ) { 147 delete_option( 'site_logo' ); 148 } 149 } 150 151 /** 152 * Hooks `_delete_site_logo_on_remove_custom_logo` in `update_option_theme_mods_$theme`. 153 * Hooks `_delete_site_logo_on_remove_theme_mods` in `delete_option_theme_mods_$theme`. 135 154 * 136 155 * Runs on `setup_theme` to account for dynamically-switched themes in the Customizer. 137 156 */ 138 function _ sync_custom_logo_to_site_logo_on_setup_theme() {157 function _delete_site_logo_on_remove_custom_logo_on_setup_theme() { 139 158 $theme = get_option( 'stylesheet' ); 140 add_action( "update_option_theme_mods_$theme", '_sync_custom_logo_to_site_logo', 10, 2 ); 159 add_action( "update_option_theme_mods_$theme", '_delete_site_logo_on_remove_custom_logo', 10, 2 ); 160 add_action( "delete_option_theme_mods_$theme", '_delete_site_logo_on_remove_theme_mods' ); 141 161 } 142 add_action( 'setup_theme', '_sync_custom_logo_to_site_logo_on_setup_theme', 11 ); 143 144 /** 145 * Updates the custom_logo theme-mod when the site_logo option gets updated. 146 * 147 * @param mixed $old_value The old option value. 148 * @param mixed $value The new option value. 149 * 150 * @return void 151 */ 152 function _sync_site_logo_to_custom_logo( $old_value, $value ) { 153 // Delete the option when the custom logo does not exist or was removed. 154 // This step ensures the option stays in sync. 155 if ( empty( $value ) ) { 156 remove_theme_mod( 'custom_logo' ); 157 } else { 158 remove_filter( 'pre_set_theme_mod_custom_logo', '_sync_custom_logo_to_site_logo' ); 159 set_theme_mod( 'custom_logo', $value ); 160 add_filter( 'pre_set_theme_mod_custom_logo', '_sync_custom_logo_to_site_logo' ); 161 } 162 } 163 164 add_action( 'update_option_site_logo', '_sync_site_logo_to_custom_logo', 10, 2 ); 162 add_action( 'setup_theme', '_delete_site_logo_on_remove_custom_logo_on_setup_theme', 11 );
Note: See TracChangeset
for help on using the changeset viewer.