class-avcf-acf-abilities.php
1 month ago
class-avcf-acf-content-models.php
1 month ago
class-avcf-acf-detector.php
1 month ago
class-avcf-acf-field-groups.php
1 month ago
class-avcf-acf-helpers.php
1 month ago
class-avcf-acf-abilities.php
108 lines
| 1 | <?php |
| 2 | /** |
| 3 | * ACF — Abilities orchestrator. |
| 4 | * |
| 5 | * Single entry point that registers the read-only check-setup baseline and |
| 6 | * dispatches the field-group and content-model ability classes. Called from |
| 7 | * doit/class-avcf-mcp.php inside the ACF-available check; each ability class |
| 8 | * still sentinel-checks ACF as defence-in-depth. |
| 9 | * |
| 10 | * Files dispatched: |
| 11 | * class-avcf-acf-field-groups.php 5 abilities |
| 12 | * class-avcf-acf-content-models.php 15 abilities (CPT/taxonomy/options ×5) |
| 13 | * (this file) 1 ability (acf-check-setup) |
| 14 | * ───────────── |
| 15 | * 21 abilities total |
| 16 | * |
| 17 | * @package atarim-visual-collaboration |
| 18 | */ |
| 19 | |
| 20 | if ( ! defined('ABSPATH') ) { |
| 21 | exit; |
| 22 | } |
| 23 | |
| 24 | class AVCF_Abilities_ACF extends AVCF_Abilities_Base { |
| 25 | |
| 26 | /** |
| 27 | * @var AVCF_ACF_Detector |
| 28 | */ |
| 29 | private $detector; |
| 30 | |
| 31 | public function __construct() { |
| 32 | $this->detector = new AVCF_ACF_Detector(); |
| 33 | } |
| 34 | |
| 35 | public function register() { |
| 36 | if ( ! $this->detector->avcf_acf_is_available() ) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | $detector = $this->detector; |
| 41 | |
| 42 | // ---- acf-check-setup ---- |
| 43 | wp_register_ability( 'atarim/acf-check-setup', [ |
| 44 | 'label' => 'Check ACF Setup', |
| 45 | 'description' => 'Call this first before any other ACF ability. Reports whether ACF is active, the edition (free / pro), the version, whether the post-type / taxonomy / options-page management abilities are available (these require ACF Pro 6.5+), and counts of currently registered field groups, ACF post types, ACF taxonomies, and ACF options pages. Zero counts mean you are starting fresh.', |
| 46 | 'category' => 'atarim', |
| 47 | 'input_schema' => [ |
| 48 | 'type' => 'object', |
| 49 | 'properties' => [], |
| 50 | 'additionalProperties' => false, |
| 51 | ], |
| 52 | 'output_schema' => [ |
| 53 | 'type' => 'object', |
| 54 | 'properties' => [ |
| 55 | 'success' => [ 'type' => 'boolean' ], |
| 56 | 'active' => [ 'type' => 'boolean' ], |
| 57 | 'edition' => [ 'type' => 'string' ], |
| 58 | 'version' => [ 'type' => 'string' ], |
| 59 | 'supports_content_model_mgmt' => [ 'type' => 'boolean' ], |
| 60 | 'field_groups_count' => [ 'type' => 'integer' ], |
| 61 | 'post_types_count' => [ 'type' => 'integer' ], |
| 62 | 'taxonomies_count' => [ 'type' => 'integer' ], |
| 63 | 'options_pages_count' => [ 'type' => 'integer' ], |
| 64 | 'message' => [ 'type' => 'string' ], |
| 65 | ], |
| 66 | 'required' => [ 'success', 'active', 'message' ], |
| 67 | ], |
| 68 | 'execute_callback' => function( $input = [] ) use ( $detector ) { |
| 69 | $active = $detector->avcf_acf_is_available(); |
| 70 | if ( ! $active ) { |
| 71 | return [ 'success' => true, 'active' => false, 'message' => 'ACF is not active on this site.' ]; |
| 72 | } |
| 73 | $supports = $detector->avcf_acf_supports_internal_post_types(); |
| 74 | $fg_count = function_exists( 'acf_get_field_groups' ) ? count( (array) acf_get_field_groups() ) : 0; |
| 75 | $cpt = $tax = $opt = 0; |
| 76 | if ( $supports ) { |
| 77 | $cpt = count( (array) acf_get_internal_post_type_posts( 'acf-post-type' ) ); |
| 78 | $tax = count( (array) acf_get_internal_post_type_posts( 'acf-taxonomy' ) ); |
| 79 | $opt = count( (array) acf_get_internal_post_type_posts( 'acf-ui-options-page' ) ); |
| 80 | } |
| 81 | return [ |
| 82 | 'success' => true, |
| 83 | 'active' => true, |
| 84 | 'edition' => $detector->avcf_acf_edition(), |
| 85 | 'version' => $detector->avcf_acf_version(), |
| 86 | 'supports_content_model_mgmt' => $supports, |
| 87 | 'field_groups_count' => $fg_count, |
| 88 | 'post_types_count' => $cpt, |
| 89 | 'taxonomies_count' => $tax, |
| 90 | 'options_pages_count' => $opt, |
| 91 | 'message' => 'OK.', |
| 92 | ]; |
| 93 | }, |
| 94 | 'permission_callback' => function() { |
| 95 | return current_user_can( 'manage_options' ); |
| 96 | }, |
| 97 | 'meta' => [ |
| 98 | 'mcp' => [ 'public' => true, 'type' => 'tool' ], |
| 99 | 'annotations' => [ 'readonly' => true, 'destructive' => false, 'idempotent' => true ], |
| 100 | ], |
| 101 | ] ); |
| 102 | |
| 103 | // Dispatch the domain clusters. |
| 104 | ( new AVCF_ACF_Field_Groups() )->register(); |
| 105 | ( new AVCF_ACF_Content_Models() )->register(); |
| 106 | } |
| 107 | } |
| 108 |