PluginProbe
Gutenberg / 6.6.0
Gutenberg v6.6.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / templates.php

templates.php in Gutenberg 6.6.0, at lib/templates.php

68 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Block template functions.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Registers block editor 'wp_template' post type.
10 */
11 function gutenberg_register_template_post_type() {
12 if (
13 get_option( 'gutenberg-experiments' ) &&
14 ! array_key_exists( 'gutenberg-full-site-editing', get_option( 'gutenberg-experiments' ) )
15 ) {
16 return;
17 }
18
19 $labels = array(
20 'name' => __( 'Templates', 'gutenberg' ),
21 );
22
23 $args = array(
24 'labels' => $labels,
25 'description' => __( 'Templates to include in your theme.', 'gutenberg' ),
26 'public' => false,
27 'has_archive' => false,
28 'show_in_rest' => true,
29 'rest_base' => 'templates',
30 'capability_type' => array( 'template', 'templates' ),
31 'map_meta_cap' => true,
32 'supports' => array(
33 'title',
34 'editor',
35 'revisions',
36 ),
37 );
38
39 register_post_type( 'wp_template', $args );
40 }
41 add_action( 'init', 'gutenberg_register_template_post_type' );
42
43 /**
44 * Filters the capabilities of a user to conditionally grant them capabilities for managing 'wp_template' posts.
45 *
46 * Any user who can 'edit_theme_options' will have access.
47 *
48 * @param array $allcaps A user's capabilities.
49 * @return array Filtered $allcaps.
50 */
51 function gutenberg_grant_template_caps( array $allcaps ) {
52 if ( isset( $allcaps['edit_theme_options'] ) ) {
53 $allcaps['edit_templates'] = $allcaps['edit_theme_options'];
54 $allcaps['edit_others_templates'] = $allcaps['edit_theme_options'];
55 $allcaps['edit_published_templates'] = $allcaps['edit_theme_options'];
56 $allcaps['edit_private_templates'] = $allcaps['edit_theme_options'];
57 $allcaps['delete_templates'] = $allcaps['edit_theme_options'];
58 $allcaps['delete_others_templates'] = $allcaps['edit_theme_options'];
59 $allcaps['delete_published_templates'] = $allcaps['edit_theme_options'];
60 $allcaps['delete_private_templates'] = $allcaps['edit_theme_options'];
61 $allcaps['publish_templates'] = $allcaps['edit_theme_options'];
62 $allcaps['read_private_templates'] = $allcaps['edit_theme_options'];
63 }
64
65 return $allcaps;
66 }
67 add_filter( 'user_has_cap', 'gutenberg_grant_template_caps' );
68