wp/wp-includes/blocks/site-logo.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
--- a/wp/wp-includes/blocks/site-logo.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/blocks/site-logo.php	Fri Sep 05 18:40:08 2025 +0200
@@ -8,12 +8,14 @@
 /**
  * Renders the `core/site-logo` block on the server.
  *
+ * @since 5.8.0
+ *
  * @param array $attributes The block attributes.
  *
  * @return string The render.
  */
 function render_block_core_site_logo( $attributes ) {
-	$adjust_width_height_filter = function ( $image ) use ( $attributes ) {
+	$adjust_width_height_filter = static function ( $image ) use ( $attributes ) {
 		if ( empty( $attributes['width'] ) || empty( $image ) || ! $image[1] || ! $image[2] ) {
 			return $image;
 		}
@@ -39,8 +41,13 @@
 	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.
-		$aria_label  = 'aria-label="' . esc_attr__( '(Home link, opens in a new tab)' ) . '"';
-		$custom_logo = str_replace( 'rel="home"', 'rel="home" target="' . esc_attr( $attributes['linkTarget'] ) . '"' . $aria_label, $custom_logo );
+		$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();
 	}
 
 	$classnames = array();
@@ -55,6 +62,8 @@
 
 /**
  * Register a core site setting for a site logo
+ *
+ * @since 5.8.0
  */
 function register_block_core_site_logo_setting() {
 	register_setting(
@@ -65,6 +74,7 @@
 				'name' => 'site_logo',
 			),
 			'type'         => 'integer',
+			'label'        => __( 'Logo' ),
 			'description'  => __( 'Site logo.' ),
 		)
 	);
@@ -74,6 +84,8 @@
 
 /**
  * Register a core site setting for a site icon
+ *
+ * @since 5.9.0
  */
 function register_block_core_site_icon_setting() {
 	register_setting(
@@ -82,6 +94,7 @@
 		array(
 			'show_in_rest' => true,
 			'type'         => 'integer',
+			'label'        => __( 'Icon' ),
 			'description'  => __( 'Site icon.' ),
 		)
 	);
@@ -91,6 +104,8 @@
 
 /**
  * Registers the `core/site-logo` block on the server.
+ *
+ * @since 5.8.0
  */
 function register_block_core_site_logo() {
 	register_block_type_from_metadata(
@@ -106,6 +121,8 @@
 /**
  * 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.
@@ -120,6 +137,8 @@
 /**
  * Updates the site_logo option when the custom_logo theme-mod gets updated.
  *
+ * @since 5.8.0
+ *
  * @param  mixed $value Attachment ID of the custom logo or an empty value.
  * @return mixed
  */
@@ -138,6 +157,8 @@
 /**
  * Deletes the site_logo when the custom_logo theme mod is removed.
  *
+ * @since 5.8.0
+ *
  * @param array $old_value Previous theme mod settings.
  * @param array $value     Updated theme mod settings.
  */
@@ -156,6 +177,8 @@
 
 /**
  * Deletes the site logo when all theme mods are being removed.
+ *
+ * @since 5.8.0
  */
 function _delete_site_logo_on_remove_theme_mods() {
 	global $_ignore_site_logo_changes;
@@ -174,6 +197,8 @@
  * 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' );
@@ -184,6 +209,8 @@
 
 /**
  * Removes the custom_logo theme-mod when the site_logo option gets deleted.
+ *
+ * @since 5.9.0
  */
 function _delete_custom_logo_on_remove_site_logo() {
 	global $_ignore_site_logo_changes;