• Resolved StenCade

    (@stencade)


    I am trying to filter output using the 'foogallery_attachment_html_link_attributes' filter. I have added a function to my functions.php file and have it working the way I want by manually entering the ID of my test gallery, but I can’t figure out how to set that variable dynamically. I feel like this should be easy to figure out, but maybe it’s just late and I’m too tired to think about variable scope properly. Anyway, thanks for any help you can give!

    https://www.ads-software.com/plugins/foogallery/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter StenCade

    (@stencade)

    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.

    Thread Starter StenCade

    (@stencade)

    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' );
        }
    Plugin Author bradvin

    (@bradvin)

    very nice @stencade!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get Gallery ID in a filter function’ is closed to new replies.