wp/wp-includes/blocks/post-terms.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    21 	if ( ! is_taxonomy_viewable( $attributes['term'] ) ) {
    21 	if ( ! is_taxonomy_viewable( $attributes['term'] ) ) {
    22 		return '';
    22 		return '';
    23 	}
    23 	}
    24 
    24 
    25 	$post_terms = get_the_terms( $block->context['postId'], $attributes['term'] );
    25 	$post_terms = get_the_terms( $block->context['postId'], $attributes['term'] );
    26 	if ( is_wp_error( $post_terms ) ) {
    26 	if ( is_wp_error( $post_terms ) || empty( $post_terms ) ) {
    27 		return '';
       
    28 	}
       
    29 	if ( empty( $post_terms ) ) {
       
    30 		return '';
    27 		return '';
    31 	}
    28 	}
    32 
    29 
    33 	$align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}";
    30 	$classes = 'taxonomy-' . $attributes['term'];
       
    31 	if ( isset( $attributes['textAlign'] ) ) {
       
    32 		$classes .= ' has-text-align-' . $attributes['textAlign'];
       
    33 	}
    34 
    34 
    35 	$terms_links = '';
    35 	$separator = empty( $attributes['separator'] ) ? ' ' : $attributes['separator'];
    36 	foreach ( $post_terms as $term ) {
       
    37 		$terms_links .= sprintf(
       
    38 			'<a href="%1$s">%2$s</a> | ',
       
    39 			get_term_link( $term->term_id ),
       
    40 			esc_html( $term->name )
       
    41 		);
       
    42 	}
       
    43 	$terms_links        = trim( $terms_links, ' | ' );
       
    44 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
       
    45 
    36 
    46 	return sprintf(
    37 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    47 		'<div %1$s>%2$s</div>',
    38 
    48 		$wrapper_attributes,
    39 	return get_the_term_list(
    49 		$terms_links
    40 		$block->context['postId'],
       
    41 		$attributes['term'],
       
    42 		"<div $wrapper_attributes>",
       
    43 		'<span class="wp-block-post-terms__separator">' . esc_html( $separator ) . '</span>',
       
    44 		'</div>'
    50 	);
    45 	);
    51 }
    46 }
    52 
    47 
    53 /**
    48 /**
    54  * Registers the `core/post-terms` block on the server.
    49  * Registers the `core/post-terms` block on the server.