acf_field_gallery::ajax_get_attachmentpublicACF 5.0.0

AJAX handler for retrieving and rendering an attachment.

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

Хуков нет.

Возвращает

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

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

$acf_field_gallery = new acf_field_gallery();
$acf_field_gallery->ajax_get_attachment();

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

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

Код acf_field_gallery::ajax_get_attachment() ACF 6.4.2

public function ajax_get_attachment() {
	// Get args.
	$args = acf_request_args(
		array(
			'id'        => 0,
			'field_key' => '',
			'nonce'     => '',
		)
	);

	// Validate request.
	if ( ! acf_verify_ajax( $args['nonce'], $args['field_key'], true ) ) {
		die();
	}

	// Cast args.
	$args['id'] = (int) $args['id'];

	// Bail early if no id.
	if ( ! $args['id'] ) {
		die();
	}

	// Load field.
	$field = acf_get_field( $args['field_key'] );
	if ( ! $field ) {
		die();
	}

	// Render.
	$this->render_attachment( $args['id'], $field );
	die;
}