ACF\AI\Abilities

PostType::get_custom_post_typespublicACF 6.8.0

Callback for the "acf/get-custom-post-types" ability.

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

Хуков нет.

Возвращает

array.

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

$PostType = new PostType();
$PostType->get_custom_post_types( $input );
$input(массив) (обязательный)
An array of input args.

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

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

Код PostType::get_custom_post_types() ACF 6.8.8

public function get_custom_post_types( $input ) {
	unset( $input ); // Not used, but required by interface.

	// Get ACF custom post types.
	$acf_post_types    = acf_get_acf_post_types();
	$custom_post_types = array();

	foreach ( $acf_post_types as $acf_post_type ) {
		$post_type_name = $acf_post_type['post_type'] ?? '';
		if ( ! $post_type_name ) {
			continue;
		}

		if ( empty( $acf_post_type['active'] ) || empty( $acf_post_type['allow_ai_access'] ) ) {
			continue;
		}

		$post_type_object = get_post_type_object( $post_type_name );
		if ( $post_type_object ) {
			$post_type_data = array(
				'post_type'    => $post_type_name,
				'label'        => $post_type_object->label,
				'labels'       => (array) $post_type_object->labels,
				'description'  => $post_type_object->description,
				'public'       => $post_type_object->public,
				'hierarchical' => $post_type_object->hierarchical,
				'supports'     => get_all_post_type_supports( $post_type_name ),
				'acf_settings' => $acf_post_type,
			);

			// Add ACF field groups information
			$acf_fields = $this->get_acf_fields_for_object( 'post_type', $post_type_name );
			if ( ! empty( $acf_fields ) ) {
				$post_type_data['acf_field_groups'] = $acf_fields;
			}

			$custom_post_types[] = $post_type_data;
		}
	}

	$count = count( $custom_post_types );

	return array(
		'custom_post_types' => $custom_post_types,
		'count'             => $count,
		'message'           => sprintf(
			/* translators: %d: Number of ACF custom post types */
			_n( 'Found %d ACF custom post type', 'Found %d ACF custom post types', $count, 'acf' ),
			$count
		),
	);
}