PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.8.1
Secure Custom Fields v6.8.1
6.9.5 6.9.4 6.9.3 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 7 months ago custom-post-type-commands.js 7 months ago
admin-commands.js
231 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 {
20 layout,
21 plus,
22 postList,
23 category,
24 settings,
25 tool,
26 upload,
27 download,
28 } from '@wordpress/icons';
29
30 /**
31 * Register admin commands for SCF
32 */
33 const registerAdminCommands = () => {
34 if ( ! dispatch( 'core/commands' ) || ! window.acf?.data ) {
35 return;
36 }
37
38 const commandStore = dispatch( 'core/commands' );
39 const adminUrl = window.acf?.data?.admin_url || '';
40
41 const viewCommands = [
42 {
43 name: 'field-groups',
44 label: __( 'Field Groups', 'secure-custom-fields' ),
45 url: 'edit.php',
46 urlArgs: { post_type: 'acf-field-group' },
47 icon: layout,
48 description: __(
49 'SCF: View and manage custom field groups',
50 'secure-custom-fields'
51 ),
52 keywords: [
53 'acf',
54 'custom fields',
55 'field editor',
56 'manage fields',
57 ],
58 },
59 {
60 name: 'post-types',
61 label: __( 'Post Types', 'secure-custom-fields' ),
62 url: 'edit.php',
63 urlArgs: { post_type: 'acf-post-type' },
64 icon: postList,
65 description: __(
66 'SCF: Manage custom post types',
67 'secure-custom-fields'
68 ),
69 keywords: [ 'cpt', 'content types', 'manage post types' ],
70 },
71 {
72 name: 'taxonomies',
73 label: __( 'Taxonomies', 'secure-custom-fields' ),
74 url: 'edit.php',
75 urlArgs: { post_type: 'acf-taxonomy' },
76 icon: category,
77 description: __(
78 'SCF: Manage custom taxonomies for organizing content',
79 'secure-custom-fields'
80 ),
81 keywords: [ 'categories', 'tags', 'terms', 'custom taxonomies' ],
82 },
83 {
84 name: 'options-pages',
85 label: __( 'Options Pages', 'secure-custom-fields' ),
86 url: 'edit.php',
87 urlArgs: { post_type: 'acf-ui-options-page' },
88 icon: settings,
89 description: __(
90 'SCF: Manage custom options pages for global settings',
91 'secure-custom-fields'
92 ),
93 keywords: [ 'settings', 'global options', 'site options' ],
94 },
95 {
96 name: 'tools',
97 label: __( 'SCF Tools', 'secure-custom-fields' ),
98 url: 'admin.php',
99 urlArgs: { page: 'acf-tools' },
100 icon: tool,
101 description: __(
102 'SCF: Access SCF utility tools',
103 'secure-custom-fields'
104 ),
105 keywords: [ 'utilities', 'import export', 'json' ],
106 },
107 {
108 name: 'import',
109 label: __( 'Import SCF Data', 'secure-custom-fields' ),
110 url: 'admin.php',
111 urlArgs: { page: 'acf-tools', tool: 'import' },
112 icon: upload,
113 description: __(
114 'SCF: Import field groups, post types, taxonomies, and options pages',
115 'secure-custom-fields'
116 ),
117 keywords: [ 'upload', 'json', 'migration', 'transfer' ],
118 },
119 {
120 name: 'export',
121 label: __( 'Export SCF Data', 'secure-custom-fields' ),
122 url: 'admin.php',
123 urlArgs: { page: 'acf-tools', tool: 'export' },
124 icon: download,
125 description: __(
126 'SCF: Export field groups, post types, taxonomies, and options pages',
127 'secure-custom-fields'
128 ),
129 keywords: [ 'download', 'json', 'backup', 'migration' ],
130 },
131 ];
132
133 // Create commands - not in SCF's admin menu, so not duplicated.
134 const createCommands = [
135 {
136 name: 'new-field-group',
137 label: __( 'Create New Field Group', 'secure-custom-fields' ),
138 url: 'post-new.php',
139 urlArgs: { post_type: 'acf-field-group' },
140 icon: plus,
141 description: __(
142 'SCF: Create a new field group to organize custom fields',
143 'secure-custom-fields'
144 ),
145 keywords: [
146 'add',
147 'new',
148 'create',
149 'field group',
150 'custom fields',
151 ],
152 },
153 {
154 name: 'new-post-type',
155 label: __( 'Create New Post Type', 'secure-custom-fields' ),
156 url: 'post-new.php',
157 urlArgs: { post_type: 'acf-post-type' },
158 icon: plus,
159 description: __(
160 'SCF: Create a new custom post type',
161 'secure-custom-fields'
162 ),
163 keywords: [ 'add', 'new', 'create', 'cpt', 'content type' ],
164 },
165 {
166 name: 'new-taxonomy',
167 label: __( 'Create New Taxonomy', 'secure-custom-fields' ),
168 url: 'post-new.php',
169 urlArgs: { post_type: 'acf-taxonomy' },
170 icon: plus,
171 description: __(
172 'SCF: Create a new custom taxonomy',
173 'secure-custom-fields'
174 ),
175 keywords: [
176 'add',
177 'new',
178 'create',
179 'taxonomy',
180 'categories',
181 'tags',
182 ],
183 },
184 {
185 name: 'new-options-page',
186 label: __( 'Create New Options Page', 'secure-custom-fields' ),
187 url: 'post-new.php',
188 urlArgs: { post_type: 'acf-ui-options-page' },
189 icon: plus,
190 description: __(
191 'SCF: Create a new custom options page',
192 'secure-custom-fields'
193 ),
194 keywords: [ 'add', 'new', 'create', 'options', 'settings page' ],
195 },
196 ];
197
198 const registerCommand = ( command ) => {
199 commandStore.registerCommand( {
200 name: 'scf/' + command.name,
201 label: command.label,
202 icon: createElement( Icon, { icon: command.icon } ),
203 context: 'admin',
204 description: command.description,
205 keywords: command.keywords,
206 callback: ( { close } ) => {
207 document.location = command.urlArgs
208 ? addQueryArgs( adminUrl + command.url, command.urlArgs )
209 : adminUrl + command.url;
210 close();
211 },
212 } );
213 };
214
215 // WordPress 6.9+ adds Command Palette commands for all admin menu items.
216 const wpVersion = window.acf.data.wp_version;
217 const isWp69Plus =
218 wpVersion.localeCompare( '6.9', undefined, { numeric: true } ) >= 0;
219
220 if ( ! isWp69Plus ) {
221 viewCommands.forEach( registerCommand );
222 }
223 createCommands.forEach( registerCommand );
224 };
225
226 if ( 'requestIdleCallback' in window ) {
227 window.requestIdleCallback( registerAdminCommands, { timeout: 500 } );
228 } else {
229 setTimeout( registerAdminCommands, 500 );
230 }
231