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.

Relative Root URL's

  1. I am using a relative root url plugin which works great, but causes issues with the admin and user emails sent out by GF because the links to images and files in the email are not absolute. I want to continue using the relative root URL's and I am wondering if there is a way I can somehow filter the email message running a function in functions.php, or the best way to modify the HTML to make the URL's absolute again. I am comfortable putting together the URL replacement, I just need to know where to hook in or filter to do so.

    I have tried output buffering which does not work...

    Thanks,
    Cameron

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  2. What plugin are you using for relative root URLs? Sounds like you need to have it avoid modifying the Gravity Forms message, maybe by removing a filter they have added?

    We would need to know when your plugin modifies the URLs in the notification emails so that you can change it back after.

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  3. Hi Chris,

    http://wordpress.org/extend/plugins/root-relative-urls/

    This plugin modifies the URL before it goes into the DB on any uploads, so it doesn't modify the message on output, it has already rewritten the url to /wp-content/uploads/etc/

    I can remove the relative URL's plugin, but it is nice to have for moving from staging to live. Also, it would be nice in general to be able to filter / modify the message sent programmatically.

    Thanks,
    Cameron

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  4. If it modifies the URL before it's stored in the database, you can going to have to modify it back to a full URL before the notification is sent. It sounds like the URLs are changed to relative URLs before the entry is stored? Can you check an entry in the database to see if it's a relative or absolute URL?

    And what URLs are we concerned with in your notification emails? Are these links to images or file uploads?

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  5. Yes, the entries are modified to relative URLs before they are inserted into the DB.

    Image and file urls are both of concern in the notification emails (images are broken, file paths are not able to be followed).

    I am comfortable rebuilding those URLS with some regex / preg_replace magic in functions.php or in a plugin, but I am not sure if there is a hook or filter to use to edit the admin notification message string.

    Any ideas on how to change that message programmatically with a hook? I don't want to hack at core files.

    Thanks much,
    Cameron

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  6. Yeah, no hacking core files :-)

    Since the value is modified by your plugin before it's stored in the entry, you will likely need to modify it on the way out. Since you are likely using a merge tag of some sort in your notification ( {all_fields} or some combination of individual merge tags ) you might have to use the gform_get_input_value filter:
    http://www.gravityhelp.com/documentation/page/Gform_get_input_value

    You can modify individual field values in that way. You can just concatenate the URL with the relative portion and return that. I'm not certain when this filter runs: you'll have to give it a try.

    I don't think there is any way to modify the notification, since it's stored as part of the form, and uses merge tags which are dynamically replaced with the values from the entry.

    An alternate approach would be to craft your notification using individual merge tags, and then use a shortcode to retrieve the root relative URLs to add back in the protocol and domain. If you have already created a custom notification, rather than using {all_fields}, this method would not require too much additional work. Just the creation of a shortcode to modify individual fields to add back the protocol and domain on the fields where it's required.

    Or, I did not look, but is it possible to configure the root relative plugin to ignore certain database inserts? Maybe there is a filter you can remove?

    Posted 11 years ago on Thursday January 3, 2013 | Permalink
  7. Hi Chris,

    On further inspection I found that it was not actually the core root relative urls plugin that was causing the issue (I disabled and even deleted it).

    I am dynamically setting the content URL in wp-config.php with the following:
    define('WP_CONTENT_URL', '/wp-content');

    This works great with all images and files (and requires and such) but causes issues with the GF forms notifications because it is saving as:
    /wp-content/uploads/gravity_forms/1-acc4bf57bc9efeed64d056171a8e757b/2013/01/filename.pdf

    Do you have an example of a hook that I can reference that manipulates the form data prior to saving to the database so that I can change the URL of the file that gets saved to wp_rg_lead_detail?

    Thanks for your help, I assume this is something others have encountered as using relative urls is pretty important in having a development environment.

    Cameron

    Posted 11 years ago on Friday January 4, 2013 | Permalink
  8. I've never heard of another Gravity Forms user using the root relative plugin for development. You can use the gform_pre_submission_filter to manipulate the data before the entry is stored:

    http://www.gravityhelp.com/documentation/page/Gform_pre_submission_filter

    Posted 11 years ago on Sunday January 6, 2013 | Permalink
  9. Thanks Chris, I will give that a shot, it's not ideal because it would still bake the URL into the file upload reference so testing uploads on a dev environment would cause the wrong URL to be linked on the live environment.

    Just to be clear also, it's actually not the root relative urls plugin at all, but the
    define('WP_CONTENT_URL', '/wp-content');
    in the functions.php that is causing GF to not absolutely link the URL's correctly (in email only, relative reference is fine in the backend for file downloads). Most users don't touch it, but some may want to redefine the location of that folder to name it simply "content" or "_web_contents" (to put it at the top of directory in sort by name) using that WP_CONTENT_URL constant. It seems that GF should account for this in how it creates the links for the email notifications to handle these standard WP config settings.

    I even tried a plugin that pushes all files uploaded through WP media uploads to Amazon S3 and those all work correctly, but not GF uploads; so I presume GF uploads are handled differently than the default WP upload methodology.

    Is there no other way to manipulate the email messages sent by GF than hack at core files? (it would be much easier to edit the message output than modify and deal with absolute URL's and adding pre-submission filters to each file upload field.) Plus this would keep things more server agnostic.

    Thanks for all your help!
    Cameron

    P.S. if I were to take the time to figure out how to setup the url replacements in a WP and GF friendly fashion would you consider reviewing the code for potential future use? I'm sure others would see benefit from this as well.

    Posted 11 years ago on Monday January 7, 2013 | Permalink
  10. My understanding of WP_CONTENT_URL is that it is a full URL, not a relative path:
    http://codex.wordpress.org/Determining_Plugin_and_Content_Directories#Constants

    I can understand why you're using it like you do, but your use of it is not common (to me, here, anyway) and is the first time a Gravity Forms user has mentioned it in these forums that I can recall. I'll bring this to the attention of the development team for their thoughts.

    Posted 11 years ago on Monday January 7, 2013 | Permalink
  11. Sound great, thanks Chris!

    Posted 11 years ago on Monday January 7, 2013 | Permalink
  12. Hi Chris, any thoughts / ideas on this from GF team?

    Thanks for all your help!
    Cameron

    Posted 11 years ago on Wednesday January 9, 2013 | Permalink
  13. I have not heard anything back from the developers. Let me ask them again.

    Posted 11 years ago on Wednesday January 9, 2013 | Permalink
  14. The suggestion from the development team was to use the gform_upload_path to change the URL and path of the Gravity Forms uploads http://www.gravityhelp.com/documentation/page/Gform_upload_path

    Posted 11 years ago on Thursday January 10, 2013 | Permalink
  15. Thanks Chris, that does the trick!

    Here's what I ended up with in case it helps someone else (in functions.php):

    add_filter("gform_upload_path", "change_upload_path", 10, 2);
    function change_upload_path($path_info, $form_id){
       $path_info["path"] = "wp-content/uploads/gravity_forms/";
       $path_info["url"] = 'http://'.$_SERVER['HTTP_HOST']."/wp-content/uploads/gravity_forms/";
       return $path_info;
    }

    Now the paths are pushed into the DB with the absolute URL path and they work correctly in the admin emails (URLs are specific to the server they are uploaded on now which is less ideal, but they work).

    I appreciate your time and help finding this solution.

    Cheers!
    Cameron

    Posted 11 years ago on Thursday January 10, 2013 | Permalink
  16. Awesome. I will let the development team know this worked for you.

    Posted 11 years ago on Friday January 11, 2013 | Permalink