Opened 19 months ago

Last modified 8 months ago

#19200 new enhancement

Introduce themes_url() and upload_url()

Reported by: ramiy 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)

19200.patch (938 bytes) - added by ramiy 19 months ago.
upload_url()
19200b.patch (840 bytes) - added by ramiy 19 months ago.
19200c.patch (1.3 KB) - added by ramiy 17 months ago.
upload_url() + themes_url()

Download all attachments as: .zip

Change History (22)

comment:1 follow-up: ↓ 2   scribu19 months ago

  • Type changed from defect (bug) to enhancement

We already have wp_upload_dir().

comment:2 in reply to: ↑ 1   mikeschinkel19 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'];
}

ramiy19 months ago

upload_url()

  • Keywords has-patch added

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.

Last edited 19 months ago by scribu (previous) (diff)

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.

ramiy19 months ago

comment:7 follow-up: ↓ 18   ocean9019 months ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to Future Release

19200b.patch looks good.

Maybe 3.4?

  • Keywords commit removed

Wait a second. Why should upload_url() return 'baseurl', rather than 'url'?

The 'baseurl' will return <http://example.com/wp-content/uploads>

and the 'url' will return <http://example.com/wp-content/uploads/2012/01>

We want to return the "upload" directory (=baseurl).

Last edited 17 months ago by ramiy (previous) (diff)

And if someone doesn't agree, are we going to introduce an upload_base_url() helper as well? What about upload paths?

Do we have plugins_url() and plugins_base_url()?

comment:14 follow-up: ↓ 15   scribu17 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   ramiy17 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>

Last edited 17 months ago by ramiy (previous) (diff)

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.

By the way, for themes url, we can use:

function themes_url() {
   $themes_url= get_theme_root_uri();
   return $themes_url;
}

ramiy17 months ago

upload_url() + themes_url()

comment:18 in reply to: ↑ 7   ramiy9 months ago

Related: #18302

  • Cc info@… added
Note: See TracTickets for help on using tickets.