wp/wp-includes/blocks/site-title.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 /**
     8 /**
     9  * Renders the `core/site-title` block on the server.
     9  * Renders the `core/site-title` block on the server.
       
    10  *
       
    11  * @since 5.8.0
    10  *
    12  *
    11  * @param array $attributes The block attributes.
    13  * @param array $attributes The block attributes.
    12  *
    14  *
    13  * @return string The render.
    15  * @return string The render.
    14  */
    16  */
    16 	$site_title = get_bloginfo( 'name' );
    18 	$site_title = get_bloginfo( 'name' );
    17 	if ( ! $site_title ) {
    19 	if ( ! $site_title ) {
    18 		return;
    20 		return;
    19 	}
    21 	}
    20 
    22 
    21 	$tag_name         = 'h1';
    23 	$tag_name = 'h1';
    22 	$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
    24 	$classes  = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
    23 
    25 	if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
    24 	$aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : '';
    26 		$classes .= ' has-link-color';
       
    27 	}
    25 
    28 
    26 	if ( isset( $attributes['level'] ) ) {
    29 	if ( isset( $attributes['level'] ) ) {
    27 		$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . (int) $attributes['level'];
    30 		$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . (int) $attributes['level'];
    28 	}
    31 	}
    29 
    32 
    30 	if ( $attributes['isLink'] ) {
    33 	if ( $attributes['isLink'] ) {
    31 		$link_attrs = array(
    34 		$aria_current = is_home() || ( is_front_page() && 'page' === get_option( 'show_on_front' ) ) ? ' aria-current="page"' : '';
    32 			'href="' . esc_url( get_bloginfo( 'url' ) ) . '"',
    35 		$link_target  = ! empty( $attributes['linkTarget'] ) ? $attributes['linkTarget'] : '_self';
    33 			'rel="' . esc_attr( 'home' ) . '"',
    36 
       
    37 		$site_title = sprintf(
       
    38 			'<a href="%1$s" target="%2$s" rel="home"%3$s>%4$s</a>',
       
    39 			esc_url( home_url() ),
       
    40 			esc_attr( $link_target ),
    34 			$aria_current,
    41 			$aria_current,
       
    42 			esc_html( $site_title )
    35 		);
    43 		);
    36 		if ( '_blank' === $attributes['linkTarget'] ) {
       
    37 			$link_attrs[] = 'target="_blank"';
       
    38 		}
       
    39 		$site_title = sprintf( '<a %1$s>%2$s</a>', implode( ' ', $link_attrs ), esc_html( $site_title ) );
       
    40 	}
    44 	}
    41 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
    45 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classes ) ) );
    42 
    46 
    43 	return sprintf(
    47 	return sprintf(
    44 		'<%1$s %2$s>%3$s</%1$s>',
    48 		'<%1$s %2$s>%3$s</%1$s>',
    45 		$tag_name,
    49 		$tag_name,
    46 		$wrapper_attributes,
    50 		$wrapper_attributes,
    49 	);
    53 	);
    50 }
    54 }
    51 
    55 
    52 /**
    56 /**
    53  * Registers the `core/site-title` block on the server.
    57  * Registers the `core/site-title` block on the server.
       
    58  *
       
    59  * @since 5.8.0
    54  */
    60  */
    55 function register_block_core_site_title() {
    61 function register_block_core_site_title() {
    56 	register_block_type_from_metadata(
    62 	register_block_type_from_metadata(
    57 		__DIR__ . '/site-title',
    63 		__DIR__ . '/site-title',
    58 		array(
    64 		array(