Skip to content
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 7 commits into from
Sep 27, 2019
12 changes: 12 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-block-directory',
)
);
add_settings_field(
'gutenberg-full-site-editing',
__( 'Full Site Editing', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Enable Full Site Editing', 'gutenberg' ),
'id' => 'gutenberg-full-site-editing',
)
);
register_setting(
'gutenberg-experiments',
'gutenberg-experiments'
Expand Down Expand Up @@ -124,6 +135,7 @@ function gutenberg_experiments_editor_settings( $settings ) {
'__experimentalEnableLegacyWidgetBlock' => $experiments_exist ? array_key_exists( 'gutenberg-widget-experiments', get_option( 'gutenberg-experiments' ) ) : false,
'__experimentalEnableMenuBlock' => $experiments_exist ? array_key_exists( 'gutenberg-menu-block', get_option( 'gutenberg-experiments' ) ) : false,
'__experimentalBlockDirectory' => $experiments_exist ? array_key_exists( 'gutenberg-block-directory', get_option( 'gutenberg-experiments' ) ) : false,
'__experimentalEnableFullSiteEditing' => $experiments_exist ? array_key_exists( 'gutenberg-full-site-editing', get_option( 'gutenberg-experiments' ) ) : false,
Copy link
Contributor

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


);
return array_merge( $settings, $experiments_settings );
Expand Down
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
require dirname( __FILE__ ) . '/compat.php';

require dirname( __FILE__ ) . '/blocks.php';
require dirname( __FILE__ ) . '/templates.php';
require dirname( __FILE__ ) . '/client-assets.php';
require dirname( __FILE__ ) . '/demo.php';
require dirname( __FILE__ ) . '/widgets.php';
Expand Down
67 changes: 67 additions & 0 deletions lib/templates.php
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already the default.

'has_archive' => false,
Copy link
Contributor

Choose a reason for hiding this comment

The 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' );