if ( empty( $custom_logo ) ) { return ''; // Return early if no custom logo is set, avoiding extraneous wrapper div. }
if ( ! $attributes['isLink'] ) { // Remove the link. $custom_logo = preg_replace( '#<a.*?>(.*?)</a>#i', '\1', $custom_logo ); }
if ( $attributes['isLink'] && '_blank' === $attributes['linkTarget'] ) { // Add the link target after the rel="home". // Add an aria-label for informing that the page opens in a new tab. $processor = new WP_HTML_Tag_Processor( $custom_logo ); $processor->next_tag( 'a' ); if ( 'home' === $processor->get_attribute( 'rel' ) ) { $processor->set_attribute( 'aria-label', __( '(Home link, opens in a new tab)' ) ); $processor->set_attribute( 'target', $attributes['linkTarget'] ); } $custom_logo = $processor->get_updated_html(); }
/** * Overrides the custom logo with a site logo, if the option is set. * * @since 5.8.0 * * @param string $custom_logo The custom logo set by a theme. * * @return string The site logo if set. */ function _override_custom_logo_theme_mod( $custom_logo ) { $site_logo = get_option( 'site_logo' ); return false === $site_logo ? $custom_logo : $site_logo; }
/** * Deletes the site_logo when the custom_logo theme mod is removed. * * @since 5.8.0 * * @global array $_ignore_site_logo_changes * * @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 ) { global $_ignore_site_logo_changes;
if ( $_ignore_site_logo_changes ) { return; }
// 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' ); } }
/** * Deletes the site logo when all theme mods are being removed. * * @since 5.8.0 * * @global array $_ignore_site_logo_changes */ function _delete_site_logo_on_remove_theme_mods() { global $_ignore_site_logo_changes;
/** * Hooks `_delete_site_logo_on_remove_custom_logo` in `update_option_theme_mods_$theme`. * Hooks `_delete_site_logo_on_remove_theme_mods` in `delete_option_theme_mods_$theme`. * * Runs on `setup_theme` to account for dynamically-switched themes in the Customizer. * * @since 5.8.0 */ function _delete_site_logo_on_remove_custom_logo_on_setup_theme() { $theme = get_option( 'stylesheet' ); 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( '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. * * @since 5.9.0 * * @global array $_ignore_site_logo_changes */ function _delete_custom_logo_on_remove_site_logo() { global $_ignore_site_logo_changes;
// Prevent _delete_site_logo_on_remove_custom_logo and // _delete_site_logo_on_remove_theme_mods from firing and causing an // infinite loop. $_ignore_site_logo_changes = true;
// Remove the custom logo. remove_theme_mod( 'custom_logo' );