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

Additional WP Constants #275

Open
gin0115 opened this issue Dec 11, 2024 · 11 comments
Open

Additional WP Constants #275

gin0115 opened this issue Dec 11, 2024 · 11 comments

Comments

@gin0115
Copy link

gin0115 commented Dec 11, 2024

Would it be possible to add the following constants to the bootstrap file? i know the paths are present, but URLs are useful for enqueued scripts etc

  • WP_CONTENT_URL
  • WP_PLUGIN_URL
  • WPMU_PLUGIN_URL

Many thanks

@szepeviktor
Copy link
Owner

Hello Glynn 👋🏻

Do these constants have a core function?

@gin0115
Copy link
Author

gin0115 commented Dec 11, 2024

yeah they are defined by wp_plugin_directory_constants()

https://developer.wordpress.org/reference/functions/wp_plugin_directory_constants/

@szepeviktor
Copy link
Owner

I mean to read them.

@szepeviktor
Copy link
Owner

I'd like to end up at this question: Are they supposed to be used my plugins?

@szepeviktor
Copy link
Owner

... and at this answer: I know there are use-cases when you have to use them,
but you could add them to your own bootstrap file.

@gin0115
Copy link
Author

gin0115 commented Dec 11, 2024

We use them in our code (themes and plugins) and our attempts at as PHPStan see these being flagged as not found.

I appreciate we could add them to our bootstrap, but we wasn't sure if this is something that should be included with the other core constants on the included bootstrap 🤷🏼

@szepeviktor
Copy link
Owner

URLs are useful for enqueued scripts

Could you share one line of code?

@gin0115
Copy link
Author

gin0115 commented Dec 11, 2024

Here is one example (not as an enqueue, i cant remember what project thats in ) where we allow a user to put images in the root of the uploads dir, then get all the files as paths and covert them into urls
$img_src = \str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $logo_path );

@szepeviktor
Copy link
Owner

szepeviktor commented Dec 11, 2024

I see.
If I would add those constants I would encourage users not to use the Media Library to manage images.
Sorry.

@szepeviktor
Copy link
Owner

szepeviktor commented Dec 11, 2024

BTW That line is dangerous. One is a filesystem path, the other is a URL.
\ vs. %4C big 💣

@IanDelMar
Copy link
Contributor

IanDelMar commented Dec 11, 2024

content_url()
plugins_url()

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

No branches or pull requests

3 participants