AyeCode / userswp

Lightweight WordPress User Profile Plugin, provides a front end login form, registration form, edit account form, forgot password, searchable users directory, and user profiles. It can be extended and we provide add-ons to integrate it with WooCommerce, Easy Digital Downloads, Wp Jobs Manager, GeoDirectory, MailChimp, and many other plugins.
https://userswp.io/
GNU General Public License v2.0
63 stars 26 forks source link

Incorrect asset enqueuing if plugin_url() is relative #655

Open krozendaal opened 2 years ago

krozendaal commented 2 years ago

Hi,

I noticed that the form builder didn't work correctly ( I couldn't change the form options after creation). After a little bit of digging I noticed this issue was due to the get_url() method of the AyeCode_UI_Settings class not returning the correct value if the plugin_url() returned a relative path (relative to the domain).

To fix this issue I propose to add the following code to the get_url() method: if(empty($url_parts[0]) && !empty($dir_parts[1])){ $url = trailingslashit( "/$wp_content_folder_name/".$dir_parts[1] ); }

This will fix the issue.

Kind regards, Kenneth

Stiofan commented 2 years ago

Hi Kenneth,

Can you give a bit more details, a file/line number, and what you expect to be output and what is actually output? (i don't see plugin_url() used in that class)

Thanks,

Stiofan

krozendaal commented 2 years ago

Hi Stiofan,

I'm sorry, I made a typo. It shoulde be plugins_url(). It's line 1342 starting the method.

The output ($url variable) should be the complete URL to the current folder, however if plugins_url() is a relative path, $url_parts[0] will end up being "", for which !empty($url_parts[0]) returns false. This results in the $url being returned being just an empty string ("") and thus assets being wrong enqueued.

Stiofan commented 2 years ago

i have never seen this as a relative path, i guess you are filtering it for some reason?

krozendaal commented 2 years ago

Hi Stiofan,

We have a custom folder structure for all client sites. We use /assets/plugins instead of {domain}/wp-content/plugins. We set this in the wp-config.php file.

Stiofan commented 2 years ago

ok i guess you are setting the constant "WP_PLUGIN_URL", that is supposed to be a full URL, is there a reason not to use the full url?

krozendaal commented 2 years ago

Ah I see, I think the issue is in the WP_CONTENT_URL, which is defined relative to the domain (starting with a slash), as we use the same wp_config.php for all client sites (DB settings and Auth Keys excluded). The issue is that we do not have access to get_option('site_url') in the wp-config.php. For this reason we have to make the WP_CONTENT_URL relative.

Stiofan commented 2 years ago

how many sites are we talking?

krozendaal commented 2 years ago

Roughly 50 sites, however only one is using this plug-in at the moment.

Stiofan commented 2 years ago

What about adding a check then?

if($_SERVER['HTTP_HOST'] == 'example.com'){
// defind with full url
}else{
// current define
}

I'm hesitant to add our own checks for this as that constant should always be a full URL