[wp-hackers] Determining URL from within a plugin

Denis de Bernardy denis at semiologic.com
Wed Jan 25 16:30:35 GMT 2006


I personally use a few defines:

if ( !defined('site_url') )
{
	define('site_url', trailingslashit(get_settings('siteurl')));
}
if ( !defined('site_path') )
{
	define('site_path', str_replace(('http://' . $_SERVER['HTTP_HOST']),
'', site_url));
}

and:

$plugin_path = str_replace(
					str_replace("\\", "/", ABSPATH),
					'',
					str_replace("\\", "/",
dirname(__FILE__))
					);

the str_replace("\\", "/", ...) prevents it from breaking on windows
platforms. and typically, you'll use $this->path within a class rather than
$plugin_path to avoid name collisions.

from there:

echo site_url;

http://yoursite.com/wp-dir/

echo site_path;

/wp-dir/

echo site_path . $plugin_path;

/wp-dir/wp-content/plugins/plugin-dir

echo site_path . $plugin_path . '/plugin-file.php';

/wp-dir/wp-content/plugins/plugin-dir/plugin-file.php


hope this helps.

D.

> -----Original Message-----
> From: wp-hackers-bounces at lists.automattic.com 
> [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of 
> Owen Winkler
> Sent: Wednesday, January 25, 2006 3:34 PM
> To: wp-hackers at lists.automattic.com
> Subject: Re: [wp-hackers] Determining URL from within a plugin
> 
> 
> Matthew Butt wrote:
> > I'm trying to figure out how to work out the URL of a file within a 
> > plugin.
> 
> $basename = str_replace('\\', '/', 
> preg_replace('/^.*wp-content[\\\\\/]plugins[\\\\\/]/', '', 
> __FILE__)); $pluginuri = get_settings('siteurl') . 
> '/wp-content/plugins/' . $basename;
> 
> Or something like that there.
> 
> Owen
> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com 
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> 



More information about the wp-hackers mailing list