-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-post-type.php
More file actions
154 lines (145 loc) · 5.09 KB
/
class-post-type.php
File metadata and controls
154 lines (145 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
namespace Big_Bite\Release_Notes;
/**
* Release Note Post Type
*/
class PostType {
/**
* Constructor.
*/
public function __construct() {
add_action( 'init', [ $this, 'register_post_type' ], 0 );
add_filter( 'allowed_block_types_all', [ $this, 'allow_post_types' ], PHP_INT_MAX, 2 );
add_action( 'init', [ $this, 'register_meta' ] );
}
/**
* Register post type meta
*
* @return void
*/
public function register_meta(): void {
register_post_meta(
'release-note',
'version',
[
'show_in_rest' => [
'schema' => [
'type' => 'string',
'default' => '0.0.0',
],
],
'single' => true,
'type' => 'string',
],
);
register_post_meta(
'release-note',
'release_date',
[
'show_in_rest' => true,
'single' => true,
'type' => 'string',
]
);
}
/**
* Register Post type.
*
* @return void
*/
public function register_post_type(): void {
$labels = [
'name' => _x( 'Release Notes', 'Post Type General Name', 'release-notes' ),
'singular_name' => _x( 'Release Note', 'Post Type Singular Name', 'release-notes' ),
'menu_name' => __( 'Release Notes', 'release-notes' ),
'name_admin_bar' => __( 'Release Note', 'release-notes' ),
'archives' => __( 'Release Notes', 'release-notes' ),
'attributes' => __( 'Release Note Attributes', 'release-notes' ),
'parent_item_colon' => __( 'Parent Release:', 'release-notes' ),
'all_items' => __( 'All Release Notes', 'release-notes' ),
'add_new_item' => __( 'Add New Release Note', 'release-notes' ),
'add_new' => __( 'Add New', 'release-notes' ),
'new_item' => __( 'New Release Note', 'release-notes' ),
'edit_item' => __( 'Edit Release Note', 'release-notes' ),
'update_item' => __( 'Update Release Note', 'release-notes' ),
'view_item' => __( 'View Release Note', 'release-notes' ),
'view_items' => __( 'View Release Note', 'release-notes' ),
'search_items' => __( 'Search Release Note', 'release-notes' ),
'not_found' => __( 'Not found', 'release-notes' ),
'not_found_in_trash' => __( 'Not found in Trash', 'release-notes' ),
'featured_image' => __( 'Featured Image', 'release-notes' ),
'set_featured_image' => __( 'Set featured image', 'release-notes' ),
'remove_featured_image' => __( 'Remove featured image', 'release-notes' ),
'use_featured_image' => __( 'Use as featured image', 'release-notes' ),
'insert_into_item' => __( 'Insert into Release Note', 'release-notes' ),
'uploaded_to_this_item' => __( 'Uploaded to this release note', 'release-notes' ),
'items_list' => __( 'Release Notes list', 'release-notes' ),
'items_list_navigation' => __( 'Release Notes list navigation', 'release-notes' ),
'filter_items_list' => __( 'Filter Release Notes list', 'release-notes' ),
];
$capabilities = [
'edit_post' => 'manage_options',
'read_post' => 'manage_options',
'delete_post' => 'manage_options',
'edit_posts' => 'manage_options',
'edit_others_posts' => 'manage_options',
'publish_posts' => 'manage_options',
'read_private_posts' => 'manage_options',
];
$args = [
'label' => __( 'Release Note', 'release-notes' ),
'description' => __( 'Release Notes', 'release-notes' ),
'labels' => $labels,
'supports' => [ 'title', 'editor', 'revisions', 'custom-fields' ],
'taxonomies' => [],
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'menu_position' => 5,
'show_in_admin_bar' => false,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'capabilities' => $capabilities,
'template' => [
[ 'core/heading', [ 'content' => 'Overview' ] ],
[ 'core/paragraph' ],
[ 'core/heading', [ 'content' => 'Added' ] ],
[ 'core/list' ],
[ 'core/heading', [ 'content' => 'Changed' ] ],
[ 'core/list' ],
[ 'core/heading', [ 'content' => 'Fixed' ] ],
[ 'core/list' ],
],
];
register_post_type( 'release-note', $args );
}
/**
* Register post type blocks
*
* @param array|bool $allowed_block_types - current allowed block types
* @param \WP_Block_Editor_Context $context - editor context.
* @return array|bool
*/
public function allow_post_types( array|bool $allowed_block_types, \WP_Block_Editor_Context $context ): array|bool {
if ( ! $context->post ) {
return $allowed_block_types;
}
return match ( $context->post->post_type ) {
'release-note' => [
'core/heading',
'core/paragraph',
'core/list',
'core/list-item',
'core/image',
'core/video',
'release-notes/markdown-parser',
],
default => $allowed_block_types,
};
}
}