From b9d16081507249186582e29df8bb85be2412176d Mon Sep 17 00:00:00 2001 From: westi Date: Sun, 15 Feb 2009 16:50:45 +0000 Subject: [PATCH] Extend plugins_url to allow you to specify the plugin file you want to be relative to so slugs don't need to be hardcoded. Fixes #6341. git-svn-id: http://svn.automattic.com/wordpress/trunk@10578 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 927854cfef..b86218eb87 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1504,15 +1504,17 @@ function content_url($path = '') { } /** - * Retrieve the url to the plugins directory. + * 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. * * @package WordPress * @since 2.6.0 * * @param string $path Optional. Path relative to the plugins url. + * @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__ * @return string Plugins url link with optional path appended. */ -function plugins_url($path = '') { +function plugins_url($path = '', $plugin = '') { $scheme = ( is_ssl() ? 'https' : 'http' ); $url = WP_PLUGIN_URL; if ( 0 === strpos($url, 'http') ) { @@ -1520,6 +1522,13 @@ function plugins_url($path = '') { $url = str_replace( 'http://', "{$scheme}://", $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, '/');