Ticket #7709 (new enhancement)

Opened 4 months ago

Last modified 3 months ago

'content_url' not filterable

Reported by: krudolph Assigned to: anonymous
Priority: low Milestone: 2.8
Component: Template Version: 2.7
Severity: minor Keywords:
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.

Change History

(follow-up: ↓ 2 ) 09/08/08 12:51:26 changed by DD32

  • version set to 2.7.

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

(in reply to: ↑ 1 ) 09/08/08 14:20:07 changed by krudolph

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”).

09/09/08 00:57:57 changed by DD32

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.

09/09/08 07:27:44 changed by krudolph

  • summary changed from 'content_url' not pluggable to 'content_url' not filterable.

10/23/08 01:22:26 changed by jacobsantos

  • component changed from General to Template.

10/23/08 01:22:30 changed by jacobsantos

  • type changed from defect to enhancement.