ACF\AI

AI::render_acf_ai_tabpublicACF 6.8.0

Renders the ACF AI tab in various contexts.

Метод класса: AI{}

Хуков нет.

Возвращает

void. Ничего (null).

Использование

$AI = new AI();
$AI->render_acf_ai_tab( $item );
$item(массив) (обязательный)
The field group, post type, taxonomy, etc. being edited.

Список изменений

С версии 6.8.0 Введена.

Код AI::render_acf_ai_tab() ACF 6.8.8

public function render_acf_ai_tab( array $item ) {
	if ( empty( $item['key'] ) ) {
		return;
	}

	$item_type = acf_determine_internal_post_type( $item['key'] );
	if ( ! $item_type ) {
		return;
	}

	$item_type           = str_replace( '-', '_', $item_type );
	$post_id             = (int) acf_request_arg( 'post', 0 );
	$allow_ai_access_val = ! empty( $item['allow_ai_access'] ) ? 1 : 0;

	// If this is a new item, default to allowing AI access.
	if ( ! $post_id ) {
		$allow_ai_access_val = 1;
	}

	$allow_access_label   = __( 'Allow AI Access', 'acf' );
	$allow_access_desc    = __( 'Allow AI systems to access and modify this content through the WordPress Abilities API.', 'acf' );
	$ai_description_label = __( 'AI Description', 'acf' );
	$ai_description_desc  = __( 'Provide a description that will help AI systems understand the purpose and how to use this effectively.', 'acf' );

	if ( 'acf_post_type' === $item_type ) {
		$allow_access_label   = __( 'Allow AI Access to Post Content', 'acf' );
		$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' );
		$ai_description_label = __( 'AI Guidance for Post Type', 'acf' );
		$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' );
	}

	if ( 'acf_taxonomy' === $item_type ) {
		$allow_access_label   = __( 'Allow AI Access to Taxonomy Terms', 'acf' );
		$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' );
		$ai_description_label = __( 'AI Guidance for Taxonomy', 'acf' );
		$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' );
	}

	if ( 'acf_field_group' === $item_type ) {
		$allow_access_label   = __( 'Allow AI Access to Field Data', 'acf' );
		$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' );
		$ai_description_label = __( 'AI Context Description', 'acf' );
		$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' );
	}

	acf_render_field_wrap(
		array(
			'type'         => 'true_false',
			'name'         => 'allow_ai_access',
			'key'          => 'allow_ai_access',
			'prefix'       => $item_type,
			'value'        => $allow_ai_access_val,
			'label'        => $allow_access_label,
			'instructions' => $allow_access_desc,
			'ui'           => true,
			'default'      => 1,
		)
	);

	acf_render_field_wrap(
		array(
			'type'         => 'textarea',
			'name'         => 'ai_description',
			'key'          => 'ai_description',
			'prefix'       => $item_type,
			'value'        => $item['ai_description'] ?? '',
			'label'        => $ai_description_label,
			'instructions' => $ai_description_desc,
			'rows'         => 4,
			'conditions'   => array(
				array(
					'field'    => 'allow_ai_access',
					'operator' => '==',
					'value'    => '1',
				),
			),
		),
		'div',
		'field'
	);
}