Rcwd Upload for Gravity Forms WP Plugin

Created: 01/08/2013
Last update: 08/02/2017
By: Roberto Cantarano
Website: http://www.cantarano.com
Twitter: https://twitter.com/robertowd
Facebook: https://facebook.com/rc.webdesigner

Thank you for purchasing my add-on.
If you have any questions that are beyond the scope of this help file, please send me an email at rcwdsupport@cantarano.com.

Intro

This add-on extends the functionality of the free Wordpress plugin Gravity Forms.

This add-on extends the functionality of the premium Wordpress plugin Gravity Forms.

It allows to add a new single file upload field that is not related to the WP media core.

Yes, you will not find the loaded file inside the media manager, also it uses a different folder for every location (based on form id, field id and entry id). Also, you can activate the option to let user upload more than 1 file!!!

NEW FEATURES!

New WP filter to manage file title position: gforms_rcwdupload_title_mode

Other features

New WP filters to manage custom rename tags: gforms_rcwdupload_rename_tags and gforms_rcwdupload_rename_tags_replace
New available tag for the rename field: [field:ID], now you can use the content from other fields
New JS trigger to customize upload filters ( gformsrcwdupload_filters and gformsrcwdupload_object). See F.A.Q. section
Available tags for the rename field ( [form_id], [field_id], [lead_id], [fieldlabel] )
Upload in chunks (by using the filter gforms_rcwdupload_chunks)
Setting for IMAGE THUMB AFTER UPLOAD
WOOCOMMERCE QUICK CHECKOUT COMPATIBILITY (needs "WooCommerce Gravity Forms Product Addons")
AUTO UPDATER (experimental, be careful, alway made a backup before do it).
Gravity Forms 1.9 ready.
Support for SAVE AND CONTINUE (GF 1.9 feature)
Javascript triggers.
Sortable. Reorder elements in list using drag&drop (if repeater option is On).
Support for image preview before upload with size settings! (for all modern browsers)
Option for autoupload after file selection
Option for rename the file (if repeater is active, a progressive numeric suffix will be added)
Option for weight limit (KB or MB)
WOOCOMMERCE 2.1.8+ COMPATIBILITY (needs "WooCommerce Gravity Forms Product Addons")
WOOCOMMERCE Catalog Visibility Options COMPATIBILITY
Options for resizing (clientside and serverside)
Options for filtering the allowed extensions
Repeater option! Yes you can let users to upload more to add additional upload fields
Support for drag&drop
Useful filters that will let you customize some stuff (new filters will be added to next releases)
Option for add a title field
Compatible with "Gravity Forms User Registration" plugin
Filename edit in admin (as requested from some of you): Now you can change the filename when editing an entry
New option available (as requested from some of you): Hide the browse button after file selection
New option available (as requested from some of you): Start the repeater with n fields
Language translation for english and italian
improved MULTISITE NETWORK COMPATIBILITY
improved UPLOAD PROCESSING AND STABILITY
improved GRAVITY VIEW COMPATIBILITY (needs "Gravity View Addon")
improved GRAVITY VIEW DATATABLES ADD-ON COMPATIBILITY (needs "Gravity View Add-on and Datatables Add-on")
added new filters to manage content in Gravity View:
     gforms_rcwdupload_gravityview_entry_mode and gforms_rcwdupload_gravityview_item
Ready-to-use PHP functions for getting url or path of the files


Gravity Forms compatibility

This add-on requires Gravity Forms v1.7+ and Wordpress v3.5+


Installation

STEP 1

**Install the Plugin**
  • Copy the 'gravityforms-rcwdupload' folder into your plugins folder;
  • Activate the plugin via the Plugins admin page.

STEP 2

After the installation, you have to fill a form to verify the purchase: you will find a new submenu page in your FORMS menu.
Click on "Rcwd Upload settings" and fill the fields (under each field you will find instructions on how to get the info you need).


How to use

After installing the add-on you will see a new field type added to the Standard Field toolbox in the Form Editor when creating or editing a Gravity Form.

Click on it to add it to the form and configure the fields options to your liking.

It is automatically includer as part of the {all_fields} merge tag output.


Ready-to-use functions

Important:
argument $single (optional): if TRUE, return only the first value (In a multifile context, it will retrieve only the first file)
argument field_id (required): to get the field id, go to form editor page, click the field to collapse it and check the ID value.

The following functions are useful for getting url or file path:


BASIC WAY

  • gforms_rcwdupload_gaf_url( $entry_id = 0, field_id = 0, $single = false )
    Retrieve uploaded file URL based on entry_id, and $field_id (all required)

  • gforms_rcwdupload_gaf_path( $entry_id = 0, field_id = 0, $single = false )
    Retrieve uploaded file PATH based on entry_id, and $field_id (all required)

--- about getting the entry_id value ---

$leads = GFFormsModel::get_leads(YOUR-FORM-ID); // PASS YOUR FORM ID TO GET ALL ENTRIES foreach($leads as $lead){ // CYCLE THE LEADS $entry_id = $lead['id']; // HERE YOU CAN CALL YOUR gforms_rcwdupload_gaf_url function }


