Edit File by line
/home/zeestwma/redstone.../wp-inclu.../blocks
File: query.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/query` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Modifies the static `core/query` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.4.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 The block instance.
[14] Fix | Delete
*
[15] Fix | Delete
* @return string Returns the modified output of the query block.
[16] Fix | Delete
*/
[17] Fix | Delete
function render_block_core_query( $attributes, $content, $block ) {
[18] Fix | Delete
$is_interactive = isset( $attributes['enhancedPagination'] )
[19] Fix | Delete
&& true === $attributes['enhancedPagination']
[20] Fix | Delete
&& isset( $attributes['queryId'] );
[21] Fix | Delete
[22] Fix | Delete
// Enqueue the script module and add the necessary directives if the block is
[23] Fix | Delete
// interactive.
[24] Fix | Delete
if ( $is_interactive ) {
[25] Fix | Delete
wp_enqueue_script_module( '@wordpress/block-library/query/view' );
[26] Fix | Delete
[27] Fix | Delete
$p = new WP_HTML_Tag_Processor( $content );
[28] Fix | Delete
if ( $p->next_tag() ) {
[29] Fix | Delete
// Add the necessary directives.
[30] Fix | Delete
$p->set_attribute( 'data-wp-interactive', 'core/query' );
[31] Fix | Delete
$p->set_attribute( 'data-wp-router-region', 'query-' . $attributes['queryId'] );
[32] Fix | Delete
$p->set_attribute( 'data-wp-context', '{}' );
[33] Fix | Delete
$p->set_attribute( 'data-wp-key', $attributes['queryId'] );
[34] Fix | Delete
$content = $p->get_updated_html();
[35] Fix | Delete
}
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
// Add the styles to the block type if the block is interactive and remove
[39] Fix | Delete
// them if it's not.
[40] Fix | Delete
$style_asset = 'wp-block-query';
[41] Fix | Delete
if ( ! wp_style_is( $style_asset ) ) {
[42] Fix | Delete
$style_handles = $block->block_type->style_handles;
[43] Fix | Delete
// If the styles are not needed, and they are still in the `style_handles`, remove them.
[44] Fix | Delete
if ( ! $is_interactive && in_array( $style_asset, $style_handles, true ) ) {
[45] Fix | Delete
$block->block_type->style_handles = array_diff( $style_handles, array( $style_asset ) );
[46] Fix | Delete
}
[47] Fix | Delete
// If the styles are needed, but they were previously removed, add them again.
[48] Fix | Delete
if ( $is_interactive && ! in_array( $style_asset, $style_handles, true ) ) {
[49] Fix | Delete
$block->block_type->style_handles = array_merge( $style_handles, array( $style_asset ) );
[50] Fix | Delete
}
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
return $content;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Registers the `core/query` block on the server.
[58] Fix | Delete
*
[59] Fix | Delete
* @since 5.8.0
[60] Fix | Delete
*/
[61] Fix | Delete
function register_block_core_query() {
[62] Fix | Delete
register_block_type_from_metadata(
[63] Fix | Delete
__DIR__ . '/query',
[64] Fix | Delete
array(
[65] Fix | Delete
'render_callback' => 'render_block_core_query',
[66] Fix | Delete
)
[67] Fix | Delete
);
[68] Fix | Delete
}
[69] Fix | Delete
add_action( 'init', 'register_block_core_query' );
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Traverse the tree of blocks looking for any plugin block (i.e., a block from
[73] Fix | Delete
* an installed plugin) inside a Query block with the enhanced pagination
[74] Fix | Delete
* enabled. If at least one is found, the enhanced pagination is effectively
[75] Fix | Delete
* disabled to prevent any potential incompatibilities.
[76] Fix | Delete
*
[77] Fix | Delete
* @since 6.4.0
[78] Fix | Delete
*
[79] Fix | Delete
* @param array $parsed_block The block being rendered.
[80] Fix | Delete
* @return array Returns the parsed block, unmodified.
[81] Fix | Delete
*/
[82] Fix | Delete
function block_core_query_disable_enhanced_pagination( $parsed_block ) {
[83] Fix | Delete
static $enhanced_query_stack = array();
[84] Fix | Delete
static $dirty_enhanced_queries = array();
[85] Fix | Delete
static $render_query_callback = null;
[86] Fix | Delete
[87] Fix | Delete
$block_name = $parsed_block['blockName'];
[88] Fix | Delete
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );
[89] Fix | Delete
$has_enhanced_pagination = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] );
[90] Fix | Delete
/*
[91] Fix | Delete
* Client side navigation can be true in two states:
[92] Fix | Delete
* - supports.interactivity = true;
[93] Fix | Delete
* - supports.interactivity.clientNavigation = true;
[94] Fix | Delete
*/
[95] Fix | Delete
$supports_client_navigation = ( isset( $block_type->supports['interactivity']['clientNavigation'] ) && true === $block_type->supports['interactivity']['clientNavigation'] )
[96] Fix | Delete
|| ( isset( $block_type->supports['interactivity'] ) && true === $block_type->supports['interactivity'] );
[97] Fix | Delete
[98] Fix | Delete
if ( 'core/query' === $block_name && $has_enhanced_pagination ) {
[99] Fix | Delete
$enhanced_query_stack[] = $parsed_block['attrs']['queryId'];
[100] Fix | Delete
[101] Fix | Delete
if ( ! isset( $render_query_callback ) ) {
[102] Fix | Delete
/**
[103] Fix | Delete
* Filter that disables the enhanced pagination feature during block
[104] Fix | Delete
* rendering when a plugin block has been found inside. It does so
[105] Fix | Delete
* by adding an attribute called `data-wp-navigation-disabled` which
[106] Fix | Delete
* is later handled by the front-end logic.
[107] Fix | Delete
*
[108] Fix | Delete
* @param string $content The block content.
[109] Fix | Delete
* @param array $block The full block, including name and attributes.
[110] Fix | Delete
* @return string Returns the modified output of the query block.
[111] Fix | Delete
*/
[112] Fix | Delete
$render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) {
[113] Fix | Delete
$has_enhanced_pagination = isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] );
[114] Fix | Delete
[115] Fix | Delete
if ( ! $has_enhanced_pagination ) {
[116] Fix | Delete
return $content;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
if ( isset( $dirty_enhanced_queries[ $block['attrs']['queryId'] ] ) ) {
[120] Fix | Delete
// Disable navigation in the router store config.
[121] Fix | Delete
wp_interactivity_config( 'core/router', array( 'clientNavigationDisabled' => true ) );
[122] Fix | Delete
$dirty_enhanced_queries[ $block['attrs']['queryId'] ] = null;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
array_pop( $enhanced_query_stack );
[126] Fix | Delete
[127] Fix | Delete
if ( empty( $enhanced_query_stack ) ) {
[128] Fix | Delete
remove_filter( 'render_block_core/query', $render_query_callback );
[129] Fix | Delete
$render_query_callback = null;
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
return $content;
[133] Fix | Delete
};
[134] Fix | Delete
[135] Fix | Delete
add_filter( 'render_block_core/query', $render_query_callback, 10, 2 );
[136] Fix | Delete
}
[137] Fix | Delete
} elseif (
[138] Fix | Delete
! empty( $enhanced_query_stack ) &&
[139] Fix | Delete
isset( $block_name ) &&
[140] Fix | Delete
( ! $supports_client_navigation )
[141] Fix | Delete
) {
[142] Fix | Delete
foreach ( $enhanced_query_stack as $query_id ) {
[143] Fix | Delete
$dirty_enhanced_queries[ $query_id ] = true;
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
return $parsed_block;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
add_filter( 'render_block_data', 'block_core_query_disable_enhanced_pagination', 10, 1 );
[151] Fix | Delete
[152] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function