Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there any equivalent to functions like plugins_url() and content_url() that give you either the relative paths or the file path.

For instance, instead of

http://localhost:8888/wordpress-3.2/wp-content

I want:

/Users/username/Sites/wordpress-3.2/wp-content

I know that I can build this path using the ABSPATH constant, but I'm specifically interested in learning if there are built in functions to handle this.

In the meantime, I'll probably just write a function to swap the url for the abspath.

EDIT: Here's the simple function that I wrote to handle this:

function get_file_path($url)
{
    return str_replace(site_url(), ABSPATH, $url);
}

Seems to do the trick, but I'd much rather use built in functions if available.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

There aren't any for plugins, but you can (and should) use WP_CONTENT_DIR, instead of ABSPATH.

For themes you have locate_template().

share|improve this answer
    
Thanks scribu! Funny thing is the project I was working with attempted to redefined WP_CONTENT_DIR. –  tollmanz Aug 4 '11 at 19:50
    
As per my answer there is WP_PLUGIN_DIR, plugins are not strictly tied to content. Gave me a lot of grief recently. :) –  Rarst Aug 4 '11 at 20:04
    
@Rarst After Scribu's answer, I looked around where WP_CONTENT_DIR was defined and found WP_PLUGIN_DIR. Nice to know these exist. I've ridded the project of ABSPATH! –  tollmanz Aug 4 '11 at 20:30

There is plugin_dir_path(), but it's not exact analogue of plugins_url().

Also ABSPATH is unreliable for how you use it, related paths can be easily redefined. See default-constants.php file.

Namely there are:

  • WP_CONTENT_DIR
  • WP_PLUGIN_DIR
  • WPMU_PLUGIN_DIR
share|improve this answer
    
Thanks as always Rarst! –  tollmanz Aug 4 '11 at 20:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.