Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: post-terms.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/post-terms` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/post-terms` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.8.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $attributes Block attributes.
[12] Fix | Delete
* @param string $content Block default content.
[13] Fix | Delete
* @param WP_Block $block Block instance.
[14] Fix | Delete
* @return string Returns the filtered post terms for the current post wrapped inside "a" tags.
[15] Fix | Delete
*/
[16] Fix | Delete
function render_block_core_post_terms( $attributes, $content, $block ) {
[17] Fix | Delete
if ( ! isset( $block->context['postId'] ) || ! isset( $attributes['term'] ) ) {
[18] Fix | Delete
return '';
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
if ( ! is_taxonomy_viewable( $attributes['term'] ) ) {
[22] Fix | Delete
return '';
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
$classes = array( 'taxonomy-' . $attributes['term'] );
[26] Fix | Delete
if ( isset( $attributes['textAlign'] ) ) {
[27] Fix | Delete
$classes[] = 'has-text-align-' . $attributes['textAlign'];
[28] Fix | Delete
}
[29] Fix | Delete
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
[30] Fix | Delete
$classes[] = 'has-link-color';
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
$separator = empty( $attributes['separator'] ) ? ' ' : $attributes['separator'];
[34] Fix | Delete
[35] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
[36] Fix | Delete
[37] Fix | Delete
$prefix = "<div $wrapper_attributes>";
[38] Fix | Delete
if ( isset( $attributes['prefix'] ) && $attributes['prefix'] ) {
[39] Fix | Delete
$prefix .= '<span class="wp-block-post-terms__prefix">' . $attributes['prefix'] . '</span>';
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
$suffix = '</div>';
[43] Fix | Delete
if ( isset( $attributes['suffix'] ) && $attributes['suffix'] ) {
[44] Fix | Delete
$suffix = '<span class="wp-block-post-terms__suffix">' . $attributes['suffix'] . '</span>' . $suffix;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
$post_terms = get_the_term_list(
[48] Fix | Delete
$block->context['postId'],
[49] Fix | Delete
$attributes['term'],
[50] Fix | Delete
wp_kses_post( $prefix ),
[51] Fix | Delete
'<span class="wp-block-post-terms__separator">' . esc_html( $separator ) . '</span>',
[52] Fix | Delete
wp_kses_post( $suffix )
[53] Fix | Delete
);
[54] Fix | Delete
[55] Fix | Delete
if ( is_wp_error( $post_terms ) || empty( $post_terms ) ) {
[56] Fix | Delete
return '';
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
return $post_terms;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* Returns the available variations for the `core/post-terms` block.
[64] Fix | Delete
*
[65] Fix | Delete
* @since 6.5.0
[66] Fix | Delete
*
[67] Fix | Delete
* @return array The available variations for the block.
[68] Fix | Delete
*/
[69] Fix | Delete
function block_core_post_terms_build_variations() {
[70] Fix | Delete
$taxonomies = get_taxonomies(
[71] Fix | Delete
array(
[72] Fix | Delete
'publicly_queryable' => true,
[73] Fix | Delete
'show_in_rest' => true,
[74] Fix | Delete
),
[75] Fix | Delete
'objects'
[76] Fix | Delete
);
[77] Fix | Delete
[78] Fix | Delete
// Split the available taxonomies to `built_in` and custom ones,
[79] Fix | Delete
// in order to prioritize the `built_in` taxonomies at the
[80] Fix | Delete
// search results.
[81] Fix | Delete
$built_ins = array();
[82] Fix | Delete
$custom_variations = array();
[83] Fix | Delete
[84] Fix | Delete
// Create and register the eligible taxonomies variations.
[85] Fix | Delete
foreach ( $taxonomies as $taxonomy ) {
[86] Fix | Delete
$variation = array(
[87] Fix | Delete
'name' => $taxonomy->name,
[88] Fix | Delete
'title' => $taxonomy->label,
[89] Fix | Delete
'description' => sprintf(
[90] Fix | Delete
/* translators: %s: taxonomy's label */
[91] Fix | Delete
__( 'Display a list of assigned terms from the taxonomy: %s' ),
[92] Fix | Delete
$taxonomy->label
[93] Fix | Delete
),
[94] Fix | Delete
'attributes' => array(
[95] Fix | Delete
'term' => $taxonomy->name,
[96] Fix | Delete
),
[97] Fix | Delete
'isActive' => array( 'term' ),
[98] Fix | Delete
'scope' => array( 'inserter', 'transform' ),
[99] Fix | Delete
);
[100] Fix | Delete
// Set the category variation as the default one.
[101] Fix | Delete
if ( 'category' === $taxonomy->name ) {
[102] Fix | Delete
$variation['isDefault'] = true;
[103] Fix | Delete
}
[104] Fix | Delete
if ( $taxonomy->_builtin ) {
[105] Fix | Delete
$built_ins[] = $variation;
[106] Fix | Delete
} else {
[107] Fix | Delete
$custom_variations[] = $variation;
[108] Fix | Delete
}
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
return array_merge( $built_ins, $custom_variations );
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Registers the `core/post-terms` block on the server.
[116] Fix | Delete
*
[117] Fix | Delete
* @since 5.8.0
[118] Fix | Delete
*/
[119] Fix | Delete
function register_block_core_post_terms() {
[120] Fix | Delete
register_block_type_from_metadata(
[121] Fix | Delete
__DIR__ . '/post-terms',
[122] Fix | Delete
array(
[123] Fix | Delete
'render_callback' => 'render_block_core_post_terms',
[124] Fix | Delete
'variation_callback' => 'block_core_post_terms_build_variations',
[125] Fix | Delete
)
[126] Fix | Delete
);
[127] Fix | Delete
}
[128] Fix | Delete
add_action( 'init', 'register_block_core_post_terms' );
[129] Fix | Delete
[130] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function