Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#7709 closed enhancement (fixed)

'content_url' (and other *_url() functions) not filterable

Reported by: krudolph's profile krudolph Owned by:
Milestone: 2.8 Priority: low
Severity: minor Version: 2.7
Component: Template Keywords: has-patch
Focuses: Cc:

Description

Hi,

A call to content_url invariably returns the whole path, including the "http[s]:" prefix and the server name. This may not be desired. In fact, I've written a filter function for option_siteurl and option_home to strip all local URIs off their server name, i.e. "http://example.com/blog/x" becomes "/blog/x".

However, since content_url isn't pluggable, my filter function doesn't catch all URIs (especially not theme-related URIs such as the stylesheet link). Actually, content_url uses WP_CONTENT_URL, which, in turn, calls get_option('siteurl'), which, in turn, is pluggable. Unfortunately, this call is made before filter functions get registered because WP_CONTENT_URL is a global constant.

I propose two possible solutions:

  • Make WP_CONTENT_URL a function. Since the constant is for internal use only, the scope of this change should be local. This solution would be preferred because it means that one hook would suffice to manipulate all local URIs created by WordPress.
  • Make content_url pluggable.

Attachments (1)

bug7709.link-template.diff (1.0 KB) - added by coffee2code 15 years ago.

Download all attachments as: .zip

Change History (11)

#1 follow-up: @DD32
16 years ago

  • Version set to 2.7

how about defining the constants after plugins are loaded?, or filtering the output of content_dir() (and its friends)

#2 in reply to: ↑ 1 @krudolph
16 years ago

Replying to DD32:

how about defining the constants after plugins are loaded?

Well, since the constant is set in WP's core there's no chance of that. Reading the wp-config.php file is definitely required before plugins and themes can be loaded.

or filtering the output of content_dir() (and its friends)

I suppose you mean content_url (since there's no content_dir function anywhere in the code base)? As I wrote, its content cannot be filtered (that's what I meant by “not pluggable”).

#3 @DD32
16 years ago

Well, since the constant is set in WP's core there's no chance of that. Reading the wp-config.php file is definitely required before plugins and themes can be loaded

Sorry, It was late :/ I was thinking "URL's are in defines, Dir's are in functions"..

By moving them after the plugins are loaded, i was refering to the default values, with the thought "If a user defines it manually, thats what they want full stop" in the back of my mind.

I suppose you mean content_url (since there's no content_dir function anywhere in the code base)? As I wrote, its content cannot be filtered

Ah yeah.. I meant the content_url() and family, some plugins will use the constants, others will use the functions though, so be warned there..

that's what I meant by “not pluggable”).

Sorry, "pluggable" means Function-replace, While "filtered" means having a filter available to me, thats probably what got me a bit confused.

Adding a filter to the *_url() functions would be a good move IMO, but, as i said before, not all plugins use it, and a fair few are going to rely on the constants directly.

#4 @krudolph
16 years ago

  • Summary changed from 'content_url' not pluggable to 'content_url' not filterable

#5 @jacobsantos
16 years ago

  • Component changed from General to Template

#6 @jacobsantos
16 years ago

  • Type changed from defect to enhancement

#7 @FFEMTcJ
15 years ago

  • Milestone changed from 2.8 to Future Release

#8 @coffee2code
15 years ago

  • Cc coffee2code added
  • Keywords has-patch added
  • Milestone changed from Future Release to 2.8
  • Summary changed from 'content_url' not filterable to 'content_url' (and other *_url() functions) not filterable

In link-template.php, site_url() is filterable, yet its associates are not:

  • admin_url()
  • includes_url()
  • content_url()
  • plugins_url()

The attached patch, bug7709.link-template.diff, simply makes the url that would be returned from each of those functions filterable.

#9 @ryan
15 years ago

(In [10983]) Add url filters. Props coffee2code. see #7709

#10 @coffee2code
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.