Skip to content

Commit 0e65f48

Browse files
authored
Add command to manage the Custom Post Type (#170)
1 parent d03ce77 commit 0e65f48

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

assets/src/js/commands/custom-post-type-commands.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Dynamic commands for user-created custom post types in Secure Custom Fields.
55
* This file generates navigation commands for each registered post type that
6-
* the current user has access to, creating both "View All" and "Add New" commands.
6+
* the current user has access to, creating "View All", "Add New", and "Edit" commands.
77
*
88
* Post type data is provided via acf.data.customPostTypes, which is populated
99
* by the PHP side after capability checks ensure the user has appropriate access.
@@ -77,7 +77,7 @@ const registerPostTypeCommands = () => {
7777
'create',
7878
'content',
7979
postType.name,
80-
...( postType.label ? [ postType.label ] : [] ),
80+
postType.label,
8181
],
8282
callback: ( { close } ) => {
8383
document.location = addQueryArgs(adminUrl + 'post-new.php', {
@@ -86,6 +86,31 @@ const registerPostTypeCommands = () => {
8686
close();
8787
},
8888
} );
89+
90+
// Register "Edit Post Type" command for registered CPTs
91+
commandStore.registerCommand( {
92+
name: `scf/edit-${ postType.name }`,
93+
label: sprintf(__('Edit post type: %s', 'secure-custom-fields'), postType.label),
94+
icon: createElement( Icon, { icon: 'edit' } ),
95+
context: 'admin',
96+
description: sprintf(__('Edit the %s post type settings', 'secure-custom-fields'), postType.label),
97+
keywords: [
98+
'edit',
99+
'modify',
100+
'post type',
101+
'cpt',
102+
'settings',
103+
postType.name,
104+
postType.label,
105+
],
106+
callback: ( { close } ) => {
107+
document.location = addQueryArgs(adminUrl + 'post.php', {
108+
post: postType.id,
109+
action: 'edit'
110+
});
111+
close();
112+
},
113+
} );
89114
} );
90115
};
91116

includes/admin/admin-commands.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ function acf_commands_init() {
5858
'all_items' => $labels->all_items,
5959
'add_new_item' => $labels->add_new_item,
6060
'icon' => $post_type['menu_icon'] ?? '',
61+
'label' => $labels->name,
62+
'id' => $post_type['ID'],
6163
);
6264
}
6365
}

0 commit comments

Comments
 (0)