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