Changeset 57377 for trunk/src/wp-includes/blocks/query.php
- Timestamp:
- 01/29/2024 09:04:18 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/query.php
r57109 r57377 18 18 */ 19 19 function render_block_core_query( $attributes, $content, $block ) { 20 if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) ) { 20 $is_interactive = isset( $attributes['enhancedPagination'] ) && true === $attributes['enhancedPagination'] && isset( $attributes['queryId'] ); 21 22 // Enqueue the script module and add the necessary directives if the block is 23 // interactive. 24 if ( $is_interactive ) { 25 wp_enqueue_script_module( '@wordpress/block-library/query' ); 26 21 27 $p = new WP_HTML_Tag_Processor( $content ); 22 28 if ( $p->next_tag() ) { 23 29 // Add the necessary directives. 24 $p->set_attribute( 'data-wp-interactive', true ); 25 $p->set_attribute( 'data-wp-navigation-id', 'query-' . $attributes['queryId'] ); 30 $p->set_attribute( 'data-wp-interactive', '{"namespace":"core/query"}' ); 31 $p->set_attribute( 'data-wp-router-region', 'query-' . $attributes['queryId'] ); 32 $p->set_attribute( 'data-wp-init', 'callbacks.setQueryRef' ); 26 33 // Use context to send translated strings. 27 34 $p->set_attribute( … … 29 36 wp_json_encode( 30 37 array( 31 'core' => array( 32 'query' => array( 33 'loadingText' => __( 'Loading page, please wait.' ), 34 'loadedText' => __( 'Page Loaded.' ), 35 ), 36 ), 38 'loadingText' => __( 'Loading page, please wait.' ), 39 'loadedText' => __( 'Page Loaded.' ), 37 40 ), 38 41 JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP … … 55 58 class="screen-reader-text" 56 59 aria-live="polite" 57 data-wp-text="context. core.query.message"60 data-wp-text="context.message" 58 61 ></div> 59 62 <div 60 63 class="wp-block-query__enhanced-pagination-animation" 61 data-wp-class--start-animation="s electors.core.query.startAnimation"62 data-wp-class--finish-animation="s electors.core.query.finishAnimation"64 data-wp-class--start-animation="state.startAnimation" 65 data-wp-class--finish-animation="state.finishAnimation" 63 66 ></div>', 64 67 $last_tag_position, … … 68 71 } 69 72 70 $view_asset = 'wp-block-query-view'; 71 if ( ! wp_script_is( $view_asset ) ) { 72 $script_handles = $block->block_type->view_script_handles; 73 // If the script is not needed, and it is still in the `view_script_handles`, remove it. 74 if ( 75 ( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) ) 76 && in_array( $view_asset, $script_handles, true ) 77 ) { 78 $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) ); 79 } 80 // If the script is needed, but it was previously removed, add it again. 81 if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $view_asset, $script_handles, true ) ) { 82 $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) ); 83 } 84 } 85 73 // Add the styles to the block type if the block is interactive and remove 74 // them if it's not. 86 75 $style_asset = 'wp-block-query'; 87 76 if ( ! wp_style_is( $style_asset ) ) { 88 77 $style_handles = $block->block_type->style_handles; 89 78 // If the styles are not needed, and they are still in the `style_handles`, remove them. 90 if ( 91 ( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) ) 92 && in_array( $style_asset, $style_handles, true ) 93 ) { 79 if ( ! $is_interactive && in_array( $style_asset, $style_handles, true ) ) { 94 80 $block->block_type->style_handles = array_diff( $style_handles, array( $style_asset ) ); 95 81 } 96 82 // If the styles are needed, but they were previously removed, add them again. 97 if ( $ attributes['enhancedPagination'] && isset( $attributes['queryId'] )&& ! in_array( $style_asset, $style_handles, true ) ) {83 if ( $is_interactive && ! in_array( $style_asset, $style_handles, true ) ) { 98 84 $block->block_type->style_handles = array_merge( $style_handles, array( $style_asset ) ); 99 85 } … … 102 88 return $content; 103 89 } 104 105 /**106 * Ensure that the view script has the `wp-interactivity` dependency.107 *108 * @since 6.4.0109 *110 * @global WP_Scripts $wp_scripts111 */112 function block_core_query_ensure_interactivity_dependency() {113 global $wp_scripts;114 if (115 isset( $wp_scripts->registered['wp-block-query-view'] ) &&116 ! in_array( 'wp-interactivity', $wp_scripts->registered['wp-block-query-view']->deps, true )117 ) {118 $wp_scripts->registered['wp-block-query-view']->deps[] = 'wp-interactivity';119 }120 }121 122 add_action( 'wp_print_scripts', 'block_core_query_ensure_interactivity_dependency' );123 90 124 91 /** … … 131 98 'render_callback' => 'render_block_core_query', 132 99 ) 100 ); 101 102 wp_register_script_module( 103 '@wordpress/block-library/query', 104 defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/query.min.js' ) : includes_url( 'blocks/query/view.min.js' ), 105 array( 106 array( 107 'id' => '@wordpress/interactivity', 108 'import' => 'static', 109 ), 110 array( 111 'id' => '@wordpress/interactivity-router', 112 'import' => 'dynamic', 113 ), 114 ), 115 defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) 133 116 ); 134 117 } … … 151 134 static $render_query_callback = null; 152 135 153 $block_name = $parsed_block['blockName']; 136 $is_interactive = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] ); 137 $block_name = $parsed_block['blockName']; 154 138 155 if ( 156 'core/query' === $block_name && 157 isset( $parsed_block['attrs']['enhancedPagination'] ) && 158 true === $parsed_block['attrs']['enhancedPagination'] && 159 isset( $parsed_block['attrs']['queryId'] ) 160 ) { 139 if ( 'core/query' === $block_name && $is_interactive ) { 161 140 $enhanced_query_stack[] = $parsed_block['attrs']['queryId']; 162 141 … … 173 152 */ 174 153 $render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) { 175 $has_enhanced_pagination = 176 isset( $block['attrs']['enhancedPagination'] ) && 177 true === $block['attrs']['enhancedPagination'] && 178 isset( $block['attrs']['queryId'] ); 154 $is_interactive = isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] ); 179 155 180 if ( ! $ has_enhanced_pagination) {156 if ( ! $is_interactive ) { 181 157 return $content; 182 158 }
Note: See TracChangeset
for help on using the changeset viewer.