I've faced with a problem. I use Mafnific popup. Below the popup I add a button to download image and different actions like social icons etc.
so, I need to find out a filesize of image uploaded to media of Wordpress. I have js variable where I have link to image.
For this in functions.php I put a function for searching id of this image by link like this:
function pippin_get_image_id($image_url) {
global $wpdb;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ));
return $attachment[0];
}
And now I can find out the filesize if I put a link of image to this function like this:
echo size_format(filesize( get_attached_file(pippin_get_image_id($link)) ),2);
But the main problem is: I am now inside js script and I need to pass to function a JS variable var link:
Inside a function I have a snippet:
return '<a href="' + link + '" download target="_blank" class="btn btn-success" id="original">Download (<?php echo size_format(filesize( get_attached_file(pippin_get_image_id( VARIABLE LINK )) ),2); ?>)</a>
p.s. see where VARIABLE LINK is. How can I put js variable there ?
Thank you so much in advance!