Plugins: In plugin_basename()
sort plugin paths before resolving symlinks.
`arsort()` sorts the paths reverse-alphabetically while preserving the keys. It results in a longer path being listed before a shorter one with the same base directory(ies). Props jdgrimes, ocean90. Fixes #28441. git-svn-id: https://develop.svn.wordpress.org/trunk@37983 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ad52e49e4f
commit
0037aa1dd5
@ -731,6 +731,7 @@ function plugin_basename( $file ) {
|
||||
// $wp_plugin_paths contains normalized paths.
|
||||
$file = wp_normalize_path( $file );
|
||||
|
||||
arsort( $wp_plugin_paths );
|
||||
foreach ( $wp_plugin_paths as $dir => $realdir ) {
|
||||
if ( strpos( $file, $realdir ) === 0 ) {
|
||||
$file = $dir . substr( $file, strlen( $realdir ) );
|
||||
|
@ -8,20 +8,57 @@
|
||||
*/
|
||||
class Tests_Plugin_Basename extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $wp_plugin_paths_backup;
|
||||
|
||||
/**
|
||||
* Normalized path to plugin directory.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $wp_plugin_path;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->wp_plugin_paths_backup = $GLOBALS['wp_plugin_paths'];
|
||||
$this->wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR );
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$GLOBALS['wp_plugin_paths'] = $this->wp_plugin_paths_backup;
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 29154
|
||||
*/
|
||||
function test_should_return_correct_basename_for_symlinked_plugins() {
|
||||
function test_return_correct_basename_for_symlinked_plugins() {
|
||||
global $wp_plugin_paths;
|
||||
|
||||
$old_wp_plugin_paths = $wp_plugin_paths;
|
||||
|
||||
$wp_plugin_paths[ wp_normalize_path( WP_PLUGIN_DIR ) . '/a-symlinked-plugin' ] = 'C:/www/path/plugins/a-plugin';
|
||||
$wp_plugin_paths = array(
|
||||
$this->wp_plugin_path . '/a-symlinked-plugin' => 'C:/www/path/plugins/a-plugin',
|
||||
);
|
||||
|
||||
$basename = plugin_basename( 'c:\www\path\plugins\a-plugin\plugin.php' );
|
||||
|
||||
$wp_plugin_paths = $old_wp_plugin_paths;
|
||||
|
||||
$this->assertSame( 'a-symlinked-plugin/plugin.php', $basename );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 28441
|
||||
*/
|
||||
function test_return_correct_basename_for_symlinked_plugins_with_path_conflicts() {
|
||||
global $wp_plugin_paths;
|
||||
|
||||
$wp_plugin_paths = array(
|
||||
$this->wp_plugin_path . '/plugin' => '/Users/me/Dropbox/Development/Repositories/plugin',
|
||||
$this->wp_plugin_path . '/trunk' => '/Users/me/Dropbox/Development/Repositories/plugin/trunk',
|
||||
);
|
||||
|
||||
$basename = plugin_basename( '/Users/me/Dropbox/Development/Repositories/plugin/trunk/plugin.php' );
|
||||
$this->assertSame( 'trunk/plugin.php', $basename );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user