I am trying to: Let a custom role (vendor) upload images to a post form.
Link to a page where the issue can be seen: hidden link
I expected to see: Successful image uploads.
Instead, I got: "An error occurred in the upload. Please try again later."
MORE INFO: I have a post form "Mitzvah Vendor Directory Registration" which can only be accessed if the user is logged in. So on the link above, you have both the "New user?" user form and the "Already have a login?" user form (both made in Toolset). If they already have an account and use the "Already have a login?" user form, image uploads on the form works fine.
But if they are a new user and use the "New user?" user form, they are unable to upload media. I have tried:
- putting in the custom code for auto-logging new users upon sign up (you can see it on my functions.php file)
- putting in the custom code for allowing guest users to upload media (you can also see it on my functions.php file)
I am clueless as to what in my site is causing this error. Can you help me out?
Thank you for contacting us and I'd be happy to assist.
To troubleshoot, why only specific post form is not uploading images, I'll need access to the website's admin area.
Can you please share temporary admin login details?
Note: Your next reply will be private and though no changes will be made on your website, please make a complete backup copy, before sharing the access details.
During testing, I noticed that the issue with the image uploading is only faced if a new user is logged in automatically after registering, through custom login code.
If a new user registers and then logs out and then logs in using the login form, the image uploading works as expected.
This suggests that the custom function that is being used on the website to automatically login user, is not working completely or some security measures/plugins on the website are not treating that authentication as adequate.
I couldn't access your theme's "functions.php" file to see that custom code, but I'll recommend to temporarily disable all extra plugins, other than Toolset and then test the registration and post creation form again.
If the issue is fixed, you can start activating the deactivated plugins one-by-one, to narrow this down to a possible conflicting one.
You're also welcome to share the code that you're using for the automatic login, on the website, so I can test it on my website too.
This is the code that I use to automatically log the user in after registering:
add_action( 'cred_save_data', 'tssupp_cred_autologin', 10, 2 );
function tssupp_cred_autologin( $post_id, $form_data ){
if ( 22161 == $form_data['id'] ) { // Edit as required
if ( !empty( $_POST['user_login'] ) && !empty( $_POST['user_pass'] ) ) {
// get the user credentials from the $_POST object
$user = array(
'user_login' => $_POST['user_login'],
'user_password' => $_POST['user_pass'],
'remember' => true
);
$login = wp_signon( $user, false );
if ( is_wp_error($login) ) {
error_log( $login->get_error_message() );
}
}
}
}
Ideally, I would prefer not to have the vendors go through the login process again (thus the auto-login code). For good measure, I also have this code on my functions.php which allows guest uploads:
add_action( 'admin_init','reset_guest_caps' , 9 );
function reset_guest_caps(){
global $current_user, $wpcf_access;
if(isset($_GET['formid']) && $_GET['formid']==17358&&$current_user->ID==0)
{
$wpcf_access->settings=array();
}
}
I thought that it could work instead of auto-logging new users, but it doesn't either. I have tried leaving one code and just running the other, I also tried having both of them on my functions.php at the same time, to no avail.
Waqar has holidays this week, so let me jump in here.
The site credentials you provided Waqar no longer work, and I need to see how your forms are set up so that I can try and match that on my local test site to understand why this isn't working.
Can I get updated credentials from you? I've set up a private reply.
I'm looking at your site and I have some ideas about what the problem may be, but I need to test it and so I'm creating a test site now that reproduces your workflow with the auto-login.
I can't replicate the problem you describe despite repeated efforts with different combinations of settings etc.
I haven't tried it on your own site because it's a live site.
Do you have a staging site for testing?
Or can I try it with creating a dummy user on your live site?
A staging site would be better, as if there is no helpful info available in the browser dev tools looking at the network request then the next step would be to try a slimmed-down version of your site with all non-Toolset plugins disabled to see if something is conflicting in this process.
The install is bare bones, just the Divi theme and its child theme and the Toolset plugins I use on the live site. I have imported all Types, Views, Forms and Access from the live site as well. I also put in the following codes on my functions.php file: autologin for new CRED user, limit image upload file size and redirect to homepage after log out.
I have tried the process again and it's still giving me "An error occurred in the upload. Please try again later."
Thanks for creating the test site. I was able to try a number of things but was still unable to get it to work.
There appeared to be something fundamentally wrong about auto-logging in the new user, because never mind the question of uploading images in a Toolset Form, if you clicked the logout link before trying anything else you were shown a 403 error.
Suspecting the issue may be specific to your server configuration I created a copy of your site and installed it locally.
There it worked fine, no problems uploading images for the auto-logged in user.
I can't think of what server settings would prevent the auto-login from working, I'm afraid, it may be something you need to discuss with your host.