I figured it out:
global $current_foogallery;
$gallery_id = $current_foogallery->ID;
Good to know, care to share what your use case for this was? I’m interested.
I want my thumbnails to come from WordPress’s media library and be public (foogallery’s default behavior) but I want the clicked link to go to a protected fullsize image via Amazon S3/Cloudfront (using the s2member plugin). I saved the path to the full-size Amazon gallery as custom post meta with the foogallery, but I needed the gallery ID to pull it out again within the filter.
This functionality is possible within the vanilla plugin by adding a custom target link in the image attributes, but I’m not gonna do that for hundreds of photos individually! So I filtered the link output.
I’ll probably wrap all this up in a proper plugin eventually, but for now I just needed it to work. And it does now! 🙂
function protected_img_urls($attr) {
global $current_foogallery;
$gallery_id = $current_foogallery->ID;
$protectedpath = trim(get_post_meta( $gallery_id, 'protected_img_url', true ));
$lastchar = substr($protectedpath, -1);
if($lastchar != "/") {
$protectedpath .= "/";
}
$img_path = $attr['href'];
//explode with '/' and take only last section.
$pieces = explode("/", $img_path);
$img_path = end($pieces);
$attr['href'] = get_site_url()."/?s2member_file_download=".$protectedpath.$img_path."&s2member_skip_confirmation";
return $attr;
}
add_filter( 'foogallery_attachment_html_link_attributes', 'protected_img_urls' );
}