Make WordPress Core


Ignore:
Timestamp:
11/08/2021 11:09:53 PM (3 years ago)
Author:
noisysocks
Message:

Editor: Add block theme infrastructure

Adds the required infrastructure to render block-based themes. This is sourced
from the Gutenberg plugin.

Fixes #54335.
Props bernhard-reiter, youknowriad, ntsekouras, hellofromtonya.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/theme-templates.php

    r51199 r52062  
    11<?php
     2
     3/**
     4 * Sets a custom slug when creating auto-draft template parts.
     5 *
     6 * This is only needed for auto-drafts created by the regular WP editor.
     7 * If this page is to be removed, this won't be necessary.
     8 *
     9 * @since 5.9.0
     10 *
     11 */
     12function wp_set_unique_slug_on_create_template_part( $post_id ) {
     13    $post = get_post( $post_id );
     14    if ( 'auto-draft' !== $post->post_status ) {
     15        return;
     16    }
     17
     18    if ( ! $post->post_name ) {
     19        wp_update_post(
     20            array(
     21                'ID'        => $post_id,
     22                'post_name' => 'custom_slug_' . uniqid(),
     23            )
     24        );
     25    }
     26
     27    $terms = get_the_terms( $post_id, 'wp_theme' );
     28    if ( ! is_array( $terms ) || ! count( $terms ) ) {
     29        wp_set_post_terms( $post_id, wp_get_theme()->get_stylesheet(), 'wp_theme' );
     30    }
     31}
    232
    333/**
     
    1545 */
    1646function wp_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type ) {
    17     if ( 'wp_template' !== $post_type ) {
     47    if ( 'wp_template' !== $post_type && 'wp_template_part' !== $post_type ) {
    1848        return $override_slug;
    1949    }
Note: See TracChangeset for help on using the changeset viewer.