-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce wp_template
post type and use it for full-site templates
#17513
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4285d1
Introduce wp_template post type.
felixarntz 62e9d0e
Improve (temporary) admin UI for wp_template post type by exposing slug.
felixarntz 230a234
Implement template loader overrides to rely on 'wp_template' posts.
felixarntz 915f34b
Render viewport meta tag.
felixarntz 3a61491
Prevent deletion of fallback 'wp_template' post 'index'.
felixarntz d835348
Scope PR to just basic wp_template post type registration.
felixarntz a7cc91f
Merge branch 'master' into add/block-templates
felixarntz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Block template functions. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Registers block editor 'wp_template' post type. | ||
*/ | ||
function gutenberg_register_template_post_type() { | ||
if ( | ||
get_option( 'gutenberg-experiments' ) && | ||
! array_key_exists( 'gutenberg-full-site-editing', get_option( 'gutenberg-experiments' ) ) | ||
) { | ||
return; | ||
} | ||
|
||
$labels = array( | ||
'name' => __( 'Templates', 'gutenberg' ), | ||
); | ||
|
||
$args = array( | ||
'labels' => $labels, | ||
'description' => __( 'Templates to include in your theme.', 'gutenberg' ), | ||
'public' => false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already the default. |
||
'has_archive' => false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already the default. |
||
'show_in_rest' => true, | ||
'rest_base' => 'templates', | ||
'capability_type' => array( 'template', 'templates' ), | ||
'map_meta_cap' => true, | ||
'supports' => array( | ||
'title', | ||
'editor', | ||
'revisions', | ||
), | ||
); | ||
|
||
register_post_type( 'wp_template', $args ); | ||
} | ||
add_action( 'init', 'gutenberg_register_template_post_type' ); | ||
|
||
/** | ||
* Filters the capabilities of a user to conditionally grant them capabilities for managing 'wp_template' posts. | ||
* | ||
* Any user who can 'edit_theme_options' will have access. | ||
* | ||
* @param array $allcaps A user's capabilities. | ||
* @return array Filtered $allcaps. | ||
*/ | ||
function gutenberg_grant_template_caps( array $allcaps ) { | ||
if ( isset( $allcaps['edit_theme_options'] ) ) { | ||
$allcaps['edit_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['edit_others_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['edit_published_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['edit_private_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['delete_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['delete_others_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['delete_published_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['delete_private_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['publish_templates'] = $allcaps['edit_theme_options']; | ||
$allcaps['read_private_templates'] = $allcaps['edit_theme_options']; | ||
} | ||
|
||
return $allcaps; | ||
} | ||
add_filter( 'user_has_cap', 'gutenberg_grant_template_caps' ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few more places where we have to update things because of this change.
See: 2aa1d04