Gravity Wiz

Magically enhanced tutorials, snippets and plugins for Gravity Forms!

  • Gravity Perks
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    • Documentation
    • Support
    • Account

Gravity Forms Media Library

Upload your files from Gravity Forms to the WordPress Media Library and Advanced Custom Fields.

This plugin is part of Gravity Perks, a suite of 32+ essential Gravity Forms addons with support you can count on.

  • View All Perks
  • Buy Gravity Perks
gp-media-library-featured-image

What does it do?

This plugin enhances Gravity Forms with the ability to automatically import uploaded files (images, documents, etc.) to the WordPress Media Library when the form is submitted.

Features

  • Automatically upload files to Media Library.
    A simple, one-click option on your Gravity Forms File Upload fields and any file uploaded from that field will be imported into the WordPress Media Library.
  • Single and multi-file uploads supported.
    Need to upload multiple files at one time? No problem!
  • Advanced Custom Fields (ACF) support.
    Automatically integrates with any ACF-powered Image or File custom field.
  • Display image thumbnails.
    Use auto-generated image merge tags to pull the exact size of the image you’d like to display.
  • Integrates with GravityView.
    Faster loading times with automatically resized images. Views display a medium-sized thumbnail instead of the huge original image.
  • Seamless, easy-to-use UI.
    Integrates directly with Gravity Forms field settings. Activate this feature with a single click.
  • Automatic updates.
    Get updates and latest features right in your dashboard.
  • Awesome support.
    We’re here to help! And we mean it.

Documentation

  1. How do I enable this functionality?
  2. Feature Details
    1. Image Merge Tags
    2. ACF Support
    3. Developer Usage
      1. Get File ID’s in a WordPress Template
      2. Get file ID for a Single File Upload field
      3. Get file ID’s for a Multi-file Upload field
      4. Get file ID of the 2nd file in a Multi-file Upload field
  3. FAQs
    1. How can I set a maximum width/height or quality for uploaded images?
    2. Will this work if I store my images with a cloud storage provider?
    3. How can I prevent WordPress from scaling down large images?
    4. How can I automatically enable this for all fields?
  4. Hooks
  5. Related Articles

How do I enable this functionality?

After installing and activating Gravity Forms Media Library, media library uploads become available in File Upload fields within any form. Let’s step through how to turn them on.

Add a File Upload field to your form.
Select the Perks tab, then check Upload to Media Library.

That’s it! Now all files and images will be uploaded to your Media Library from your form when it is submitted.


Feature Details

Image Merge Tags

GP Media Library Merge Tags

GF Media Library also supports outputting the uploaded images in Notification Emails and Confirmation Messages. This is done via merge tags.

It supports everything supported by Gravity Forms for Post Image merge tags. View Gravity Forms merge tag documentation.

You will find the available merge tags in the GP Media Library section of the Gravity Forms merge tag selector. By default, the four standard WordPress sizes will be displayed (thumbnail, medium, large, full) and up to four custom sizes per field.

You can also modify which image merge tags are available with the gpml_merge_tag_image_sizes hook

Lastly, while merge tags will still display for all File Upload fields, this will only work correctly for images that are uploaded to the field.

ACF Support

Need to integrate this with Advanced Custom Fields? No problem, we have you covered! Check out our article on How to Add Advanced Custom Fields Support for GP Media Library

Developer Usage

Here are some examples of how to retrieve the files and images that are added to the WordPress Media Library by GF Media Library.

One case where this would be useful would be to retrieve the file ID of the image in order to output different sizes of the image that are created by WordPress.

Get File ID’s in a WordPress Template
$file_ids = gp_media_library()->get_file_ids( $entry_id, $field_id, $file_index );
Get file ID for a Single File Upload field
$file_id = gp_media_library()->get_file_ids( 1234, 1 );
Get file ID’s for a Multi-file Upload field
$file_ids = gp_media_library()->get_file_ids( 1234, 2 );
Get file ID of the 2nd file in a Multi-file Upload field
$file_id = gp_media_library()->get_file_ids( 1234, 2, 1 );

