ACF\CLI

JsonCommand::resolve_export_keysprivateACF 6.8

Resolves export arguments into an array of ACF keys.

When no arguments are provided, collects all items across all types. Accepts keys directly (group_xxx) or labels which are matched against existing items.

Method of the class: JsonCommand{}

No Hooks.

Returns

Array. List of ACF keys to export.

Usage

// private - for code of main (parent) class only
$result = $this->resolve_export_keys( $field_groups_arg, $post_types_arg, $taxonomies_arg, $options_pages_arg );
$field_groups_arg(string|null) (required)
Comma-separated field group keys/labels.
$post_types_arg(string|null) (required)
Comma-separated post type keys/labels.
$taxonomies_arg(string|null) (required)
Comma-separated taxonomy keys/labels.
$options_pages_arg(string|null) (required)
Comma-separated options page keys/labels.

Changelog

Since 6.8 Introduced.

JsonCommand::resolve_export_keys() code ACF 6.8.8

private function resolve_export_keys( $field_groups_arg, $post_types_arg, $taxonomies_arg, $options_pages_arg ) {
	$no_filters = ! $field_groups_arg && ! $post_types_arg && ! $taxonomies_arg && ! $options_pages_arg;
	$keys       = array();

	if ( $no_filters ) {
		foreach ( $this->get_post_types() as $post_type ) {
			$keys = array_merge( $keys, $this->resolve_keys_for_type( $post_type, null ) );
		}

		return $keys;
	}

	if ( $field_groups_arg ) {
		$keys = array_merge( $keys, $this->resolve_keys_for_type( 'acf-field-group', $field_groups_arg ) );
	}

	if ( $post_types_arg ) {
		$keys = array_merge( $keys, $this->resolve_keys_for_type( 'acf-post-type', $post_types_arg ) );
	}

	if ( $taxonomies_arg ) {
		$keys = array_merge( $keys, $this->resolve_keys_for_type( 'acf-taxonomy', $taxonomies_arg ) );
	}

	if ( $options_pages_arg ) {
		if ( ! acf_is_pro() ) {
			WP_CLI::error(
				"Options pages require ACF PRO.\n\n" .
				"To export options pages, you need:\n" .
				"  - ACF PRO license\n" .
				"  - Active license key\n\n" .
				'See: https://www.advancedcustomfields.com/pro/'
			);
		}

		$keys = array_merge( $keys, $this->resolve_keys_for_type( 'acf-ui-options-page', $options_pages_arg ) );
	}

	return $keys;
}