ACF\AI\GEO

FieldSettings::ajax_get_output_formatspublicACF 6.8.0

AJAX handler to get output format choices for a field type + property combination.

Method of the class: FieldSettings{}

No Hooks.

Returns

null. Nothing (null).

Usage

$FieldSettings = new FieldSettings();
$FieldSettings->ajax_get_output_formats();

Changelog

Since 6.8.0 Introduced.

FieldSettings::ajax_get_output_formats() code ACF 6.8.8

public function ajax_get_output_formats() {
	// Verify request.
	if ( ! acf_verify_ajax() ) {
		wp_send_json_error(
			new WP_Error(
				'acf_invalid_nonce',
				__( 'Invalid nonce.', 'acf' )
			)
		);
	}

	// Verify user can admin.
	if ( ! acf_current_user_can_admin() ) {
		wp_send_json_error(
			new WP_Error(
				'acf_invalid_permissions',
				__( 'Sorry, you do not have permission to do that.', 'acf' )
			)
		);
	}

	$field_type         = acf_request_arg( 'field_type', '' );
	$qualified_property = acf_request_arg( 'property', '' );
	$property           = Schema::get_property_name( $qualified_property );

	if ( empty( $field_type ) || empty( $property ) ) {
		wp_send_json_error(
			new WP_Error(
				'acf_invalid_param',
				__( 'Missing required parameters', 'acf' )
			)
		);
	}

	$choices       = array();
	$valid_formats = Schema::get_valid_output_formats( $field_type, $property );

	foreach ( $valid_formats as $format ) {
		$choices[] = array(
			'id'   => $format,
			'text' => $format,
		);
	}

	$default = Schema::get_default_output_format( $field_type, $property );

	wp_send_json_success(
		array(
			'choices' => $choices,
			'default' => $default,
		)
	);
}