Changeset 57578 for trunk/src/wp-includes/blocks/query.php
- Timestamp:
- 02/09/2024 06:20:12 PM (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/query.php
r57377 r57578 18 18 */ 19 19 function render_block_core_query( $attributes, $content, $block ) { 20 $is_interactive = isset( $attributes['enhancedPagination'] ) && true === $attributes['enhancedPagination'] && isset( $attributes['queryId'] ); 20 $is_interactive = isset( $attributes['enhancedPagination'] ) 21 && true === $attributes['enhancedPagination'] 22 && isset( $attributes['queryId'] ); 21 23 22 24 // Enqueue the script module and add the necessary directives if the block is 23 25 // interactive. 24 26 if ( $is_interactive ) { 27 $suffix = wp_scripts_get_suffix(); 28 if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { 29 $module_url = gutenberg_url( '/build/interactivity/query.min.js' ); 30 } 31 32 wp_register_script_module( 33 '@wordpress/block-library/query', 34 isset( $module_url ) ? $module_url : includes_url( "blocks/query/view{$suffix}.js" ), 35 array( 36 array( 37 'id' => '@wordpress/interactivity', 38 'import' => 'static', 39 ), 40 array( 41 'id' => '@wordpress/interactivity-router', 42 'import' => 'dynamic', 43 ), 44 ), 45 defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) 46 ); 25 47 wp_enqueue_script_module( '@wordpress/block-library/query' ); 26 48 … … 31 53 $p->set_attribute( 'data-wp-router-region', 'query-' . $attributes['queryId'] ); 32 54 $p->set_attribute( 'data-wp-init', 'callbacks.setQueryRef' ); 33 // Use context to send translated strings. 34 $p->set_attribute( 35 'data-wp-context', 36 wp_json_encode( 37 array( 38 'loadingText' => __( 'Loading page, please wait.' ), 39 'loadedText' => __( 'Page Loaded.' ), 40 ), 41 JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP 42 ) 43 ); 55 $p->set_attribute( 'data-wp-context', '{}' ); 44 56 $content = $p->get_updated_html(); 45 46 // Mark the block as interactive.47 $block->block_type->supports['interactivity'] = true;48 49 // Add a div to announce messages using `aria-live`.50 $html_tag = 'div';51 if ( ! empty( $attributes['tagName'] ) ) {52 $html_tag = esc_attr( $attributes['tagName'] );53 }54 $last_tag_position = strripos( $content, '</' . $html_tag . '>' );55 $content = substr_replace(56 $content,57 '<div58 class="screen-reader-text"59 aria-live="polite"60 data-wp-text="context.message"61 ></div>62 <div63 class="wp-block-query__enhanced-pagination-animation"64 data-wp-class--start-animation="state.startAnimation"65 data-wp-class--finish-animation="state.finishAnimation"66 ></div>',67 $last_tag_position,68 069 );70 57 } 71 58 } … … 99 86 ) 100 87 ); 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' )116 );117 88 } 118 89 add_action( 'init', 'register_block_core_query' ); … … 134 105 static $render_query_callback = null; 135 106 136 $is_interactive = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] ); 137 $block_name = $parsed_block['blockName']; 107 $block_name = $parsed_block['blockName']; 108 $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name ); 109 $has_enhanced_pagination = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] ); 110 /* 111 * Client side navigation can be true in two states: 112 * - supports.interactivity = true; 113 * - supports.interactivity.clientNavigation = true; 114 */ 115 $supports_client_navigation = ( isset( $block_type->supports['interactivity']['clientNavigation'] ) && true === $block_type->supports['interactivity']['clientNavigation'] ) 116 || ( isset( $block_type->supports['interactivity'] ) && true === $block_type->supports['interactivity'] ); 138 117 139 if ( 'core/query' === $block_name && $ is_interactive) {118 if ( 'core/query' === $block_name && $has_enhanced_pagination ) { 140 119 $enhanced_query_stack[] = $parsed_block['attrs']['queryId']; 141 120 … … 152 131 */ 153 132 $render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) { 154 $ is_interactive= isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] );133 $has_enhanced_pagination = isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] ); 155 134 156 if ( ! $ is_interactive) {135 if ( ! $has_enhanced_pagination ) { 157 136 return $content; 158 137 } 159 138 160 139 if ( isset( $dirty_enhanced_queries[ $block['attrs']['queryId'] ] ) ) { 161 $p = new WP_HTML_Tag_Processor( $content ); 162 if ( $p->next_tag() ) { 163 $p->set_attribute( 'data-wp-navigation-disabled', 'true' ); 164 } 165 $content = $p->get_updated_html(); 140 // Disable navigation in the router store config. 141 wp_interactivity_config( 'core/router', array( 'clientNavigationDisabled' => true ) ); 166 142 $dirty_enhanced_queries[ $block['attrs']['queryId'] ] = null; 167 143 } … … 182 158 ! empty( $enhanced_query_stack ) && 183 159 isset( $block_name ) && 184 ( ! str_starts_with( $block_name, 'core/' ) || 'core/post-content' === $block_name)160 ( ! $supports_client_navigation ) 185 161 ) { 186 162 foreach ( $enhanced_query_stack as $query_id ) {
Note: See TracChangeset
for help on using the changeset viewer.