FAQs

How can I set a maximum width/height or quality for uploaded images?

Use EWWW Image Optimizer to automatically optimize and resize images uploaded through GP Media Library. To set a maximum width or height, click the Resize tab in EWWW Image Optimizer’s settings and set the max width and height. No additional settings are needed for optimization.

Set Max Width and Height

Will this work if I store my images with a cloud storage provider?

Yep! If you want to offload your images onto a cloud storage provider, we recommend WP Offload Media Lite. No additional setup is needed.

How can I prevent WordPress from scaling down large images?

WordPress automatically scales very large images (>2560px) when they are imported into the Media Library. This can be disabled using this hook:

add_filter( 'big_image_size_threshold', '__return_false' );

Unless you have a specific need for allowing very large file uploads, we do not recommend removing the big image size threshold.

How can I automatically enable this for all fields?

You can use the snippet below to enable the Media Library setting on all File Upload Fields on the website, to ensure that all uploaded files are always saved in the Media Folder. The snippet will apply the setting when the form is edited.

If you later choose to deactivate this snippet, you’ll need to manually disable the Upload to Media Library setting on each field.
add_filter( 'gform_form_post_get_meta', function($form){
    foreach( $form['fields'] as &$field )  {
        if ( $field->type == 'fileupload' || $field->type == 'slim' ) {
            $field->uploadMediaLibrary = true;
        }
    }
    return $form;
});

Hooks

  • gpml_auto_convert_custom_fields
  • gpml_delete_entry_files_from_media_library
  • gpml_image_merge_tag_link_atts
  • gpml_media_data
  • gpml_merge_tag_image_sizes
  • gpml_multi_file_merge_tag_glue
  • gpml_supported_field_types
Gravity Forms has hundreds of hooks. Check out our Gravity Forms Hook Reference for the most thorough guide to Gravity Forms’ many actions and filters.

Related Articles

  • Optimize and Offload Uploaded Files with Gravity Forms
  • Add Image Previews to Gravity Forms File Upload Fields
  • How To Build a Company Directory with GravityView
  • How to Upload Files & Images from Gravity Forms to Advanced Custom Fields

Perk Deets

  • Version 1.2.16
  • Updated October 6, 2020
  • Released January 23, 2017
  • View Changelog

Changelog

1.2.16

  • Fixed an issue where GPML may generate PHP notices if no file is uploaded.
  • Fixed an issue where the uploaded file's form ID may not be captured correctly.

1.2.15

  • Fixed an issue where image size names containing a dash were not recognized in merge tags.

1.2.14

  • Fixed potential PHP notice when GF Media Library is used on a form that's also using Live Merge Tags from GF Populate Anything.

1.2.13

  • Added GP_Media_Library::acf_update_field() and refactored to use this method where possible.

1.2.12

  • Added gpml_supported_field_types filter.

1.2.11

  • Updated how file IDs are retrieved from existing file URLs to use a core WordPress function as it is more comprehensive.

1.2.10

  • Fixed issue where files with customized file paths (via gform_upload_path filter) failed importation.

1.2.9

  • Added support for populating WooCommerce product gallery when creating a product via Gravity Forms.
  • Added gpml_auto_convert_custom_fields filter to allow auto-converting any custom field.

1.2.8

  • Fixed fatal error that occurred when mapping a GPML-enabled file upload field to a custom field via the Advanced Post Creation add-on.

1.2.7

  • Added gpml_delete_entry_files_from_media_library filter to allow filtering whether files imported into the Media library should be deleted when their corresponding entry is deleted.

1.2.6

  • Fixed issue where files that failed import were deleted.

1.2.5

  • Updated error processing to allow single import failures. Previously import would fail for all images if any image failed.

