Skip Navigation

[Resolved] 'Featured Image' Upload Failed! when WP is using subdirectory (like Bedrock)

This support ticket is created 7 years, 8 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.

Our next available supporter will start replying to tickets in about 0.20 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 14 replies, has 3 voices.

Last updated by Beda 7 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#428707

Guys,

Seriously, start testing your plugins with every WordPress install variation possible. For example, when WP is using subdirectory like Bedrock WP Boilerplate.

Since, CRED version 1.6 I am waiting for a fix on this and you already said fix was to be included in the next update (https://toolset.com/forums/topic/toolset-code-errors/) . Then there was 1.7 and now 1.8, and guess what... this is not fixed, still...

Am I wrong to think that the point of this "Toolset Professional Support" is to listen to your clients and help them with whatever problem they are having about your products?

Here is the problem. Again.
1. Get Bedrock WP Boilerplate | hidden link
2. Follow the instructions and setup WordPress | hidden link (You can skip the deploying...)
3. Build a Post Form (Create content or Edit content, it doesn't matter) and include a 'Featured Image' field
4. Use the form to create/edit post content and try to set a 'Featured Image' ('Main Image' as you call it in your descriptions) with this form
5. ERROR. You get the 'Upload Failed!' alert.
6. Investigate... OPS, no need to investigate as I can tell you what the problem is...

Since:

toolset/toolset-common/toolset-forms/classes/submit.php
function cred_find_wp_config_path() {
    $dir = dirname(__FILE__);
    do {
        if (file_exists($dir . "/wp-load.php")) {
            return $dir . '/';
        }
    } while ($dir = realpath("$dir/.."));
    return null;
}

function cred_get_root_path() {
    return cred_find_wp_config_path();
}

Bedrock root path doesn't have file named wp-load.php, so obviously cred_find_wp_config_path() will fail. Until CRED version 1.8 it was wp-config.php and this function did not fail but the next one still does... cred_get_root_path() is assuming that if the file name exist then this is the wp root path, but as you can see here hidden link that is not the case. It is using a subdirectory called 'wp' so it should be '$dir/wp/'

I think this info should be more than enough to get the idea.

Regards,
Jordan

#428719

I think this is important to note:

Until 1.7.1 it was enough to edit:

cred-frontend-editor/embedded/toolset/toolset-common/toolset-forms/classes/submit.php

Now with the latest updates you have to edit:

types/library/toolset/toolset-common/toolset-forms/classes/submit.php

But, you should know exactly why is that.

#429147

We changed that due to the fact that wp-config.php can be moved and wp-load.php will always load the correct path.

As WordPress has, in any case, a wp-load.php it should also find it.
hidden link

What I am not sure is why we assume that it should be in dirname(__FILE__) since wp-content can be moved, and the wp-load.php is NOT in the wp-content folder.

I can not deploy the Bedrock install locally, the instructions are not clear and it does simply put, not mirror a WordPress install.

If you need us to analize Customized WordPress Installs, can you provide us with a Example server, where we have full access to the Server and the WP Install?

.env.example is empty on Bedrock setup and there is no instructions how to setup the install.

I apologize but this is above the scope of the Support here, as we provide a Plugin for WordPress installs from wordpress.org and if we need to change the Plugin to adapt to customized installs, we require more information to reproduce this.

We can not change CRED to find a path as $dir/wp/ just because one Tool uses that path.

We have several users they use WordPress in a native setup.

I agree with you that the assumption wp-load.php is in the dirname(__FILE__) of CRED is simply not correct.

I will discuss this with the Developers.

If you need detailed assistance for Bedrock I will need more details as above elaborated.

#430093

Hi Beda,

First:
Theres no need to search for the WP root path as the constant ABSPATH will 99.9% always point to that directory, so just use ABSPATH.

So this code below is really useless/pointless:

function cred_find_wp_config_path() {
    $dir = dirname(__FILE__);
    do {
        if (file_exists($dir . "/wp-load.php")) {
            return $dir . '/';
        }
    } while ($dir = realpath("$dir/.."));
    return null;
}

function cred_get_root_path() {
    return cred_find_wp_config_path();
}

Also, cred_get_root_path() return cred_find_wp_config_path(). Just use cred_find_wp_config_path()...

Second:
In general, loading wp-load.php in plugins is WRONG. Really.

You can never know where wp-load.php is. Plugin and wp-content directories can be moved (wp-content even renamed). Basically, all WordPress files can be moved. Searching for them is just... I don't want to say stupid, but it's not very clever thing to do either.

More on this here:
hidden link
Also:
hidden link

Please, forward this to your dev team, so they can optimize their coding.

Regards,
Jordan

#430647

Our Developer has a solution for it in a Develop Branch.

He asks, if one of below to options is valuable to you:

1. Provide us access to your Server (SFTP And WP Admin) where you use this specific Setup

OR

2. I send you a ZIP of CRED in a pathced form.

For either of both I will need access to a SFTP server to (in case of #2) upload the File, or, in case yu provide access, for full tests of our Developer.

This should be (in case of #1) a FULL TEST server, or at least, a backed up system

I am awating your reply.

#431852

Hi again,

In file:

types/library/toolset/toolset-common/toolset-forms/js/jquery_upload/file_upload.js

Line 165 there is:

jQuery("#attachid_" + myid).attr("value", attachid);

Problem is no input field is generated with that ID. So, unless you manually generate it, featured image field will not work.

Assuming you fixed the wrong approach to load wp-load.php, and now you fix this.
Everything should work very nice.

Regards,
Jordan

#432379

The featured image issue completely irrelated to the Bedrock setup.
It's a BUG that makes teh image not been assigned to the post (it simply misses the Meta infor Post ID.)

But it uploads - it is not assigned though.

Your report here is about code in CRED/Types that looks for wp-load.php and which causes problems in Bedrock Setup.

For that specific setup we woudl wish to send you a version of the Plugin with a different approach.

Please do not mix the issues in your reports, even if they are similar.

This will cuase the issue to be lost and not solved.
https://toolset.com/toolset-support-policy/

Can I send you the patched version of CRED to test this on your install?
If this is not possible please let me know.

#433477

Hi,

I think I see your point and I apologize for the mix up.
As for the test, yeah, sure. I have no problem with testing this patched version.

#433479

This would be very helpful!

I would like then to request FTP access so I could send you a Copy (ZIP) of CRED in develop version.

This should fix the problem.

I will enable a private form for this to be submitted safely.

#433900

Thank you.

We will begin tests ASAP.

Please stand by 🙂

#434391

Hi Beda,

Any news on the test?

#434438

Hi,

I'm sorry to jump here, I've got an update that this will be fixed in the next CRED release.

For now, please follow this Errata page instructions to solve the issue: https://toolset.com/errata/file-upload-fails-custom-wordpress-directories-structure/

Thanks.

#434557

Thanks,

Just wanted to confirm it work.

Just a side note, It only work if you are using CRED only.
If you use CRED and Types together this fix should also be applied to Types plugin too.

Best,
Jordan

#436921

This is great news.

I updated the Developers and will keep you update you here about our process in regard
We do have an erratum for now:
https://toolset.com/errata/file-upload-fails-custom-wordpress-directories-structure/

#440720

This is now solved in the Current Toolset Release.

Can you drop a line here once you updated Toolset, that it works for you too?

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