acf_add_local_field_group()ACF 5.7.10

acf_add_local_field_group

Adds a local field group.

Хуков нет.

Возвращает

true|false.

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

acf_add_local_field_group( $field_group );
$field_group(массив) (обязательный)
The field group array.

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

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

Код acf_add_local_field_group() ACF 6.0.4

function acf_add_local_field_group( $field_group ) {

	// Apply default properties needed for import.
	$field_group = wp_parse_args(
		$field_group,
		array(
			'key'    => '',
			'title'  => '',
			'fields' => array(),
			'local'  => 'php',
		)
	);

	// Generate key if only name is provided.
	if ( ! $field_group['key'] ) {
		$field_group['key'] = 'group_' . acf_slugify( $field_group['title'], '_' );
	}

	// Bail early if field group already exists.
	if ( acf_is_local_field_group( $field_group['key'] ) ) {
		return false;
	}

	// Prepare field group for import (adds menu_order and parent properties to fields).
	$field_group = acf_prepare_field_group_for_import( $field_group );

	// Extract fields from group.
	$fields = acf_extract_var( $field_group, 'fields' );

	// Add to store
	acf_get_local_store( 'groups' )->set( $field_group['key'], $field_group );

	// Add fields
	if ( $fields ) {
		acf_add_local_fields( $fields );
	}

	// Return true on success.
	return true;
}