Support

Account

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' );