PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.5.4
Secure Custom Fields v6.5.4
6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / assets / src / js / commands / admin-commands.js
secure-custom-fields / assets / src / js / commands Last commit date
admin-commands.js 1 year ago custom-post-type-commands.js 1 year ago
admin-commands.js
208 lines
1 /**
2 * Admin Commands
3 *
4 * Core WordPress commands for Secure Custom Fields administration.
5 * This file registers navigation commands for all primary SCF admin screens,
6 * enabling quick access through the WordPress commands interface (Cmd+K / Ctrl+K).
7 *
8 * @since SCF 6.5.0
9 */
10
11 /**
12 * WordPress dependencies
13 */
14 import { __ } from '@wordpress/i18n';
15 import { createElement } from '@wordpress/element';
16 import { Icon } from '@wordpress/components';
17 import { dispatch } from '@wordpress/data';
18 import { addQueryArgs } from '@wordpress/url';
19 import { layout, plus, postList, category, settings, tool, upload, download } from '@wordpress/icons';
20
21 /**
22 * Register admin commands for SCF
23 */
24 const registerAdminCommands = () => {
25 if ( ! dispatch( 'core/commands' ) || ! window.acf?.data ) {
26 return;
27 }
28
29 const commandStore = dispatch( 'core/commands' );
30 const adminUrl = window.acf?.data?.admin_url || '';
31
32 const commands = [
33 {
34 name: 'field-groups',
35 label: __( 'Field Groups', 'secure-custom-fields' ),
36 url: 'edit.php',
37 urlArgs: { post_type: 'acf-field-group' },
38 icon: layout,
39 description: __(
40 'SCF: View and manage custom field groups',
41 'secure-custom-fields'
42 ),
43 keywords: [
44 'acf',
45 'custom fields',
46 'field editor',
47 'manage fields',
48 ],
49 },
50 {
51 name: 'new-field-group',
52 label: __( 'Create New Field Group', 'secure-custom-fields' ),
53 url: 'post-new.php',
54 urlArgs: { post_type: 'acf-field-group' },
55 icon: plus,
56 description: __(
57 'SCF: Create a new field group to organize custom fields',
58 'secure-custom-fields'
59 ),
60 keywords: [
61 'add',
62 'new',
63 'create',
64 'field group',
65 'custom fields',
66 ],
67 },
68 {
69 name: 'post-types',
70 label: __( 'Post Types', 'secure-custom-fields' ),
71 url: 'edit.php',
72 urlArgs: { post_type: 'acf-post-type' },
73 icon: postList,
74 description: __(
75 'SCF: Manage custom post types',
76 'secure-custom-fields'
77 ),
78 keywords: [ 'cpt', 'content types', 'manage post types' ],
79 },
80 {
81 name: 'new-post-type',
82 label: __( 'Create New Post Type', 'secure-custom-fields' ),
83 url: 'post-new.php',
84 urlArgs: { post_type: 'acf-post-type' },
85 icon: plus,
86 description: __(
87 'SCF: Create a new custom post type',
88 'secure-custom-fields'
89 ),
90 keywords: [ 'add', 'new', 'create', 'cpt', 'content type' ],
91 },
92 {
93 name: 'taxonomies',
94 label: __( 'Taxonomies', 'secure-custom-fields' ),
95 url: 'edit.php',
96 urlArgs: { post_type: 'acf-taxonomy' },
97 icon: category,
98 description: __(
99 'SCF: Manage custom taxonomies for organizing content',
100 'secure-custom-fields'
101 ),
102 keywords: [ 'categories', 'tags', 'terms', 'custom taxonomies' ],
103 },
104 {
105 name: 'new-taxonomy',
106 label: __( 'Create New Taxonomy', 'secure-custom-fields' ),
107 url: 'post-new.php',
108 urlArgs: { post_type: 'acf-taxonomy' },
109 icon: plus,
110 description: __(
111 'SCF: Create a new custom taxonomy',
112 'secure-custom-fields'
113 ),
114 keywords: [
115 'add',
116 'new',
117 'create',
118 'taxonomy',
119 'categories',
120 'tags',
121 ],
122 },
123 {
124 name: 'options-pages',
125 label: __( 'Options Pages', 'secure-custom-fields' ),
126 url: 'edit.php',
127 urlArgs: { post_type: 'acf-ui-options-page' },
128 icon: settings,
129 description: __(
130 'SCF: Manage custom options pages for global settings',
131 'secure-custom-fields'
132 ),
133 keywords: [ 'settings', 'global options', 'site options' ],
134 },
135 {
136 name: 'new-options-page',
137 label: __( 'Create New Options Page', 'secure-custom-fields' ),
138 url: 'post-new.php',
139 urlArgs: { post_type: 'acf-ui-options-page' },
140 icon: plus,
141 description: __(
142 'SCF: Create a new custom options page',
143 'secure-custom-fields'
144 ),
145 keywords: [ 'add', 'new', 'create', 'options', 'settings page' ],
146 },
147 {
148 name: 'tools',
149 label: __( 'SCF Tools', 'secure-custom-fields' ),
150 url: 'admin.php',
151 urlArgs: { page: 'acf-tools' },
152 icon: tool,
153 description: __(
154 'SCF: Access SCF utility tools',
155 'secure-custom-fields'
156 ),
157 keywords: [ 'utilities', 'import export', 'json' ],
158 },
159 {
160 name: 'import',
161 label: __( 'Import SCF Data', 'secure-custom-fields' ),
162 url: 'admin.php',
163 urlArgs: { page: 'acf-tools', tool: 'import' },
164 icon: upload,
165 description: __(
166 'SCF: Import field groups, post types, taxonomies, and options pages',
167 'secure-custom-fields'
168 ),
169 keywords: [ 'upload', 'json', 'migration', 'transfer' ],
170 },
171 {
172 name: 'export',
173 label: __( 'Export SCF Data', 'secure-custom-fields' ),
174 url: 'admin.php',
175 urlArgs: { page: 'acf-tools', tool: 'export' },
176 icon: download,
177 description: __(
178 'SCF: Export field groups, post types, taxonomies, and options pages',
179 'secure-custom-fields'
180 ),
181 keywords: [ 'download', 'json', 'backup', 'migration' ],
182 },
183 ];
184
185 commands.forEach( ( command ) => {
186 commandStore.registerCommand( {
187 name: 'scf/' + command.name,
188 label: command.label,
189 icon: createElement( Icon, { icon: command.icon } ),
190 context: 'admin',
191 description: command.description,
192 keywords: command.keywords,
193 callback: ( { close } ) => {
194 document.location = command.urlArgs
195 ? addQueryArgs( adminUrl + command.url, command.urlArgs )
196 : adminUrl + command.url;
197 close();
198 },
199 } );
200 } );
201 };
202
203 if ( 'requestIdleCallback' in window ) {
204 window.requestIdleCallback( registerAdminCommands, { timeout: 500 } );
205 } else {
206 setTimeout( registerAdminCommands, 500 );
207 }
208