Skip Navigation

[Resolved] Image upload in front end Form not working for Guest Users

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a Form that allows Guest Users to create posts, and the form includes an image custom field. When Guests try to upload an image, they are shown an error message "There was an error uploading your file".

Solution:
Add this custom code to override the guest restriction imposed by Wordpress:

add_action( 'admin_init','reset_guest_caps' ,9 );
function reset_guest_caps(){
    global $current_user, $wpcf_access;
    if(isset($_GET['formid']) && $_GET['formid']==12345&&$current_user->ID==0)
    {
        $wpcf_access->settings=array();
    }
}

Replace 12345 with the numeric ID of this Form.

100% of people find this useful.

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Paul Marconi 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#903098
error.PNG

I am trying to have users be able to upload their images to the site using a cred frontend form, but I'm getting a popup, "There was an error uploading your

file" every time.

When I am logged into the wordpress site, I am able to upload images with no problem, but visitors who are not logged in are getting this error.

My plugins are updated, I have tried going to this article from toolset.com (https://toolset.com/errata/upload-fails-wordpress-installed-directory/), but it

still did not solve my issue. The images are uploading to the default folder.

Wordpress version 4.9.6
Toolset Access 2.4.3.5
Toolset CRED 1.9.6.1
Toolset Types 2.2.23
Toolset Views 2.5.2

hidden link

Please help. Really appreciate.

#903108

Hi, please go to Toolset > Access Control > Post Types and check the settings for the Posts post type (it should be managed by Access) and the Media post type (it should be managed by Access and Guests should have Publish permissions).

If this configuration does not solve the problem, please try the following troubleshooting steps:
- Temporarily deactivate all plugins except Types, Views, Access, and CRED, and activate a default theme like Twenty Seventeen. Then test again.
- If the problem was resolved, reactivate your theme and other plugins one by one until the conflict is revealed
- If the problem was not resolved, I'll need to take a closer look.

#903873
Access-Control-WordPress-screenshot.png

Hi Christian,

Thank you for your quick response.
When I went to Toolset > Access Control > Post Types and check the settings for the "Shared Stories" custom post type, it's managed by Access. The 'Media' post type is managed by Access, but the Publish option for Guest is grey out & the tooltip has this message 'This option doesn't work for Guest'. Same for all the Custom Post type & the default Post type.
The only option for Guest is 'Read'.

I have a screenshot attached.

Are there any settings that I need to change before doing the steps above?

Thanks, Rose

#904526

I see, can you tell me more about the image upload? Is the issue appearing when Guests try to upload a custom field image, or when Guests try to insert an image into a post's content?

#905040
upload-error-cred-form.png

Hi Christian,

The form is created using the CRED form, and there is a custom upload field for visitors/guests to upload their image.

The issue is that every time when guest tries to upload their image on the front-end CRED form (hidden link), they're getting a popup, "There was an error uploading your file".

I have a CPT called "Shared Stories", and I have added custom fields to this Post type using the Toolset Post Fields. It includes a custom Image field (for the image upload in the front-end).

In the CRED Post form, I have inserted the CRED shortcode [cred_field field='share-a_photo' post='shared_story' value='' urlparam=''] which is the upload field for visitors / guests to upload thier image. Once submitted, the post should be marked as pending (which it is), and from the upload image field, it should be inserted into the custom Image field.

It's working when I am logged in, but for guest / visitors (not logged in), they are getting the popup error "There was an error uploading your file".

I am not sure what the issue is. Please help. Really appreciate.

Thanks

#905681

Okay thanks. Please add this code to your child theme's functions.php file to attempt to override guest permissions on this form:

add_action( 'admin_init','reset_guest_caps' ,9 );
function reset_guest_caps(){
    global $current_user, $wpcf_access;
    if(isset($_GET['formid']) && $_GET['formid']==12345&&$current_user->ID==0)
    {
        $wpcf_access->settings=array();
    }
}

Replace 12345 with the numeric ID of this CRED form, and test again. Let me know the results and we can go from there.

#906290

Thank you so much Christian! It's working now for guests who are not logged in.
I really appreciate your help.

Thanks again!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.