Home › Forums › Add-ons › Gallery Field › Edit the "acf-gallery-side-info" content › Reply To: Edit the "acf-gallery-side-info" content
Hi John,
I needed a looooong time to solve the entire issue but the JS API append action is exactly what I was looking for.
If someone want the complete solution I use in a PHP function file :
// Add a AJAX action to get attachement URL by ID in JS
add_action( 'wp_ajax_get_media_url', 'get_media_url' );
add_action( 'wp_ajax_nopriv_get_media_url', 'get_media_url' );
function get_media_url() {
if ( isset( $_POST['att_id'] )) {
$attachement_id = $_POST['att_id'];
$attachement_url = wp_get_attachment_url( $attachement_id );
echo $attachement_url;
} else {
echo '#';
}
wp_die();
}
// JS to add the download link
function acf_gallery_download_link() {
if ( !is_admin() ) { return; }?>
<script type='text/javascript'>
( function ( $ ) { $( document ).ready( function () {
acf.addAction('append', function( $el ){
var attachement_id = $el.find(".actions").children(".acf-gallery-edit").attr("data-id");
var data = {
'action': 'get_media_url',
'att_id': attachement_id,
};
$.post(ajaxurl, data, function(response){
var attachement_url = response;
$el.find(".actions").children(".acf-gallery-edit").before('<a href="'+ attachement_url +'" target="_blank" class="acf-gallery-see" data-id="'+attachement_id+'">See</a>');
});
});
});
}( jQuery ) );
</script>
<?php}
add_action( 'admin_footer', 'acf_gallery_download_link' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.