Make WordPress Core

Opened 12 years ago

Closed 10 years ago

#19200 closed enhancement (duplicate)

Introduce themes_url() and upload_url()

Reported by: ramiy's profile ramiy Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Template Keywords: has-patch
Focuses: Cc:

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 12 years ago.
upload_url()
19200b.patch (840 bytes) - added by ramiy 12 years ago.
19200c.patch (1.3 KB) - added by ramiy 12 years ago.
upload_url() + themes_url()

Download all attachments as: .zip

Change History (24)

#1 follow-up: @scribu
12 years ago

  • Type changed from defect (bug) to enhancement

We already have wp_upload_dir().

#2 in reply to: ↑ 1 @mikeschinkel
12 years 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.

#3 @ramiy
12 years ago

function upload_url() {
   $upload_dir = wp_upload_dir();
   return $upload_dir['baseurl'];
}

@ramiy
12 years ago

upload_url()

#4 @ramiy
12 years ago

  • Keywords has-patch added

#5 @scribu
12 years ago

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 site_url().

Also, you have some missing whitespace around function calls.

Version 0, edited 12 years ago by scribu (next)

#6 @scribu
12 years ago

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.

@ramiy
12 years ago

#8 @scribu
12 years ago

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

19200b.patch looks good.

#9 @ramiy
12 years ago

Maybe 3.4?

#10 @scribu
12 years ago

  • Keywords commit removed

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

#11 @ramiy
12 years ago

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 12 years ago by ramiy (previous) (diff)

#12 @scribu
12 years ago

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

#13 @ramiy
12 years ago

Do we have plugins_url() and plugins_base_url()?

#14 follow-up: @scribu
12 years ago

No, because there's only one plugins directory, whereas you have a base uploads directory and a current uploads directory (uploads/2012/01).

#15 in reply to: ↑ 14 @ramiy
12 years 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 12 years ago by ramiy (previous) (diff)

#16 @ramiy
12 years 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.

#17 @ramiy
12 years ago

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

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

@ramiy
12 years ago

upload_url() + themes_url()

#18 in reply to: ↑ 7 @ramiy
12 years ago

Related: #18302

#19 @toscho
12 years ago

  • Cc info@… added

#20 @nacin
10 years ago

  • Component changed from General to Template

#21 @nacin
10 years ago

  • Milestone Future Release deleted
  • Resolution set to duplicate
  • Status changed from new to closed

I don't think we benefit much from an ambiguous upload URL function. I think #18302 otherwise covers this.

Note: See TracTickets for help on using tickets.