Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu.../blocks
File: term-template.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/term-template` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/term-template` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.9.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
*
[15] Fix | Delete
* @return string Returns the output of the term template.
[16] Fix | Delete
*/
[17] Fix | Delete
function render_block_core_term_template( $attributes, $content, $block ) {
[18] Fix | Delete
if ( ! isset( $block->context ) || empty( $block->context['termQuery'] ) ) {
[19] Fix | Delete
return '';
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
$query = $block->context['termQuery'];
[23] Fix | Delete
[24] Fix | Delete
$query_args = array(
[25] Fix | Delete
'number' => $query['perPage'],
[26] Fix | Delete
'order' => $query['order'],
[27] Fix | Delete
'orderby' => $query['orderBy'],
[28] Fix | Delete
'hide_empty' => $query['hideEmpty'],
[29] Fix | Delete
);
[30] Fix | Delete
[31] Fix | Delete
$inherit_query = isset( $query['inherit'] )
[32] Fix | Delete
&& $query['inherit']
[33] Fix | Delete
&& ( is_tax() || is_category() || is_tag() );
[34] Fix | Delete
[35] Fix | Delete
if ( $inherit_query ) {
[36] Fix | Delete
// Get the current term and taxonomy from the queried object.
[37] Fix | Delete
$queried_object = get_queried_object();
[38] Fix | Delete
[39] Fix | Delete
// For hierarchical taxonomies, show children of the current term.
[40] Fix | Delete
// For non-hierarchical taxonomies, show all terms (don't set parent).
[41] Fix | Delete
if ( is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {
[42] Fix | Delete
// If showNested is true, use child_of to include nested terms.
[43] Fix | Delete
// Otherwise, use parent to show only direct children.
[44] Fix | Delete
if ( ! empty( $query['showNested'] ) ) {
[45] Fix | Delete
$query_args['child_of'] = $queried_object->term_id;
[46] Fix | Delete
} else {
[47] Fix | Delete
$query_args['parent'] = $queried_object->term_id;
[48] Fix | Delete
}
[49] Fix | Delete
}
[50] Fix | Delete
$query_args['taxonomy'] = $queried_object->taxonomy;
[51] Fix | Delete
} else {
[52] Fix | Delete
// If not inheriting set `taxonomy` from the block attribute.
[53] Fix | Delete
$query_args['taxonomy'] = $query['taxonomy'];
[54] Fix | Delete
[55] Fix | Delete
// If we are including specific terms we ignore `showNested` argument.
[56] Fix | Delete
if ( ! empty( $query['include'] ) ) {
[57] Fix | Delete
$query_args['include'] = array_unique( array_map( 'intval', $query['include'] ) );
[58] Fix | Delete
$query_args['orderby'] = 'include';
[59] Fix | Delete
$query_args['order'] = 'asc';
[60] Fix | Delete
} elseif ( is_taxonomy_hierarchical( $query['taxonomy'] ) && empty( $query['showNested'] ) ) {
[61] Fix | Delete
// We set parent only when inheriting from the taxonomy archive context or not
[62] Fix | Delete
// showing nested terms, otherwise nested terms are not displayed.
[63] Fix | Delete
$query_args['parent'] = 0;
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
$terms_query = new WP_Term_Query( $query_args );
[68] Fix | Delete
$terms = $terms_query->get_terms();
[69] Fix | Delete
[70] Fix | Delete
if ( ! $terms || is_wp_error( $terms ) ) {
[71] Fix | Delete
return '';
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
$content = '';
[75] Fix | Delete
foreach ( $terms as $term ) {
[76] Fix | Delete
// Get an instance of the current Term Template block.
[77] Fix | Delete
$block_instance = $block->parsed_block;
[78] Fix | Delete
[79] Fix | Delete
// Set the block name to one that does not correspond to an existing registered block.
[80] Fix | Delete
// This ensures that for the inner instances of the Term Template block, we do not render any block supports.
[81] Fix | Delete
$block_instance['blockName'] = 'core/null';
[82] Fix | Delete
[83] Fix | Delete
$term_id = $term->term_id;
[84] Fix | Delete
$taxonomy = $term->taxonomy;
[85] Fix | Delete
[86] Fix | Delete
$filter_block_context = static function ( $context ) use ( $term_id, $taxonomy ) {
[87] Fix | Delete
$context['termId'] = $term_id;
[88] Fix | Delete
$context['taxonomy'] = $taxonomy;
[89] Fix | Delete
return $context;
[90] Fix | Delete
};
[91] Fix | Delete
[92] Fix | Delete
// Use an early priority to so that other 'render_block_context' filters have access to the values.
[93] Fix | Delete
add_filter( 'render_block_context', $filter_block_context, 1 );
[94] Fix | Delete
[95] Fix | Delete
// Render the inner blocks of the Term Template block with `dynamic` set to `false` to prevent calling
[96] Fix | Delete
// `render_callback` and ensure that no wrapper markup is included.
[97] Fix | Delete
$block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) );
[98] Fix | Delete
[99] Fix | Delete
remove_filter( 'render_block_context', $filter_block_context, 1 );
[100] Fix | Delete
[101] Fix | Delete
// Wrap the render inner blocks in a `li` element with the appropriate term classes.
[102] Fix | Delete
$term_classes = "wp-block-term term-{$term->term_id} {$term->taxonomy} taxonomy-{$term->taxonomy}";
[103] Fix | Delete
[104] Fix | Delete
$content .= '<li class="' . esc_attr( $term_classes ) . '">' . $block_content . '</li>';
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
$classnames = '';
[108] Fix | Delete
[109] Fix | Delete
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
[110] Fix | Delete
$classnames .= 'has-link-color';
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classnames ) ) );
[114] Fix | Delete
[115] Fix | Delete
return sprintf(
[116] Fix | Delete
'<ul %s>%s</ul>',
[117] Fix | Delete
$wrapper_attributes,
[118] Fix | Delete
$content
[119] Fix | Delete
);
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Registers the `core/term-template` block on the server.
[124] Fix | Delete
*
[125] Fix | Delete
* @since 6.9.0
[126] Fix | Delete
*/
[127] Fix | Delete
function register_block_core_term_template() {
[128] Fix | Delete
register_block_type_from_metadata(
[129] Fix | Delete
__DIR__ . '/term-template',
[130] Fix | Delete
array(
[131] Fix | Delete
'render_callback' => 'render_block_core_term_template',
[132] Fix | Delete
)
[133] Fix | Delete
);
[134] Fix | Delete
}
[135] Fix | Delete
add_action( 'init', 'register_block_core_term_template' );
[136] Fix | Delete
[137] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function