Make WordPress Core


Ignore:
Timestamp:
04/07/2022 01:33:03 PM (3 years ago)
Author:
gziolo
Message:

Site Editor: Resolve homepage template on server-side

Backports change from Gutenberg to support server-side home template resolution in the Site Editor. Original PR https://github.com/WordPress/gutenberg/pull/38817.

Props Mamaduka.
See #55505.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template.php

    r52697 r53093  
    332332    }
    333333}
     334
     335/**
     336 * Returns the correct template for the site's home page.
     337 *
     338 * @access private
     339 * @since 6.0.0
     340 *
     341 * @return array|null A template object, or null if none could be found.
     342 */
     343function _resolve_home_block_template() {
     344    $show_on_front = get_option( 'show_on_front' );
     345    $front_page_id = get_option( 'page_on_front' );
     346
     347    if ( 'page' === $show_on_front && $front_page_id ) {
     348        return array(
     349            'postType' => 'page',
     350            'postId'   => $front_page_id,
     351        );
     352    }
     353
     354    $hierarchy = array( 'front-page', 'home', 'index' );
     355    $template  = resolve_block_template( 'home', $hierarchy, '' );
     356
     357    if ( ! $template ) {
     358        return null;
     359    }
     360
     361    return array(
     362        'postType' => 'wp_template',
     363        'postId'   => $template->id,
     364    );
     365}
Note: See TracChangeset for help on using the changeset viewer.