WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 months ago

#19200 closed enhancement (duplicate)

Introduce themes_url() and upload_url()

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

Download all attachments as: .zip

Change History (24)

comment:1 follow-up: scribu2 years ago

  • Type changed from defect (bug) to enhancement

We already have wp_upload_dir().

comment:2 in reply to: ↑ 1 mikeschinkel2 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.

comment:3 ramiy2 years ago

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

ramiy2 years ago

upload_url()

comment:4 ramiy2 years ago

  • Keywords has-patch added

comment:5 scribu2 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 get_site_url().

Also, you have some missing whitespace around function calls.

Last edited 2 years ago by scribu (previous) (diff)

comment:6 scribu2 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.

ramiy2 years ago

comment:8 scribu2 years ago

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

19200b.patch looks good.

comment:9 ramiy2 years ago

Maybe 3.4?

comment:10 scribu2 years ago

  • Keywords commit removed

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

comment:11 ramiy2 years ago

You are right, it should be 'url' rather 'baseurl'. Nice catch. :-)

Version 0, edited 2 years ago by ramiy (next)

comment:12 scribu2 years 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 ramiy2 years ago

Do we have plugins_url() and plugins_base_url()?

comment:14 follow-up: scribu2 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).

comment:15 in reply to: ↑ 14 ramiy2 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 2 years ago by ramiy (previous) (diff)

comment:16 ramiy2 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.

comment:17 ramiy2 years ago

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

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

ramiy2 years ago

upload_url() + themes_url()

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

Related: #18302

comment:19 toscho19 months ago

  • Cc info@… added

comment:20 nacin3 months ago

  • Component changed from General to Template

comment:21 nacin2 months 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.