Improve plugin detection. Related to #82.
Technically, it's possible to place a plugin anywhere outside the WordPress directory and then create a symlink inside /wp-content/plugins that points to the plugin directory. If the plugin developer then passes the real, symlink-resolved path to the PUC factory, PUC will assume it can't be a plugin because it's not inside the expected directory. Semi-fixed by checking if the input file contains a valid plugin header. However, I would still recommend against using symlinks in this manner because it's likely to cause odd bugs elsewhere. For example, __FILE__ resolves symlinks but plugin_basename() doesn't. This means that the basename that WP sees and the basename you generate in your own code might not match.
This commit is contained in:
parent
467000eb73
commit
8a04b9679e
|
|
@ -108,16 +108,27 @@ if ( !class_exists('Puc_v4_Factory', false) ):
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if the path points to something inside the "plugins" or "mu-plugins" directories.
|
||||
* Check if the path points to a plugin file.
|
||||
*
|
||||
* @param string $absolutePath Normalized path.
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isPluginFile($absolutePath) {
|
||||
//Is the file inside the "plugins" or "mu-plugins" directory?
|
||||
$pluginDir = wp_normalize_path(WP_PLUGIN_DIR);
|
||||
$muPluginDir = wp_normalize_path(WPMU_PLUGIN_DIR);
|
||||
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0);
|
||||
//Does it have a valid plugin header?
|
||||
//This is a last-ditch check for plugins symlinked from outside the WP root.
|
||||
if ( function_exists('get_file_data') ) {
|
||||
$headers = get_file_data($absolutePath, array('Name' => 'Plugin Name'), 'plugin');
|
||||
return !empty($headers['Name']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue