acf_field_gallery::ajax_get_attachment
AJAX handler for retrieving and rendering an attachment.
Method of the class: acf_field_gallery{}
No Hooks.
Returns
void. Nothing (null).
Usage
$acf_field_gallery = new acf_field_gallery(); $acf_field_gallery->ajax_get_attachment();
Changelog
| Since 5.0.0 | Introduced. |
acf_field_gallery::ajax_get_attachment() acf field gallery::ajax get attachment code ACF 6.8.8
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, 'gallery' ) ) {
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;
}