WHEN USING FORM FOR CREATING POSTS

  • gforms_rcwdupload_gpaf_url( $post_id = 0, $field_id = 0, $single = false )
    Retrieve uploaded file URL based on post_id, and $field_id (all required)

  • gforms_rcwdupload_gpaf_path( $post_id = 0, $field_id = 0, $single = false )
    Retrieve uploaded file PATH based on post_id, and $field_id (all required)

WHEN USING USER REGISTRATION ADD-ON

  • gforms_rcwdupload_guaf_url( $user_id = 0, $field_id = 0, $single = false )
    Retrieve uploaded file URL based on user_id, and $field_id (all required)

  • gforms_rcwdupload_guaf_path( $user_id = 0, $field_id = 0, $single = false )
    Retrieve uploaded file PATH based on user_id, and $field_id (all required)

Actions & Filters

This add-on provides hooks to customize various aspect. New actions and filters will be available in next releases.

Following is a list of available hooks and filters.

ACTIONS

  • gforms_rcwdupload_up_in_external (requires the filter gforms_rcwdupload_up_is_external to be set to TRUE)
    This hook is used when the field value is being saved, exactly before the temporary file is moved to the website folder.
    function gforms_rcwdupload_up_in_external( $tempfile, $form_id, $field_id, $lead_id ){ //HERE YOU CAN USE, FOR EXAMPLE: rename( $tempfile, 'YOURDIR/filename.yourextension'); // OR SOME CODE TO UPLOAD THE FILE OUTSIDE, IN EXAMPLE AMAZON S3 OR DROPBOX } add_action( 'gforms_rcwdupload_up_in_external', 'gforms_rcwdupload_up_in_external', 10, 4 );

FILTERS

  • gforms_rcwdupload_thumb_force_http - defaults to false
    This filter force the preview thumb to be under http protocol also when https is active.
    Why this?
    Some servers that run websites in https have problems (don't know why, probably is something security related) to show the generated thumb with the same protocol .
    function gforms_rcwdupload_thumb_force_http( $force, $form_id, $field_id, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_thumb_force_http', 'gforms_rcwdupload_thumb_force_http', 10, 4);

  • gforms_rcwdupload_chunks (3 variants) - defaults to 0
    This filter set the limit of fields that user can create with the repeater button.
    The upload script has a built-in support for chunking, although it is disabled by default.
    What happens when it is activated, is that instead of sending a complete file, the script splits it into chunks of predefined size and uploads them one by one to be reassembled back to a complete file on a server-side.
    function gforms_rcwdupload_chunks( $chunk, $form_id, $field_id, $lead_id ){ //chunk_size accepts either a size in bytes or a formatted string, e.g: 204800 or"204800b"`` or "200kb". //REMEMBER: don't set the chunk value over the php or wordpress upload limit. $chunk = '500kb'; return $chunk; } add_filter( 'gforms_rcwdupload_chunks', 'gforms_rcwdupload_chunks', 10, 4 ); functiongforms_rcwdupload_chunks_FORMID( $chunk, $field_id, $lead_id ){ //chunk_size accepts either a size in bytes or a formatted string, e.g: 204800 or"204800b"`` or "200kb".
    //REMEMBER: don't set the chunk value over the php or wordpress upload limit. $chunk = '500kb'; return $chunk; } add_filter( 'gforms_rcwdupload_chunks_FORMID', 'gforms_rcwdupload_chunks_FORMID', 10, 3 ); function gforms_rcwdupload_chunks_FORMID_FIELDID( $chunk, $lead_id ){ //chunk_size accepts either a size in bytes or a formatted string, e.g: 204800 or"204800b"`` or "200kb".
    //REMEMBER: don't set the chunk value over the php or wordpress upload limit. $chunk = '500kb'; return $chunk; } add_filter( 'gforms_rcwdupload_chunks_FORMID_FIELDID', 'gforms_rcwdupload_chunks_FORMID_FIELDID', 10, 2 );

  • gforms_rcwdupload_repeater_limit (3 variants) - defaults to 0
    This filter set the limit of fields that user can create with the repeater button.
    function gforms_rcwdupload_repeater_limit( $value, $form_id, $field_id, $lead_id ){ return $value; } add_filter( 'gforms_rcwdupload_repeater_limit', 'gforms_rcwdupload_repeater_limit', 10, 4); function gforms_rcwdupload_repeater_limit_FORMID( $value, $field_id, $lead_id ){ return $value; } add_filter( 'gforms_rcwdupload_repeater_limit_FORMID', 'gforms_rcwdupload_repeater_limit_FORMID', 10, 3); function gforms_rcwdupload_repeater_limit_FORMID_FIELDID( $value, $lead_id ){ return $value; } add_filter( 'gforms_rcwdupload_repeater_limit_FORMID_FIELDID', 'gforms_rcwdupload_repeater_limit_FORMID_FIELDID', 10, 2);

  • gforms_rcwdupload_up_is_external (3 variants) - defaults to FALSE
    This filter returns a true/false value that is used as a check that will enable the above action (gforms_rcwdupload_up_in_external) .
    function gforms_rcwdupload_up_is_external( $external, $form_id, $field_id, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_up_is_external', 'gforms_rcwdupload_up_is_external', 10, 4 ); function gforms_rcwdupload_up_is_external_FORMID( $external, $field_id, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_up_is_external_FORMID', 'gforms_rcwdupload_up_is_external_FORMID', 10, 3 ); function gforms_rcwdupload_up_is_external_FORMID_FIELDID( $external, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_up_is_external_FORMID_FIELDID', 'gforms_rcwdupload_up_is_external_FORMID_FIELDID', 10, 2 );

  • gforms_rcwdupload_merge_tag_filter (2 variants) - defaults to LINK
    This filter is called before notifications are sent.
    You can choose how the field value is displayed in notification mail by returning one of the following strings:
    • name
      for example, this displays "lorem.jpg"
    • link
      for example, this displays "lorem.jpg" linked to the file
    • url
      for example, this displays "http://yourwebsite/gformsrcwdup/0/75080/17/1/541/lorem.jpg"

    function gforms_rcwdupload_merge_tag_filter( $mode, $lead, $form ){
    return 'name'; } add_filter( gforms_rcwdupload_merge_tag_filter', gforms_rcwdupload_merge_tag_filter, 10, 3 ); function gforms_rcwdupload_merge_tag_filtere_FORMID( $mode, $lead ){ return 'url'; } add_filter( 'gforms_rcwdupload_merge_tag_filter_FORMID', gforms_rcwdupload_merge_tag_filter_FORMID, 10, 2 );

  • ( DEPRECATED, use gforms_rcwdupload_merge_tag_filter instead ) gforms_rcwdupload_notification_only_name (2 variants) - defaults to FALSE
    This filter is called after an entry has been saved and before notifications are sent and before the confirmation is processed.
    It returns a true/false value. By default, the notification mail that admin or user receives, will contain the value of the rcwd upload field in a only text format. It means that the string is not linked to the file uploaded.
    Passing FALSE to this filter, will enable the file link.
    function gforms_rcwdupload_notification_only_name( $only_name, $lead, $form ){ return false; } add_filter( 'gforms_rcwdupload_notification_only_name', gforms_rcwdupload_notification_only_name, 10, 3 ); function gforms_rcwdupload_notification_only_name_FORMID( $only_name, $lead ){ return false; } add_filter( 'gforms_rcwdupload_notification_only_name_FORMID', gforms_rcwdupload_notification_only_name_FORMID, 10, 2 );

  • gforms_rcwdupload_filename_as_title (3 variants) - defaults to FALSE
    This filter is called when field's value is retrieved from the database.
    It returns a true/false value. By default, when the value is show, in example, inside the entry list, the title associated to the file will be used.
    function gforms_rcwdupload_filename_as_title( $only_name, $form_id, $field_id, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_filename_as_title', gforms_rcwdupload_filename_as_title, 10, 4 ); function gforms_rcwdupload_filename_as_title_FORMID( $only_name, $field_id, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_filename_as_title_FORMID', gforms_rcwdupload_filename_as_title_FORMID, 10, 3 ); function gforms_rcwdupload_filename_as_title_FORMID_FIELDID( $only_name, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_filename_as_title_FORMID_FIELDID', gforms_rcwdupload_filename_as_title_FORMID, 10, 2 );

  • gforms_rcwdupload_entry_mask_url (3 variants) - defaults to FALSE
    This filter is called when field's value is retrieved from the database.
    It returns a true/false value. if set to TRUE, when the value is show, in example, inside the entry list, the file link will use a permalink that hide the original path.

    A little explanation:

    This plugin output the file path in 2 ways:

    1. http://YOURWEBSITE/wp-content/uploads/gformsrcwduploads/11/5/5140/lorem.jpg

      This is the REAL URL/PATH of the file (this is active by default)

    2. http://YOURWEBSITE/gformsrcwdup/0/91700/11/5/5140/lorem.jpg

      This is a PERMALINKED URL, it means that the real path is hidden
      This url is structured in this way:

      gformsrcwdup: THE KEY detected by htaccess

      0: OPEN FILE INLINE, changing it with 1 will force the download

      91700: RANDOM NUMBER, just used to create a more deeper url

      11: the FORM ID

      5: the FIELD ID

      5140: the ENTRY ID


    function gforms_rcwdupload_entry_mask_url( $mask_url, $form_id, $field_id, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_entry_mask_url', 'gforms_rcwdupload_entry_mask_url', 10, 4 ); function gforms_rcwdupload_entry_mask_url_FORMID( $mask_url, $field_id, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_entry_mask_url_FORMID', 'gforms_rcwdupload_entry_mask_url_FORMID', 10, 3 ); function gforms_rcwdupload_entry_mask_url_FORMID_FIELDID( $mask_url, $lead_id ){ return true; } add_filter( 'gforms_rcwdupload_entry_mask_url_FORMID_FIELDID', 'gforms_rcwdupload_entry_mask_url_FORMID', 10, 2 );

  • gforms_rcwdupload_entry_filelist_separator (3 variants) - defaults to <BR />
    This filter is called when field's value is retrieved from the database.
    It returns a true/false value. By default, when the value is show, in example, inside the entry list, and there are more than 1 file uploaded (when the repeater is active) the files are separated by a breakline.
    function gforms_rcwdupload_entry_filelist_separator( $separator, $form_id, $field_id, $lead_id ){ return '-'; } add_filter( 'gforms_rcwdupload_entry_filelist_separator', gforms_rcwdupload_entry_filelist_separator, 10, 4 ); function gforms_rcwdupload_entry_filelist_separator_FORMID( $separator, $field_id, $lead_id ){ return '-'; } add_filter( 'gforms_rcwdupload_entry_filelist_separator_FORMID', gforms_rcwdupload_entry_filelist_separator_FORMID, 10, 3 ); function gforms_rcwdupload_entry_filelist_separator_FORMID_FIELDID( $separator, $lead_id ){ return '-'; } add_filter( 'gforms_rcwdupload_entry_filelist_separator_FORMID_FIELDID', gforms_rcwdupload_entry_filelist_separator_FORMID, 10, 2 );

  • gforms_rcwdupload_path (3 variants)
    This filter is called when the add-on need to retreive the path where upload or find the uploaded file.
    This filter should be useful when using an external service (AMAZON s3, DROPBOX etc.).
    function gforms_rcwdupload_path( $path, $form_id, $field_id, $lead_id ){ //... //SOME SCRIPTS TO GET THE NEW PATH (remember: no filename here!) return $YOURPATH; //... } add_filter( 'gforms_rcwdupload_path', gforms_rcwdupload_path, 10, 4 ); function gforms_rcwdupload_path_FORMID_FIELDID( $path, $field_id, $lead_id ){ //... //SOME SCRIPTS TO GET THE NEW PATH (remember: no filename here!) return $YOURPATH; //... } add_filter( 'gforms_rcwdupload_path_FORMID', gforms_rcwdupload_path_FORMID, 10, 3 ); function gforms_rcwdupload_path_FORMID_FIELDID( $path, $lead_id ){ //... //SOME SCRIPTS TO GET THE NEW PATH (remember: no filename here!) return $YOURPATH; //... } add_filter( 'gforms_rcwdupload_path_FORMID_FIELDID', gforms_rcwdupload_path_FORMID_FIELDID, 10, 2 );

  • gforms_rcwdupload_url (3 variants)
    This filter is called when the add-on need to retreive the url of the uploaded file.
    This filter should be useful when using an external service (AMAZON s3, DROPBOX etc.).
    function gforms_rcwdupload_url( $url, $form_id, $field_id, $lead_id ){ //... //SOME SCRIPTS TO GET THE NEW URL (remember: no filename here!) return $YOURURL; //... } add_filter( 'gforms_rcwdupload_url', 'gforms_rcwdupload_url', 10, 4 ); function gforms_rcwdupload_url_FORMID_FIELDID( $url, $field_id, $lead_id ){ //... //SOME SCRIPTS TO GET THE NEW URL (remember: no filename here!) return $YOURURL; //... } add_filter( 'gforms_rcwdupload_url_FORMID', 'gforms_rcwdupload_url_FORMID', 10, 3 ); function gforms_rcwdupload_url_FORMID_FIELDID( $url, $lead_id ){ //... //SOME SCRIPTS TO GET THE NEW URL (remember: no filename here!) return $YOURURL; //... } add_filter( 'gforms_rcwdupload_url_FORMID_FIELDID', 'gforms_rcwdupload_url_FORMID_FIELDID', 10, 2 );

  • gforms_rcwdupload_rewrite_rules
    This filter is called before the add-on rewrite rules (to hide the url path of the files) are set.
    IMPORTANT: Don't forget to update your permalink structure after add the new rules by going to BACKOFFICE -> SETTINGS -> PERMALINK
    function gforms_rcwdupload_rewrite_rules( $rewrite_rules ){ //$REWRITE_RULES IS ARRAY. WANT TO ADD YOUR CUSTOM RULES? DO IT HERE :) //PASS VALUES IN THIS WAY: $new_non_wp_rules = array( 'YOUR RULE' => 'YOUR RULE CONVERSION' ); //OR IF YOU WANT TO KEEP DEFAULT RULES AND ADD YOURS: $new_non_wp_rules[YOUR RULE] = 'YOUR RULE CONVERSION'; return $new_non_wp_rules; // DON'T FORGET TO ADD THIS } add_filter( 'gforms_rcwdupload_rewrite_rules', 'gforms_rcwdupload_rewrite_rules' );

  • gforms_rcwdupload_rename_tags and gforms_rcwdupload_rename_tags_replace
    These triggers are needed to add custom rename tags (used by the "rename" option).
    function rcwd_gforms_rcwdupload_rename_tags(){ $tags[] = '[rndm]'; // THIS SET THE SHORTCODE return $tags; } add_filter( 'gforms_rcwdupload_rename_tags', 'rcwd_gforms_rcwdupload_rename_tags' ); function rcwd_gforms_rcwdupload_rename_tags_replace( $replace, $form_id, $field_id, $lead_id ){ $replace[] = 'whateveryouwant'; // THIS SET THE CONTENT THAT REPLACE THE PREVIOUS SHORTCODE return $replace; } add_filter( 'gforms_rcwdupload_rename_tags_replace', 'rcwd_gforms_rcwdupload_rename_tags_replace', 10, 4 );

  • gforms_rcwdupload_gravityview_entry_mode and gforms_rcwdupload_gravityview_item
    These triggers are needed to customize items in gravity view.
    Click here for an example
    function gforms_rcwdupload_gravityview_entry_mode( $mode, $args, $form ){ /* POSSIBLE VALUES: link (default) : this will output the html for the anchor only_name : this will output the name of the file url : this will output the url */ return 'link'; } add_filter( 'gforms_rcwdupload_gravityview_entry_mode', 'gforms_rcwdupload_gravityview_entry_mode', 10, 3 ); function gforms_rcwdupload_gravityview_item( $item, $args, $form ){ $items = explode( '<br />', $item ); // THIS IS NECESSARY WHEN YOU ARE USING THE REPEATER OPTION $output = ''; foreach($items as $item) $output .= $item; return $output; } add_filter( 'gforms_rcwdupload_gravityview_item', 'gforms_rcwdupload_gravityview_item', 10, 3 );

  • gforms_rcwdupload_title_mode
    With this filter you can choose the file title position (currently, 2 ways).
    function gforms_rcwdupload_title_mode( $mode, $vfile, $title, $form_id, $field_id, $lead_id ){ /* POSSIBLE VALUES: 0 (default) : this will use the title instead of the filename 1 : this will prepend the title before the link followed by a minus sign */ return 0; } add_filter( 'gforms_rcwdupload_title_mode', 'gforms_rcwdupload_title_mode', 10, 6 );


Javascript triggers

These triggers can help you to achieve some results.

  • gformsrcwdupload_filters
    This trigger is called before the upload object is created and pass the file type filters generated by the field settings in backoffice.
    You can use this trigger to add a new filter definition call.
    jQuery(function($){ $(document).on( "gformsrcwdupload_filters", function( event, filters, form_id, field_id ) { filters['your-filter-name'] = 'your-value'; // CHECK THE F.A.Q. SECTION FOR AN EXAMPLE return filters; // ALWAYS NEEDED! }); });

  • gformsrcwdupload_object
    This trigger is called after the upload object is created.
    You can use this trigger, for example, to add a new filter (if you do this, don't forget to add the definition call by using the filter gformsrcwdupload_filters!).
    jQuery(function($){ $(document).on( "gformsrcwdupload_object", function( event, form_id, field_id ) { // CHECK THE F.A.Q. SECTION FOR AN EXAMPLE }); });

  • gformsrcwdupload_preview (3 variants)
    This trigger is called when a file(image) is selected and before the preview is displayed.
    You can use this trigger to customize the size of the preview.
    jQuery(function($){ //GENERAL _______________________ $(document).on( "gformsrcwdupload_preview", function( event, element, form_id, field_id, args ){ $(element).data({ width : 200, height : 30, crop : true }); }); // FILTERING WITH FORM ID_______________________ $(document).on( "gformsrcwdupload_FORMID_preview", function( event, element, field_id, args ){ //... }); // FILTERING WITH FORM ID AND FIELD ID_______________________ $(document).on( "gformsrcwdupload_FORMID_FIELDID_preview", function( event, element, args ){ //... }); });

  • gformsrcwdupload_fileuploaded (3 variants)
    This trigger is called when a file is uploaded.
    You can use this trigger, for example, to show a thumbnail.
    jQuery(function($){ // GENERAL _______________________ $(document).on( "gformsrcwdupload_fileuploaded", function( event, url, form_id, field_id ){ $('#thumbnail img').attr( 'src', href ); }); // FILTERING WITH FORM ID_______________________ $(document).on( "gformsrcwdupload_FORMID_fileuploaded", function( event, url, field_id, ){ //... }); // FILTERING WITH FORM ID AND FIELD ID_______________________ $(document).on( "gformsrcwdupload_FORMID_FIELDID_fileuploaded", function( event, url ){ //... }); });

  • gformsrcwdupload_remove_temp_file (3 variants)
    This trigger is called when a temporary uploaded file is removed.
    You can use this trigger, for example, to remove the thumbnail created using the previous trigger.
    jQuery(function($){ // GENERAL _______________________ $(document).on( "gformsrcwdupload_fileuploaded", function( event, form_id, field_id ){ $('#thumbnail img').attr( 'src', '' ); }); // FILTERING WITH FORM ID_______________________ $(document).on( "gformsrcwdupload_FORMID_fileuploaded", function( event, field_id, ){ //... }); // FILTERING WITH FORM ID AND FIELD ID_______________________ $(document).on( "gformsrcwdupload_FORMID_FIELDID_fileuploaded", function( event ){ //... }); });

Woocommerce compatibility

Finally, this plugin is almost compatible with Woocommerce (2.1.8+)!!!

Obviously, you need to purchase the "WooCommerce Gravity Forms Product Addons". This plugin connect any GF field to Woocommerce.

If you have a lower version, try this little modification of the woocommerce core file "includes/class-wc-order-item-meta.php":
https://github.com/woothemes/woocommerce/commit/2c0cf92

Any info or tutorial will be put in this space.


Support

You need support for it? no problem! Send me an email at rcwdsupport@cantarano.com.

No support in comments section. Please use it for presale questions only, thanks :)


FAQ

This is a permalink structure bug. To fix it, just go to BACKOFFICE -> SETTINGS -> PERMALINK.
No need to save there, WP will update the permalink structure automatically just opening that admin page.

If this will not fix it, please send an email to rcwdsupport@cantarano.com with your htaccess file attached and all info about your server type (windows or linux).
Anyway you can manually edit the htaccess file and add those 2 lines BEFORE the line "RewriteCond %{REQUEST_FILENAME} -f [OR]":

RewriteRule ^([_0-9a-zA-Z-]+/)?gformsrcwdup/([^/\.]*)/[^/\.]+/([^/\.]+)/([^/]+)/([^/]+)/((.+)(\.[^.]*$|$))?$ //?mode=$2&gformsrcwduplddwnlod=$3&fid=$4&leadid=$5&file=$6 [QSA,L]
RewriteRule ^([_0-9a-zA-Z-]+/)?gformsrcwdup/([^/\.]*)/([^/\.]*)/user/([^/]+)/((.+)(\.[^.]*$|$))?$ //?mode=$2&gformsrcwduplddwnlod=$3&userid=$4&file=$5 [QSA,L]
Easy! Follow this simple guide:
You need 2 JS triggers: gformsrcwdupload_filters and gformsrcwdupload_object
$(document).on( "gformsrcwdupload_filters", function( event, filters, form_id, field_id ) { filters['max_width'] = 50; // SET YOUR WIDTH LIMIT, WITHOUT THE WORD PX return filters; // DON'T FORGET TO RETURN THE FILTERS! }); $(document).on( "gformsrcwdupload_object", function( event, form_id, field_id ) { plupload.addFileFilter('max_width', function( max_width, file, cb ){ var self = this var img = new o.Image(); function finalize(result){ img.destroy(); img = null; if (!result){ self.trigger('Error', { code : plupload.IMAGE_DIMENSIONS_ERROR, message : "The width exceeds the allowed limit of " + max_width + " pixels.", file : file }); } cb(result); } img.onload = function() { finalize(img.width < max_width); }; img.onerror = function(){ finalize(false); }; img.load(file.getSource()); }); });

 
Check the FUNCTIONS section, you will find all info by clicking here
Easy task, you can use one method of the class GFRcwdCommon: inside my plugin:

GFRcwdCommon::upload_info( $form_id, $field_id, $entry_id, $user_id )

NOTE: $user_id IS OPTIONAL, you have to pass this value ONLY if you are using the plugin with "gravity forms user registration add-on".

NOTE ABOUT " HOW TO GET MY FIELD SERIALIZED DATA": if have two methods to get the data, the 1st is to cycle all leads using GFFormsModel::get_leads($form_id), or, if you are using the form to create a POST, you need to get the ENTRY ID by using the wp function get_post_meta( $post_id, '_gform-entry-id', true ).

With this class method, you can get the path (real or permalink) of the file and use it with filename in this way:
$lead = RGFormsModel::get_lead(ENTRY_ID); $form = RGFormsModel::get_form_meta(FORM_ID); foreach( $form['fields'] as $field ){ $field = (array)$field; // IT SEEMS THAT IN LATEST GFORMS VERSION, THIS WILL BE AN OBJECT. I PREFER TO CAST IT AS ARRAY if($field['type'] == 'rcwdupload'){ $value = unserialize( $lead[$field['id']] ); //$value = unserialize(get_user_meta( $user_id, 'YOUR-META-NAME', true )); // NEED THIS IF USING WITH GFORMS USER REGISTRATION ADD-ON $form_id = $value[0]['form_id']; $field_id = $value[0]['field_id']; $entry_id = $value[0]['entry_id']; $filename = $value[0]['file']; $path = GFRcwdCommon::upload_info( $form_id, $field_id, $entry_id ); //$path = GFRcwdCommon::upload_info( $form_id, $field_id, $entry_id, $user_id ); // NEED THIS IF USING WITH GFORMS USER REGISTRATION ADD-ON $file = $path['url'].$filename; } }
if you do a var_dump on $path, you will see other useful info that you should need.
function change_user_notification_attachments( $notification, $form, $entry ){ if($notification["name"] == "Notifica amministratore"){ // THIS IS THE IMPORTANT PART,IF YOU HAVE MORE THAN ONE NOTIFICATION, THE ONLY WAY TO ADD ATTACHMENTS ONLY TO ONE IS USING THE NAME, IT MUST BE THE SAME YOU ADD IN YOUR NOTIFICATION SETTINGS. SEE THE ATTACHED IMAGE $rcwdupload_fields = GFCommon::get_fields_by_type($form, array("rcwdupload")); if(!is_array($rcwdupload_fields)) return $notification; $attachments = array(); foreach($rcwdupload_fields as $rcwdupload){ if(!empty($entry[$rcwdupload["id"]])){ $value = unserialize($entry[$rcwdupload["id"]]); foreach($value as $singlevalue){ if( isset($singlevalue) and isset($singlevalue['form_id']) and isset($singlevalue['field_id']) and isset($singlevalue['entry_id']) and isset($singlevalue['file']) and !empty($singlevalue['file']) ){ $form_id = $singlevalue['form_id']; $field_id = $singlevalue['field_id']; $entry_id = $singlevalue['entry_id']; $filename = $singlevalue['file']; $path = GFRcwdCommon::upload_info( $form_id, $field_id, $entry_id ); $attachments[] = $path['path'].$filename; } } } } $notification["attachments"] = $attachments; } return $notification; } add_filter( 'gform_notification', 'change_user_notification_attachments', 10, 3 );
function gform_notification( $notification, $form, $entry ){ if($notification["name"] == "Notifica amministratore"){ // THIS IS THE IMPORTANT PART,IF YOU HAVE MORE THAN ONE NOTIFICATION, THE ONLY WAY TO ADD ATTACHMENTS ONLY TO ONE IS USING THE NAME, IT MUST BE THE SAME YOU ADD IN YOUR NOTIFICATION SETTINGS. SEE THE ATTACHED IMAGE $text = $notification['message']; $form_id = $form['id']; $fields = $form['fields']; preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER ); if(is_array($matches)){ $rcwdfields = GFCommon::get_fields_by_type($form, array("rcwdupload")); if(!is_array($rcwdfields)) return $notification; $matchesids = array(); $matchesidsc = array(); foreach($matches as $match){ $matchesidsc[] = $match[0]; $matchesids[] = $match[1]; } foreach($rcwdfields as $rcwdfield){ if(false !== $rfkey = array_search( $rcwdfield->id, $matchesids )){ $pics = gforms_rcwdupload_gaf_url( $entry['id'], $rcwdfield->id, $single = false ); if(!empty($pics)){ foreach($pics as $pk => $pic) $pics[$pk] = '<img src="'.$pic.'" alt="">'; } $text = str_replace( $matchesidsc[$rfkey], implode( ' ', $pics ), $text ); } } $notification['message'] = $text; } } return $notification; } add_filter( 'gform_notification', 'gform_notification', 10, 3 );
Easy task, you can use the following filters:

function gforms_rcwdupload_gravityview_entry_mode( $mode, $args, $form ){ return 'url'; // THIS IS NECESSARY TO GET ONLY THE URL FOR EVERY SINGLE FILE } add_filter( 'gforms_rcwdupload_gravityview_entry_mode', 'gforms_rcwdupload_gravityview_entry_mode', 10, 3 ); function gforms_rcwdupload_gravityview_item( $item, $args, $form ){ $items = explode( '<br />', $item ); // THIS IS NECESSARY WHEN YOU ARE USING THE REPEATER OPTION $output = ''; foreach($items as $item) $output .= '<div class="your-item"><a href="'.$item.'" target="_blank"><img src="'.$item.'" alt="" width="150"></a></div>'; return $output; } add_filter( 'gforms_rcwdupload_gravityview_item', 'gforms_rcwdupload_gravityview_item', 10, 3 );

This section will grow with your support! Send me an email at rcwdsupport@cantarano.com with your question and i will help you as soon as possible.


Updates

Don't forget to check the checkbox "Get notified by email if this item is updated" in your Downloads page :)

To update the plugin you have 2 ways

  1. login to CodeCanyon -> Downloads section -> re-download the plugin
  2. Use the (experimental, be careful and do a backup!) auto-updater feature

V1.1.7.0

  • New WP filter to manage file title position: gforms_rcwdupload_title_mode
  • minor bug fixes

V1.1.6.9

  • improved GF API compatibility
  • minor bug fixes

V1.1.6.6

  • minor bug fixes

V1.1.6.0

  • fixed a bug that prevent to edit the field value in admin

V1.1.5.9

  • New option added to the "hide browse button" dropdown: you can choose to keep it hidden until remove button is clicked
  • fixed a bug with upload script file not properly working on some server

V1.1.5.8

  • fixed a bug that prevents uploaded images to be resized

V1.1.5.6

  • improved gravity view datatables add-on

V1.1.5.4

  • improved multisite network compatibility.
  • fixed upload url querystring security

V1.1.5.3

  • IMPROVED upload processing and stability
  • Added ready-to-use PHP functions for getting url or path of the files
  • improved compatibility with Gravity View
  • new filters forGravity View add-on: gforms_rcwdupload_gravityview_entry_mode and gforms_rcwdupload_gravityview_item
  • Changed default value for gforms_rcwdupload_entry_mask_url filter: FALSE
  • minor bug fixes

V1.1.5.0

  • bug fixes

V1.1.4.9

  • auto-upgrade process is fixed

V1.1.4.8

  • bug fixes

V1.1.4.7

  • New WP filters to manage custom rename tags: gforms_rcwdupload_rename_tags and gforms_rcwdupload_rename_tags_replace

V1.1.4.6

  • bug fixes for iOS7

V1.1.4.5

  • fixed a bug that wrongly renamed the filename if repeater is on

V1.1.4.4

  • New feature added: Filename edit in admin (as requested from some of you): Now you can change the filename when editing an entry
  • New option added: Filename edit in admin (as requested from some of you): Hide the browse button after file selection
  • New option added: Filename edit in admin (as requested from some of you): Start the repeater with n fields
  • bug fixes

V1.1.4.1

  • bug fixes

V1.1.3.9

  • bug fixes

V1.1.3.5

  • bug fixes about temp file deletion

V1.1.3.4

  • Fixed a critical bug that prevents a second upload on iphone and IE8 (please clear your browser cache)

V1.1.3.1

  • More compatibility with latest GF Api
  • Bug fixes

V1.1.2.9

  • Bug fixes

V1.1.2.5

  • Some fixes for User Registration Add-On compatibility

V1.1.2.4

  • Compatibility with User Registration Add-On V3

V1.1.2.3

  • Fixed a bug that prevents image upload when server does not support exif_read_data function

V1.1.2.2

  • Fixed a bug that prevents no-image files to be uploaded correctly

V1.1.2.0

  • Fixed the rotation problem that happens on some smartphone after upload(for ex. Iphone)

V1.1.1.9

  • Fixed a bug that prevents the loaded image to show when using the "save and continue later" feature

V1.1.1.7

  • New JS triggers to customize upload filters (gformsrcwdupload_filters and gformsrcwdupload_object). See F.A.Q. section

V1.1.1.6

  • Various bug fixes

V1.1.1.5

  • Update compatibility with Woocommerce!
  • Update compatibility with Gravity Forms User Registration add-on!
  • Improved code that show the thumb of the uploaded file. Now it happens only if file is image type. Also, the real file path is hidden.
  • Improved code that show the thumb of the preview file. Now it happens only if file is image type.

V1.1.1.2

  • Fixed a bug that prevents to get the original filename

V1.1.1.1

  • Added available tags for the rename field

V1.1.1.0

  • Fixed a bug that shown errors on screen with not used upload fields with User Registration Addon

V1.1.0.9

  • Fixed a critical bug that prevented the cropping feature to works as it should be

V1.1.0.8

  • Various bug fixes

V1.1.0.7

  • Added crop feature to resized image
  • Updated compatibility with mobile devices
  • Bug fixes and optimization with WP 4.3.1

V1.1.0.6

  • Fixed a bug that slow down website if plugin account is not validated
  • Fixed a bug that happens when post fields are used and GFORMS UPDATE POST is not installed

V1.1.0.5

  • Bug fixes

V1.1.0.4

  • New filter: gforms_rcwdupload_thumb_force_http (see Actions & Filters section)

V1.1.0.3

  • New filter: gforms_rcwdupload_chunks (see Actions & Filters section)

V1.1.0.1

  • Fixed: some websites on http had problems validating the plugin.
  • Fixed: image preview after upload was not working properly.

V1.1.0.0

  • New filter: gforms_rcwdupload_merge_tag_filter
  • Various bug fixes

V1.0.9.9

  • Added setting to show image thumb after upload.
  • Added auto-updater (experimental) feature.
  • WOOCOMMERCE QUICK CHECKOUT COMPATIBILITY
  • Fixed: a bug caused problems to drag&drop in Chrome browsers
  • Fixed: "resend notifications" no more show errors on some environments
  • Fixed: in repeater mode, when you choose an image when a previous has been selected, it will correctly change the current chosen file.
  • Fixed: now the username check is case insensitive

V1.0.9.2

  • Bug fixes on file preview

V1.0.9.1

  • Fix for Woocommerce Catalog Visibility Options
  • Various small fixes

V1.0.9.0

  • Added support for SAVE AND CONTINUE (GF 1.9 feature)

V1.0.8.9

  • Gravity Forms 1.9 ready.

V1.0.8.8

  • Various bug fixes.

V1.0.8.7

  • Multi-page for fixed. No more 404 error on file link when you go back to the page when the file is uploaded.

V1.0.8.6

  • New javascript triggers.

V1.0.8.5

  • New feature: sortable elements (if repeater option is On).
  • Permalink structure fixed.

V1.0.8.2

  • Various fixes, some about PHP strict standards.

V1.0.8.1

  • Fixed problem with settings not saved when going to previous page in multipage form.
  • Changed the error alert box.
  • Various fixes.

V1.0.8.0

  • Various fixes, some about PHP strict standards.

V1.0.7.9

  • Important fix: url rewrite now better detects filename.

V1.0.7.3

  • Important fix: no more error on editing lead on WP panel.

V1.0.7.2

  • Important fix: some bugs prevented the field to work correctly.

V1.0.7.1

  • WOOCOMMERCE COMPATIBILITY
  • Size settings for image preview
  • Added option to set autoupload after file selection
  • Option for rename the file
  • Option for weight limit
  • Wordpress 3.9 compatibility

V1.0.6.2

  • Added option to automatically upload files on selection
  • Added option to set an upload size limit
  • Fix: jQuery Dialog box will not be covered by the overlay anymore

V1.0.5.9

  • Critical fix for IE9

V1.0.5.6

  • Added support for GForms User Registration Add-On
  • Fixed an annoying bug that prevents the functionality of field in IE8 and IE10 if the field is initially hidden (this is what happens if conditional fields are used)

V1.0.5.4

  • Fixed a bug for using the field in gform ajax mode
  • Small bug fixes

V1.0.5.3

  • Bug fixes for uploaded image preview

V1.0.5.2

  • Bug fixes for resizing options

V1.0.5.1

  • Added repeater limit (by option or by the new filter "gforms_rcwdupload_repeater_limit")
  • Small bug fixes for new WP version

V1.0.4

  • Fixed the correct display (css and js) of the form field in the backoffice preview

v1.0.3

  • Added select field for "image preview before upload" option
  • Fixed a bug that did't hide the image preview after remove or upload
  • Small bug fixes

v1.0.2

  • Added image preview before upload(it works on Firefox 3.6+, Chrome 7+, IE 10+, Opera 12.02+, Safari 6.0.2+)

v1.0.1

  • fixed a bug that prevent the field to be added to the form in Chrome and IE

v1.0.0

  • first version

Roberto Cantarano - web design and developement