wpseek.com
A WordPress-centric search engine for devs and theme authors
render_block_core_query › WordPress Function
Since6.4.0
Deprecatedn/a
› render_block_core_query ( $attributes, $content, $block )
Parameters: (3) |
|
Returns: |
|
Defined at: |
|
Codex: |
Modifies the static `core/query` block on the server.
Source
function render_block_core_query( $attributes, $content, $block ) {
$is_interactive = isset( $attributes['enhancedPagination'] )
&& true === $attributes['enhancedPagination']
&& isset( $attributes['queryId'] );
// Enqueue the script module and add the necessary directives if the block is
// interactive.
if ( $is_interactive ) {
wp_enqueue_script_module( '@wordpress/block-library/query/view' );
$p = new WP_HTML_Tag_Processor( $content );
if ( $p->next_tag() ) {
// Add the necessary directives.
$p->set_attribute( 'data-wp-interactive', 'core/query' );
$p->set_attribute( 'data-wp-router-region', 'query-' . $attributes['queryId'] );
$p->set_attribute( 'data-wp-context', '{}' );
$p->set_attribute( 'data-wp-key', $attributes['queryId'] );
$content = $p->get_updated_html();
}
}
// Add the styles to the block type if the block is interactive and remove
// them if it's not.
$style_asset = 'wp-block-query';
if ( ! wp_style_is( $style_asset ) ) {
$style_handles = $block->block_type->style_handles;
// If the styles are not needed, and they are still in the `style_handles`, remove them.
if ( ! $is_interactive && in_array( $style_asset, $style_handles, true ) ) {
$block->block_type->style_handles = array_diff( $style_handles, array( $style_asset ) );
}
// If the styles are needed, but they were previously removed, add them again.
if ( $is_interactive && ! in_array( $style_asset, $style_handles, true ) ) {
$block->block_type->style_handles = array_merge( $style_handles, array( $style_asset ) );
}
}
return $content;
}