Support

Account

Home Forums Add-ons Gallery Field Interacting with the gallery fields wp.media frame

Solving

Interacting with the gallery fields wp.media frame

  • I’m looking to run a javascript when gallery images are successfully uploaded. I’ve done this for the wordpress featured image meta box using this method: http://stackoverflow.com/questions/30085701/wordpress-wp-media-featured-image-id

    Is there something similar I can do with the gallery meta box? If I look into acf-pro-input.js I can see that it calls the media frame

    var frame = acf.media.popup({
    	title:		acf._e('gallery', 'select'),

    Not sure how I can interact with it though. acf._e is available in the chrome javascript console. But it does not contain .frame() or .get()..

    Any help? Not even sure if it works similar to featured images box since featured image is just one images while the gallery is multiple..

  • Hi @intelligence

    To be honest I’ve never tried to hook into anything like this..
    Have you checked what wp.media contains when setting images for the gallery field?

    Also, just out of curiosity, to what end do you need this? 🙂

  • Ah. Yes I plan on running a little script called color thief (https://github.com/lokesh/color-thief/) I will save the values generated from the script and use it for styling.

    Actually, wp.media.gallery exist, but can’t see any attachments to it, hm. wp.media.gallery.attachments exist but only links to a function in media-edtior.js:

    * @param {wp.shortcode} shortcode An instance of wp.shortcode().
    * @returns {wp.media.model.Attachments} A Backbone.Collection containing
    * the media items belonging to a collection.
    * The query[ this.tag ] property is a Backbone.Model
    * containing the ‘props’ for the collection.

  • Ah nice. I suppose a hacky solution would be to do this on the front end instead, checking for an existing value beforehand so it’s only done once.

    Hm, I would’ve thought you’d see some attachments there.
    so wp.media.gallery.attachments does not return anything from that function? Based on that comment it seems it should’ve returned the media items.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Interacting with the gallery fields wp.media frame’ is closed to new replies.