Make plugin_dir() and plugin_basename() work for mu-plugins directory, props Denis-de-Bernardy, fixes #9561

git-svn-id: http://svn.automattic.com/wordpress/trunk@11069 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-04-23 08:16:06 +00:00
parent 91a3c4bbf4
commit 8682f79e6a
2 changed files with 11 additions and 4 deletions

View File

@ -1775,14 +1775,19 @@ function content_url($path = '') {
*/
function plugins_url($path = '', $plugin = '') {
$scheme = ( is_ssl() ? 'https' : 'http' );
$url = WP_PLUGIN_URL;
if ( $plugin !== '' && preg_match('#^' . preg_quote(WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR, '#') . '#', $plugin) ) {
$url = WPMU_PLUGIN_URL;
} else {
$url = WP_PLUGIN_URL;
}
if ( 0 === strpos($url, 'http') ) {
if ( is_ssl() )
$url = str_replace( 'http://', "{$scheme}://", $url );
}
if ( !empty($plugin) && is_string($plugin) )
{
if ( !empty($plugin) && is_string($plugin) ) {
$folder = dirname(plugin_basename($plugin));
if ('.' != $folder)
$url .= '/' . ltrim($folder, '/');

View File

@ -492,7 +492,9 @@ function plugin_basename($file) {
$file = preg_replace('|/+|','/', $file); // remove any duplicate slash
$plugin_dir = str_replace('\\','/',WP_PLUGIN_DIR); // sanitize for Win32 installs
$plugin_dir = preg_replace('|/+|','/', $plugin_dir); // remove any duplicate slash
$file = preg_replace('|^' . preg_quote($plugin_dir, '|') . '/|','',$file); // get relative path from plugins dir
$mu_plugin_dir = str_replace('\\','/',WPMU_PLUGIN_DIR); // sanitize for Win32 installs
$mu_plugin_dir = preg_replace('|/+|','/', $mu_plugin_dir); // remove any duplicate slash
$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
return $file;
}