PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Custom Upload Directory plugin and GF

  1. sascha
    Member

    Hi there,
    I am using the CUD (Custom Upload Directory) plugin and would like that also the files that GF creates in uploads for the media library are added to the folder specified through the CUD plugin. It works fine from the backend, but submitting a post through a GF form just writes all the files to the uploads directory and of course the original files to the GF folder by year and month.

    Is there anyway that those two plugins (CUD and GF) can play together? That would just be so awsome!
    Sascha

    Posted 13 years ago on Wednesday September 28, 2011 | Permalink
  2. Gravity Forms uses WordPress functions for adding images to the media library. So if the CUD plugin isn't handling them it is going to be due to how it hooks into WordPress and where it implements it's functionality. It may not be doing it at the function level.

    Posted 13 years ago on Wednesday September 28, 2011 | Permalink
  3. sascha
    Member

    Hi Carl,
    he adds the upload path with a filter:
    add_filter('upload_dir', 'cud_custom_upload_dir');

    Obviously that does not seem to fire when I use GF. Is it just a matter of changing the priority maybe? Or have you got an idea of how I can pass the cud_custom_upload_dir string to GF, so that it uses that path to create the media library files?
    If you point me to the right files of GF I can try and have a look myself, but I'm not a fluent coder...

    Posted 13 years ago on Wednesday September 28, 2011 | Permalink
  4. Gravity Forms uses built in WordPress functions to add the image to the Media Library and then WordPress processes the image and moves it where it needs to go. Gravity Forms itself doesn't handle this, it calls a WordPress function to do this. Most likely the CUD plugin is applying hooks to to do what it does in such a way that it isn't applied to this function. You may need to discuss this with the CUD plugin developer.

    Posted 13 years ago on Wednesday September 28, 2011 | Permalink
  5. sascha
    Member

    Thanks. I have contacted him. We will see what he says....
    Can you let me know which WP function and when GF is calling when you submit a form that sends a post submission? Maybe I can have a look myself why the CUD settings are being bypassed. Might just need another add_filter/apply_filter somewhere else to make this work.
    It would be great if you could point me to the right files & functions for both GF and WP.
    Maybe it also has to do with the order that GF calls the WP functions?
    Anyway, any pointers to the right files would be appriciated in case I do not hear from the CUD developer.

    Posted 13 years ago on Wednesday September 28, 2011 | Permalink
  6. The functions we use are:

    wp_insert_attachment()
    wp_update_attachment_metadata()
    wp_generate_attachment_metadata()

    The first one inserts the attachment into the Media Library. The 2nd and 3rd function calls above are used together to then create the image sizes, etc.

    Posted 13 years ago on Wednesday September 28, 2011 | Permalink
  7. sascha
    Member

    Hi Carl or anyone,
    my head is buzzing. No idea why the filter is being bypassed. The filter is in the wp_upload_dir() function (functions.php in wp-includes) which GF uses as well. Any idea why it's not being recognized? I'm not sure how WP processes filters.....

    Posted 13 years ago on Friday September 30, 2011 | Permalink
  8. Gravity Forms uses the functions I referenced above to add the image to the media library. So those are the functions that are used to handle media library attachment and processing.

    Posted 13 years ago on Friday September 30, 2011 | Permalink
  9. sascha
    Member

    Hi at GF,
    I'm back on this issue again and banging my head. Could you let me know where in the GF code exactly the attachment is uploaded to the directory, basically where the above functions are called? And also if the post is created before the attachment is uploaded or after? Maybe that will give me a hint on why the following filter gets bypassed:
    add_filter('upload_dir', 'cud_custom_upload_dir');

    A whole walkthrough of the process of creating a post and uploading an attachment in GF would be great and hopefully together with the CUD developer we can get this issue sorted!

    Posted 12 years ago on Monday December 5, 2011 | Permalink
  10. sascha
    Member

    Hi again,
    looked at the official function reference for "wp_insert_attachment" referenced above. It basically inserts a file from the "uploads directory". The problem is that GF bypasses the uploads directory modified by CUD, but uses only the one given in the WP media settings instead.

    So the questin really is:
    How does GF get that file to the uploads directory and where does it get the uploads directory path from? Which functions/code does it use to do that? Where is it in the code of GF?
    That might help me figure out why it bypasses CUD....
    Grateful for any help with this!

    Posted 12 years ago on Monday December 5, 2011 | Permalink
  11. sascha
    Member

    Hi there,
    made good progress! Tracked it down to the following GF function:

    private static function copy_post_image($url) in forms_model.php

    1. How can I make the (just created) post information available during that function? I need the author, category, post type, post id. When I var_dump ($post) I get NULL.... I guess if I have the post ID I can get all the information by adding a get_post to the copy_post_image($url) function.

    2. If that is not possible: can I get any $entry information at this stage?

    Thanks!

    Posted 12 years ago on Monday December 5, 2011 | Permalink
  12. sascha
    Member

    Hi again,
    the post_id (as a global?!?) is actually enough. I need to pass that on to CUD and tell CUD that the request came from GF.

    Posted 12 years ago on Monday December 5, 2011 | Permalink
  13. sascha
    Member

    Ok, I got a reply from the author of CUD. Not sure if those requirements can be met with a hook/filter in GF? I would value your opinion on that....

    "Yeah, I just realized we don't need any special flag at all. They just need to provide

    $_REQUEST['Upload'] or $_REQUEST['html-upload']

    and either:
    global $post
    global $post_id
    or $_REQUEST['post_id']"

    Would that make sense to integrate into GF?

    Posted 12 years ago on Monday December 5, 2011 | Permalink