userswp
userswp copied to clipboard
Incorrect asset enqueuing if plugin_url() is relative
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
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
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.
i have never seen this as a relative path, i guess you are filtering it for some reason?
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.
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?
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.
how many sites are we talking?
Roughly 50 sites, however only one is using this plug-in at the moment.
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