Opened 19 months ago
Last modified 8 months ago
#19200 new enhancement
Introduce themes_url() and upload_url()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | mikeschinkel@…, info@… |
Description
WordPress has some very usefull url tempalate tags in the wp-includes/link-template.php file, functions like:
home_url() => ../ site_url() => ../ admin_url() => ../wp-admin/ includes_url() => ../wp-includes/ content_url() => ../wp-content/ plugins_url() => ../wp-content/plugins/
we need 2 more functions:
themes_url() => ../wp-content/themes/ upload_url() => ../wp-content/upload/
they will make developers life easier.
Attachments (3)
Change History (22)
comment:2
in reply to:
↑ 1
mikeschinkel — 19 months ago
- Cc mikeschinkel@… added
Replying to scribu:
We already have wp_upload_dir().
wp_upload_dir() returns an array and since PHP does not allow indexing the return values of a function -- i.e. since this is not valid in PHP: wp_upload_dir()['baseurl'] -- it would be really nice to have an upload_url() function, for consistency with the others if nothing else.
function upload_url() {
$upload_dir = wp_upload_dir();
return $upload_dir['baseurl'];
}
I don't think this is check is appropriate here:
if ( 0 === strpos($url, 'http') && is_ssl() ) $url = str_replace( 'http://', 'https://', $url );
Instead, we should make wp_upload_dir() use get_site_url().
Also, you have some missing whitespace around function calls.
Actually, the problem is that the uploads url can be an entirely different domain, which is not guaranteed to have SSL.
In any case, uploads_url() should just use what wp_upload_dir() returns, without modifying the protocol.
- Keywords commit added
- Milestone changed from Awaiting Review to Future Release
19200b.patch looks good.
comment:10
scribu — 17 months ago
- Keywords commit removed
Wait a second. Why should upload_url() return 'baseurl', rather than 'url'?
comment:11
ramiy — 17 months ago
You are right, it should be 'url' rather 'baseurl'. Nice catch. :-)
comment:12
scribu — 17 months ago
And if someone doesn't agree, are we going to introduce an upload_base_url() helper as well? What about upload paths?
comment:13
ramiy — 17 months ago
Do we have plugins_url() and plugins_base_url()?
comment:14
follow-up:
↓ 15
scribu — 17 months ago
No, because there's only one plugins directory, whereas you have a base uploads directory and a current uploads directory (uploads/2012/01).
comment:15
in reply to:
↑ 14
ramiy — 17 months ago
Same with plugins/themes,
we have a base directory <http://example.com/wp-content/plugins>
and a current plugin dirctory <http://example.com/wp-content/plugins/some-plugin>
comment:16
ramiy — 17 months ago
Another thing - if we will use upload_base_url() and upload_url(), the function names won't be consistant with the functions mentioned above in the introductory paragraph.
comment:17
ramiy — 17 months ago
By the way, for themes url, we can use:
function themes_url() {
$themes_url= get_theme_root_uri();
return $themes_url;
}
comment:18
in reply to:
↑ 7
ramiy — 9 months ago
Related: #18302
comment:19
toscho — 8 months ago
- Cc info@… added

We already have wp_upload_dir().