Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: post-template.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/post-template` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Determines whether a block list contains a block that uses the featured image.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.0.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param WP_Block_List $inner_blocks Inner block instance.
[12] Fix | Delete
*
[13] Fix | Delete
* @return bool Whether the block list contains a block that uses the featured image.
[14] Fix | Delete
*/
[15] Fix | Delete
function block_core_post_template_uses_featured_image( $inner_blocks ) {
[16] Fix | Delete
foreach ( $inner_blocks as $block ) {
[17] Fix | Delete
if ( 'core/post-featured-image' === $block->name ) {
[18] Fix | Delete
return true;
[19] Fix | Delete
}
[20] Fix | Delete
if (
[21] Fix | Delete
'core/cover' === $block->name &&
[22] Fix | Delete
! empty( $block->attributes['useFeaturedImage'] )
[23] Fix | Delete
) {
[24] Fix | Delete
return true;
[25] Fix | Delete
}
[26] Fix | Delete
if ( $block->inner_blocks && block_core_post_template_uses_featured_image( $block->inner_blocks ) ) {
[27] Fix | Delete
return true;
[28] Fix | Delete
}
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
return false;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Renders the `core/post-template` block on the server.
[36] Fix | Delete
*
[37] Fix | Delete
* @since 6.3.0 Changed render_block_context priority to `1`.
[38] Fix | Delete
*
[39] Fix | Delete
* @global WP_Query $wp_query WordPress Query object.
[40] Fix | Delete
*
[41] Fix | Delete
* @param array $attributes Block attributes.
[42] Fix | Delete
* @param string $content Block default content.
[43] Fix | Delete
* @param WP_Block $block Block instance.
[44] Fix | Delete
*
[45] Fix | Delete
* @return string Returns the output of the query, structured using the layout defined by the block's inner blocks.
[46] Fix | Delete
*/
[47] Fix | Delete
function render_block_core_post_template( $attributes, $content, $block ) {
[48] Fix | Delete
$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
[49] Fix | Delete
$enhanced_pagination = isset( $block->context['enhancedPagination'] ) && $block->context['enhancedPagination'];
[50] Fix | Delete
$page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
[51] Fix | Delete
[52] Fix | Delete
// Use global query if needed.
[53] Fix | Delete
$use_global_query = ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] );
[54] Fix | Delete
if ( $use_global_query ) {
[55] Fix | Delete
global $wp_query;
[56] Fix | Delete
[57] Fix | Delete
/*
[58] Fix | Delete
* If already in the main query loop, duplicate the query instance to not tamper with the main instance.
[59] Fix | Delete
* Since this is a nested query, it should start at the beginning, therefore rewind posts.
[60] Fix | Delete
* Otherwise, the main query loop has not started yet and this block is responsible for doing so.
[61] Fix | Delete
*/
[62] Fix | Delete
if ( in_the_loop() ) {
[63] Fix | Delete
$query = clone $wp_query;
[64] Fix | Delete
$query->rewind_posts();
[65] Fix | Delete
} else {
[66] Fix | Delete
$query = $wp_query;
[67] Fix | Delete
}
[68] Fix | Delete
} else {
[69] Fix | Delete
$query_args = build_query_vars_from_query_block( $block, $page );
[70] Fix | Delete
$query = new WP_Query( $query_args );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
if ( ! $query->have_posts() ) {
[74] Fix | Delete
return '';
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
if ( block_core_post_template_uses_featured_image( $block->inner_blocks ) ) {
[78] Fix | Delete
update_post_thumbnail_cache( $query );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
$classnames = '';
[82] Fix | Delete
if ( isset( $block->context['displayLayout'] ) && isset( $block->context['query'] ) ) {
[83] Fix | Delete
if ( isset( $block->context['displayLayout']['type'] ) && 'flex' === $block->context['displayLayout']['type'] ) {
[84] Fix | Delete
$classnames = "is-flex-container columns-{$block->context['displayLayout']['columns']}";
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
[88] Fix | Delete
$classnames .= ' has-link-color';
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
// Ensure backwards compatibility by flagging the number of columns via classname when using grid layout.
[92] Fix | Delete
if ( isset( $attributes['layout']['type'] ) && 'grid' === $attributes['layout']['type'] && ! empty( $attributes['layout']['columnCount'] ) ) {
[93] Fix | Delete
$classnames .= ' ' . sanitize_title( 'columns-' . $attributes['layout']['columnCount'] );
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classnames ) ) );
[97] Fix | Delete
[98] Fix | Delete
$content = '';
[99] Fix | Delete
while ( $query->have_posts() ) {
[100] Fix | Delete
$query->the_post();
[101] Fix | Delete
[102] Fix | Delete
// Get an instance of the current Post Template block.
[103] Fix | Delete
$block_instance = $block->parsed_block;
[104] Fix | Delete
[105] Fix | Delete
// Set the block name to one that does not correspond to an existing registered block.
[106] Fix | Delete
// This ensures that for the inner instances of the Post Template block, we do not render any block supports.
[107] Fix | Delete
$block_instance['blockName'] = 'core/null';
[108] Fix | Delete
[109] Fix | Delete
$post_id = get_the_ID();
[110] Fix | Delete
$post_type = get_post_type();
[111] Fix | Delete
$filter_block_context = static function ( $context ) use ( $post_id, $post_type ) {
[112] Fix | Delete
$context['postType'] = $post_type;
[113] Fix | Delete
$context['postId'] = $post_id;
[114] Fix | Delete
return $context;
[115] Fix | Delete
};
[116] Fix | Delete
[117] Fix | Delete
// Use an early priority to so that other 'render_block_context' filters have access to the values.
[118] Fix | Delete
add_filter( 'render_block_context', $filter_block_context, 1 );
[119] Fix | Delete
// Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling
[120] Fix | Delete
// `render_callback` and ensure that no wrapper markup is included.
[121] Fix | Delete
$block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) );
[122] Fix | Delete
remove_filter( 'render_block_context', $filter_block_context, 1 );
[123] Fix | Delete
[124] Fix | Delete
// Wrap the render inner blocks in a `li` element with the appropriate post classes.
[125] Fix | Delete
$post_classes = implode( ' ', get_post_class( 'wp-block-post' ) );
[126] Fix | Delete
[127] Fix | Delete
$inner_block_directives = $enhanced_pagination ? ' data-wp-key="post-template-item-' . $post_id . '"' : '';
[128] Fix | Delete
[129] Fix | Delete
$content .= '<li' . $inner_block_directives . ' class="' . esc_attr( $post_classes ) . '">' . $block_content . '</li>';
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/*
[133] Fix | Delete
* Use this function to restore the context of the template tags
[134] Fix | Delete
* from a secondary query loop back to the main query loop.
[135] Fix | Delete
* Since we use two custom loops, it's safest to always restore.
[136] Fix | Delete
*/
[137] Fix | Delete
wp_reset_postdata();
[138] Fix | Delete
[139] Fix | Delete
return sprintf(
[140] Fix | Delete
'<ul %1$s>%2$s</ul>',
[141] Fix | Delete
$wrapper_attributes,
[142] Fix | Delete
$content
[143] Fix | Delete
);
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Registers the `core/post-template` block on the server.
[148] Fix | Delete
*
[149] Fix | Delete
* @since 5.8.0
[150] Fix | Delete
*/
[151] Fix | Delete
function register_block_core_post_template() {
[152] Fix | Delete
register_block_type_from_metadata(
[153] Fix | Delete
__DIR__ . '/post-template',
[154] Fix | Delete
array(
[155] Fix | Delete
'render_callback' => 'render_block_core_post_template',
[156] Fix | Delete
'skip_inner_blocks' => true,
[157] Fix | Delete
)
[158] Fix | Delete
);
[159] Fix | Delete
}
[160] Fix | Delete
add_action( 'init', 'register_block_core_post_template' );
[161] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function