PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.8.1
Secure Custom Fields v6.8.1
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 / includes / admin / admin-commands.php
secure-custom-fields / includes / admin Last commit date
beta-features 7 months ago post-types 10 months ago tools 7 months ago views 7 months ago admin-commands.php 1 year ago admin-internal-post-type-list.php 10 months ago admin-internal-post-type.php 1 year ago admin-notices.php 1 year ago admin-tools.php 10 months ago admin-upgrade.php 1 year ago admin.php 10 months ago beta-features.php 7 months ago class-acf-admin-options-page.php 7 months ago index.php 1 year ago
admin-commands.php
83 lines
1 <?php
2 /**
3 * SCF Commands Integration
4 *
5 * @package Secure Custom Fields
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Initializes SCF commands integration
14 *
15 * This function handles the integration with WordPress Commands (Cmd+K / Ctrl+K),
16 * providing navigation commands for SCF admin pages and custom post types.
17 *
18 * The implementation follows these principles:
19 * 1. Only loads in screens where WordPress commands are available.
20 * 2. Performs capability checks to ensure users only see commands they can access.
21 * 3. Core administrative commands are only shown to users with SCF admin capabilities.
22 * 4. Custom post type commands are conditionally shown based on edit_posts capability
23 * for each specific post type.
24 * 5. Post types must have UI enabled (show_ui setting) to appear in commands.
25 *
26 * @since SCF 6.5.0
27 */
28 function acf_commands_init() {
29 // Ensure we only load our commands where the WordPress commands API is available.
30 if ( ! wp_script_is( 'wp-commands', 'registered' ) ) {
31 return;
32 }
33
34 $custom_post_types = array();
35
36 $scf_post_types = acf_get_acf_post_types();
37
38 foreach ( $scf_post_types as $post_type ) {
39 // Skip if post type name is not set (defensive) or post type is inactive.
40 if ( empty( $post_type['post_type'] ) || ( isset( $post_type['active'] ) && ! $post_type['active'] ) ) {
41 continue;
42 }
43
44 $post_type_obj = get_post_type_object( $post_type['post_type'] );
45
46 // Three conditions must be met to include this post type in the commands:
47 // 1. Post type object must exist
48 // 2. Current user must have permission to edit posts of this type.
49 // 3. Post type must have admin UI enabled (show_ui setting).
50 if ( $post_type_obj &&
51 current_user_can( $post_type_obj->cap->edit_posts ) &&
52 $post_type_obj->show_ui ) {
53
54 $labels = get_post_type_labels( $post_type_obj );
55
56 $custom_post_types[] = array(
57 'name' => $post_type['post_type'],
58 'all_items' => $labels->all_items,
59 'add_new_item' => $labels->add_new_item,
60 'icon' => $post_type['menu_icon'] ?? '',
61 'label' => $labels->name,
62 'id' => $post_type['ID'],
63 );
64 }
65 }
66
67 if ( ! empty( $custom_post_types ) ) {
68 acf_localize_data(
69 array(
70 'customPostTypes' => $custom_post_types,
71 )
72 );
73 wp_enqueue_script( 'scf-commands-custom-post-types' );
74 }
75
76 // Only load admin commands if user has SCF admin capabilities.
77 if ( current_user_can( acf_get_setting( 'capability' ) ) ) {
78 wp_enqueue_script( 'scf-commands-admin' );
79 }
80 }
81
82 add_action( 'admin_enqueue_scripts', 'acf_commands_init' );
83