gform_media_upload_path

Description

This filter can be used to change the location where files uploaded using the Post Image field are copied to when the post is created.

Usage

The following would apply to all forms.

add_filter( 'gform_media_upload_path', 'your_function_name', 10, 3 );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_media_upload_path_FORMID)

add_filter( 'gform_media_upload_path_5', 'your_function_name', 10, 3 );

Parameters

  • $upload_dir array

    The upload directory path and url to be filtered.

    • $upload_dir[‘path’] string

      Full physical path to the folder.

    • $upload_dir[‘url’] string

      Full URL to the folder.

  • $form_id integer

    The ID of the form currently being processed.

  • $post_id integer

    The ID of the post created from the entry currently being processed.

Examples

1. Log the current path

You can use this example with logging enabled to find out what the current path is before using the next example to change the path.

add_filter( 'gform_media_upload_path', function ( $upload_dir, $form_id ) {
    GFCommon::log_debug( "gform_media_upload_path(): upload_dir for form #{$form_id} => " . print_r( $upload_dir, true ) );

    return $path_info;
}, 1, 2 );

2. Change the path and url

This example changes the upload path and url for the File Upload field.

add_filter( 'gform_media_upload_path', 'change_media_upload_path', 10, 3 );
function change_media_upload_path( $upload_dir, $form_id, $post_id ) {
   $upload_dir['path'] = '/home/public_html/yourdomainfolder/new/path/';
   $upload_dir['url'] = 'http://yourdomainhere.com/new/path/';

   return $upload_dir;
}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GFFormsModel::copy_post_image() in forms_model.php

Since

This filter was added in Gravity Forms 1.9.14.19.