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.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / src / AI / AI.php
advanced-custom-fields / src / AI Last commit date
Abilities 3 months ago GEO 5 months ago AI.php 5 months ago
AI.php
197 lines
1 <?php
2 /**
3 * @package ACF
4 * @author WP Engine
5 *
6 * © 2026 Advanced Custom Fields (ACF®). All rights reserved.
7 * "ACF" is a trademark of WP Engine.
8 * Licensed under the GNU General Public License v2 or later.
9 * https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 namespace ACF\AI;
13
14 use ACF\AI\Abilities\Abilities;
15 use ACF\AI\GEO\GEO;
16
17 /**
18 * Initializes the ACF AI functionality if enabled.
19 */
20 class AI {
21
22 /**
23 * Constructs the AI class.
24 *
25 * @since 6.8.0
26 *
27 * @return void
28 */
29 public function __construct() {
30 add_action( 'acf/init', array( $this, 'initialize' ) );
31 }
32
33 /**
34 * Initializes the AI functionality.
35 *
36 * @since 6.8.0
37 *
38 * @return void
39 */
40 public function initialize() {
41 if ( $this->is_geo_enabled() ) {
42 new GEO();
43 }
44
45 if ( $this->is_ai_enabled() ) {
46 new Abilities();
47 $this->add_admin_ui_hooks();
48 }
49 }
50
51 /**
52 * Checks if AI functionality is enabled.
53 *
54 * @since 6.8.0
55 *
56 * @return boolean
57 */
58 public function is_ai_enabled(): bool {
59 return (bool) acf_get_setting( 'enable_acf_ai' );
60 }
61
62 /**
63 * Checks if GEO functionality is enabled.
64 *
65 * @since 6.8.0
66 *
67 * @return boolean
68 */
69 public function is_geo_enabled(): bool {
70 return (bool) acf_get_setting( 'enable_schema' );
71 }
72
73 /**
74 * Adds admin UI hooks.
75 *
76 * @since 6.8.0
77 *
78 * @return void
79 */
80 public function add_admin_ui_hooks() {
81 // Add ACF AI tab to field groups.
82 add_filter( 'acf/field_group/additional_group_settings_tabs', array( $this, 'add_acf_ai_tab' ) );
83 add_action( 'acf/field_group/render_group_settings_tab/acf-ai', array( $this, 'render_acf_ai_tab' ) );
84
85 // Add ACF AI tab to post types.
86 add_filter( 'acf/post_type/additional_settings_tabs', array( $this, 'add_acf_ai_tab' ) );
87 add_action( 'acf/post_type/render_settings_tab/acf-ai', array( $this, 'render_acf_ai_tab' ) );
88
89 // Add ACF AI tab to taxonomies.
90 add_filter( 'acf/taxonomy/additional_settings_tabs', array( $this, 'add_acf_ai_tab' ) );
91 add_action( 'acf/taxonomy/render_settings_tab/acf-ai', array( $this, 'render_acf_ai_tab' ) );
92 }
93
94 /**
95 * Registers the AI tab in various contexts.
96 *
97 * @since 6.8.0
98 *
99 * @param array $tabs The existing tabs array.
100 * @return array
101 */
102 public function add_acf_ai_tab( array $tabs ): array {
103 $tabs['acf-ai'] = __( 'ACF AI', 'acf' );
104 return $tabs;
105 }
106
107 /**
108 * Renders the ACF AI tab in various contexts.
109 *
110 * @since 6.8.0
111 *
112 * @param array $item The field group, post type, taxonomy, etc. being edited.
113 * @return void
114 */
115 public function render_acf_ai_tab( array $item ) {
116 if ( empty( $item['key'] ) ) {
117 return;
118 }
119
120 $item_type = acf_determine_internal_post_type( $item['key'] );
121 if ( ! $item_type ) {
122 return;
123 }
124
125 $item_type = str_replace( '-', '_', $item_type );
126 $post_id = (int) acf_request_arg( 'post', 0 );
127 $allow_ai_access_val = ! empty( $item['allow_ai_access'] ) ? 1 : 0;
128
129 // If this is a new item, default to allowing AI access.
130 if ( ! $post_id ) {
131 $allow_ai_access_val = 1;
132 }
133
134 $allow_access_label = __( 'Allow AI Access', 'acf' );
135 $allow_access_desc = __( 'Allow AI systems to access and modify this content through the WordPress Abilities API.', 'acf' );
136 $ai_description_label = __( 'AI Description', 'acf' );
137 $ai_description_desc = __( 'Provide a description that will help AI systems understand the purpose and how to use this effectively.', 'acf' );
138
139 if ( 'acf_post_type' === $item_type ) {
140 $allow_access_label = __( 'Allow AI Access to Post Content', 'acf' );
141 $allow_access_desc = __( 'When enabled, AI models can access and interact with the content of posts in this post type using supported integrations. This feature uses the WordPress Abilities API.', 'acf' );
142 $ai_description_label = __( 'AI Guidance for Post Type', 'acf' );
143 $ai_description_desc = __( "Add a short explanation of what this post type is for. The clearer your description, the better the AI's output will be.", 'acf' );
144 }
145
146 if ( 'acf_taxonomy' === $item_type ) {
147 $allow_access_label = __( 'Allow AI Access to Taxonomy Terms', 'acf' );
148 $allow_access_desc = __( 'When enabled, AI models can access and interact with the terms in this taxonomy using supported integrations. This feature uses the WordPress Abilities API.', 'acf' );
149 $ai_description_label = __( 'AI Guidance for Taxonomy', 'acf' );
150 $ai_description_desc = __( "Add a short explanation of what this taxonomy is for. The clearer your description, the better the AI's output will be.", 'acf' );
151 }
152
153 if ( 'acf_field_group' === $item_type ) {
154 $allow_access_label = __( 'Allow AI Access to Field Data', 'acf' );
155 $allow_access_desc = __( 'When enabled, AI models can access and interact with the fields in this group using supported integrations. This feature uses the WordPress Abilities API.', 'acf' );
156 $ai_description_label = __( 'AI Context Description', 'acf' );
157 $ai_description_desc = __( "Add a short explanation of what this field group is for. The clearer your description, the better the AI's output will be.", 'acf' );
158 }
159
160 acf_render_field_wrap(
161 array(
162 'type' => 'true_false',
163 'name' => 'allow_ai_access',
164 'key' => 'allow_ai_access',
165 'prefix' => $item_type,
166 'value' => $allow_ai_access_val,
167 'label' => $allow_access_label,
168 'instructions' => $allow_access_desc,
169 'ui' => true,
170 'default' => 1,
171 )
172 );
173
174 acf_render_field_wrap(
175 array(
176 'type' => 'textarea',
177 'name' => 'ai_description',
178 'key' => 'ai_description',
179 'prefix' => $item_type,
180 'value' => $item['ai_description'] ?? '',
181 'label' => $ai_description_label,
182 'instructions' => $ai_description_desc,
183 'rows' => 4,
184 'conditions' => array(
185 array(
186 'field' => 'allow_ai_access',
187 'operator' => '==',
188 'value' => '1',
189 ),
190 ),
191 ),
192 'div',
193 'field'
194 );
195 }
196 }
197