Definition:
function plugins_url($path = '', $plugin = '') {}
Retrieve the url to the plugins directory or to a specific file within that directory.
You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name.
Parameters
- string $path: Optional. Path relative to the plugins url.
- string $plugin: Optional. The plugin file that you want to be relative to – i.e. pass in __FILE__
Return values
returns:Plugins url link with optional path appended.
Defined filters
- plugins_url
apply_filters('plugins_url', $url, $path, $plugin)
Source code
function plugins_url($path = '', $plugin = '') {
$mu_plugin_dir = WPMU_PLUGIN_DIR;
foreach ( array('path', 'plugin', 'mu_plugin_dir') as $var ) {
$$var = str_replace('\\' ,'/', $$var); // sanitize for Win32 installs
$$var = preg_replace('|/+|', '/', $$var);
}
if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) )
$url = WPMU_PLUGIN_URL;
else
$url = WP_PLUGIN_URL;
if ( 0 === strpos($url, 'http') && is_ssl() )
$url = str_replace( 'http://', 'https://', $url );
if ( !empty($plugin) && is_string($plugin) ) {
$folder = dirname(plugin_basename($plugin));
if ( '.' != $folder )
$url .= '/' . ltrim($folder, '/');
}
if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
$url .= '/' . ltrim($path, '/');
return apply_filters('plugins_url', $url, $path, $plugin);
}
2515

February 12, 2011 


No comments yet... Be the first to leave a reply!