Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect asset enqueuing if plugin_url() is relative #655

Open
krozendaal opened this issue May 6, 2022 · 9 comments
Open

Incorrect asset enqueuing if plugin_url() is relative #655

krozendaal opened this issue May 6, 2022 · 9 comments

Comments

@krozendaal
Copy link

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
Copy link
Contributor

Stiofan commented May 6, 2022

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
Copy link
Author

krozendaal commented May 6, 2022

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
Copy link
Contributor

Stiofan commented May 6, 2022

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

@krozendaal
Copy link
Author

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
Copy link
Contributor

Stiofan commented May 6, 2022

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
Copy link
Author

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
Copy link
Contributor

Stiofan commented May 6, 2022

how many sites are we talking?

@krozendaal
Copy link
Author

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

@Stiofan
Copy link
Contributor

Stiofan commented May 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants