wp/wp-includes/blocks/post-title.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    17 function render_block_core_post_title( $attributes, $content, $block ) {
    17 function render_block_core_post_title( $attributes, $content, $block ) {
    18 	if ( ! isset( $block->context['postId'] ) ) {
    18 	if ( ! isset( $block->context['postId'] ) ) {
    19 		return '';
    19 		return '';
    20 	}
    20 	}
    21 
    21 
    22 	$post_ID          = $block->context['postId'];
    22 	$post_ID = $block->context['postId'];
       
    23 	$title   = get_the_title();
       
    24 
       
    25 	if ( ! $title ) {
       
    26 		return '';
       
    27 	}
       
    28 
    23 	$tag_name         = 'h2';
    29 	$tag_name         = 'h2';
    24 	$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
    30 	$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
    25 
    31 
    26 	if ( isset( $attributes['level'] ) ) {
    32 	if ( isset( $attributes['level'] ) ) {
    27 		$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level'];
    33 		$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level'];
    28 	}
    34 	}
    29 
    35 
    30 	$title = get_the_title( $post_ID );
       
    31 	if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
    36 	if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
    32 		$title = sprintf( '<a href="%1s" target="%2s" rel="%3s">%4s</a>', get_the_permalink( $post_ID ), $attributes['linkTarget'], $attributes['rel'], $title );
    37 		$title = sprintf( '<a href="%1$s" target="%2$s" rel="%3$s">%4$s</a>', get_the_permalink( $post_ID ), esc_attr( $attributes['linkTarget'] ), esc_attr( $attributes['rel'] ), $title );
    33 	}
    38 	}
    34 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
    39 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
    35 
    40 
    36 	return sprintf(
    41 	return sprintf(
    37 		'<%1$s %2$s>%3$s</%1$s>',
    42 		'<%1$s %2$s>%3$s</%1$s>',