_resolve_template_for_new_post

The timeline below displays how wordpress function _resolve_template_for_new_post has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Sets the current WP_Query to return auto-draft posts.
 *
 * The auto-draft status indicates a new post, so allow the the WP_Query instance to
 * return an auto-draft post for template resolution when editing a new post.
 *
 * @access private
 * @since 5.9.0
 *
 * @param WP_Query $wp_query Current WP_Query instance, passed by reference.
 */
function _resolve_template_for_new_post($wp_query)
{
    if (!$wp_query->is_main_query()) {
        return;
    }
    remove_filter('pre_get_posts', '_resolve_template_for_new_post');
    // Pages.
    $page_id = isset($wp_query->query['page_id']) ? $wp_query->query['page_id'] : null;
    // Posts, including custom post types.
    $p = isset($wp_query->query['p']) ? $wp_query->query['p'] : null;
    $post_id = $page_id ? $page_id : $p;
    $post = get_post($post_id);
    if ($post && 'auto-draft' === $post->post_status && current_user_can('edit_post', $post->ID)) {
        $wp_query->set('post_status', 'auto-draft');
    }
}

WordPress Version: 5.9

/**
 * Sets the current WP_Query to return auto-draft posts.
 *
 * The auto-draft status indicates a new post, so allow the the WP_Query instance to
 * return an auto-draft post for template resolution when editing a new post.
 *
 * @access private
 * @since 5.9.0
 *
 * @param WP_Query $wp_query Current WP_Query instance, passed by reference.
 */
function _resolve_template_for_new_post($wp_query)
{
    remove_filter('pre_get_posts', '_resolve_template_for_new_post');
    // Pages.
    $page_id = isset($wp_query->query['page_id']) ? $wp_query->query['page_id'] : null;
    // Posts, including custom post types.
    $p = isset($wp_query->query['p']) ? $wp_query->query['p'] : null;
    $post_id = $page_id ? $page_id : $p;
    $post = get_post($post_id);
    if ($post && 'auto-draft' === $post->post_status && current_user_can('edit_post', $post->ID)) {
        $wp_query->set('post_status', 'auto-draft');
    }
}