Changeset 52316
- Timestamp:
- 12/03/2021 07:37:32 PM (3 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template.php
r52308 r52316 5 5 * @package WordPress 6 6 */ 7 8 /** 9 * Adds necessary filters to use 'wp_template' posts instead of theme template files. 10 * 11 * @access private 12 * @since 5.9.0 13 */ 14 function _add_template_loader_filters() { 15 if ( ! current_theme_supports( 'block-templates' ) ) { 16 return; 17 } 18 19 $template_types = array_keys( get_default_block_template_types() ); 20 foreach ( $template_types as $template_type ) { 21 // Skip 'embed' for now because it is not a regular template type. 22 if ( 'embed' === $template_type ) { 23 continue; 24 } 25 add_filter( str_replace( '-', '', $template_type ) . '_template', 'locate_block_template', 20, 3 ); 26 } 27 28 // Request to resolve a template. 29 if ( isset( $_GET['_wp-find-template'] ) ) { 30 add_filter( 'pre_get_posts', '_resolve_template_for_new_post' ); 31 } 32 } 7 33 8 34 /** … … 267 293 return $context; 268 294 } 295 296 /** 297 * Sets the current WP_Query to return auto-draft posts. 298 * 299 * The auto-draft status indicates a new post, so allow the the WP_Query instance to 300 * return an auto-draft post for template resolution when editing a new post. 301 * 302 * @access private 303 * @since 5.9.0 304 * 305 * @param WP_Query $wp_query Current WP_Query instance, passed by reference. 306 */ 307 function _resolve_template_for_new_post( $wp_query ) { 308 remove_filter( 'pre_get_posts', '_resolve_template_for_new_post' ); 309 310 // Pages. 311 $page_id = isset( $wp_query->query['page_id'] ) ? $wp_query->query['page_id'] : null; 312 313 // Posts, including custom post types. 314 $p = isset( $wp_query->query['p'] ) ? $wp_query->query['p'] : null; 315 316 $post_id = $page_id ? $page_id : $p; 317 $post = get_post( $post_id ); 318 319 if ( 320 $post && 321 'auto-draft' === $post->post_status && 322 current_user_can( 'edit_post', $post->ID ) 323 ) { 324 $wp_query->set( 'post_status', 'auto-draft' ); 325 } 326 } -
trunk/src/wp-includes/default-filters.php
r52272 r52316 681 681 add_action( 'wp_footer', 'the_block_template_skip_link' ); 682 682 add_action( 'setup_theme', 'wp_enable_block_templates' ); 683 add_action( 'wp_loaded', '_add_template_loader_filters' ); 683 684 684 685 unset( $filter, $action );
Note: See TracChangeset
for help on using the changeset viewer.