1.2.4

  • Fixed issue where Media Library files were not correctly attached to Gravity Forms notifications.

1.2.3

  • Added additional logging when a file fails to upload.

1.2.2

  • Added logging support.

1.3

  • Fixed fatal error that occurred when field mapped in Advanced Post Creation feed no longer exists.

1.2.1

  • Fixed fatal error that occurred when field mapped in Advanced Post Creation feed no longer exists.

1.2

  • Added support for integrating the Advanced Custom Fields and Advanced Post Creation.

1.1

  • Added support for Slim Image Cropper for Gravity Forms.

1.0.14

  • Updated minimum GF version to actual required version: 2.0.8
  • Fixed notice that was generated on non-standard WP pages.

1.0.13

  • Fixed issue where files were uploaded to the wrong directory due to get_post() returning a post even when no post ID was passed.

1.0.12

  • Added 'gpml_media_data' filter to allow modifying media data before uploading (see: https://gravitywiz.com/documentation/gpml_media_data/).

1.0.11

  • Fixed link to documentation.

1.0.10

  • Fixed issue where all GPML-enabled image field merge tags were being treated as post images.

1.0.9

  • Fixed issue where new regex for parsing multi-file merge tag modifiers ignored all but the last modifier.

1.0.8

  • Added support for passing more than two parameters for multi-file merge tags (i.e. {File:1:thumbnail:left:link}).
  • Added 'gpml_multi_file_merge_tag_glue' filter to allow modifying the string that is used to join individual images in a multi-file image merge tag.

1.0.7

  • Fixed notice generated when checking for existing file ID when none existed.
  • Fixed notice genrated when replacing merge tags without an entry object.

1.0.6

  • Fixed issue w/ 3rd party integrations where GPML failed to correctly locate the existing attachment when the attachment URL did not match the guid.

1.0.5

  • Fixed fatal error that occurred w/ WC GF Product Add-ons (surprise!).

1.0.4

  • Added support for ":link" modifier; automatically wraps generated <img> in a link to the full sized image.
  • Added support for automatically replacing GPML-enabled field images with the medium-sized thumbnail when viewed in Gravity View.

1.0.3

  • Added support for mapping GF Multi-file Upload fields to ACF's Gallery field.

1.0.2

  • Fixed fatal error when download_url() function failed.
  • Updated upload_to_media_library() function to use original Gravity Forms image.

1.0.1

  • Added support for image merge tags (i.e. {File:1:medium} and {Multi-file Upload:2:thumbnail:right}).

1.0

  • "People can lose their lives in libraries. They ought to be warned." ~ Saul Bellow

All Perks

  • GF Auto Login
  • GF Better User Activation
  • GF Blacklist
  • GF Conditional Logic Dates
  • GF Conditional Pricing
  • GF Copy Cat
  • GF Date Time Calculator
  • GF Disable Entry Creation
  • GF Easy Passthrough
  • GF eCommerce Fields
  • GF Email Users
  • GF Expand Textareas
  • GF File Upload Pro
  • GF Limit Checkboxes
  • GF Limit Choices
  • GF Limit Dates
  • GF Limit Submissions
  • GF Live Preview
  • GF Media Library
  • GF Multi-Page Navigation
  • GF Nested Forms
  • GF Pay Per Word
  • GF PayPal One-time Fee
  • GF Placeholder
  • GF Populate Anything
  • GF Post Content Merge Tags
  • GF Preview Submission
  • GF Price Range
  • GF Read Only
  • GF Reload Form
  • GF Terms Of Service
  • GF Unique ID
  • GF Word Count

Copyright © 2021 · Powered by WordPress · Gravity Wiz LLC

  • Support
  • Affiliates
  • About
  • Sitemap
  • Gravity Perks
    ▼
    • Gravity Perks
    • Tutorials & Snippets
    • About
  • Support
    ▼
    • Documentation
    • Support
    • Account