获取插件的基名称。
说明(Description)
此方法从插件的文件名中提取插件的名称。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$file | (string) | 必需 | 插件的文件名。 |
返回(Return)
(string)插件的名称。
源码(Source)
/**
* Gets the basename of a plugin.
*
* This method extracts the name of a plugin from its filename.
*
* @since 1.5.0
*
* @global array $wp_plugin_paths
*
* @param string $file The filename of plugin.
* @return string The name of a plugin.
*/
function plugin_basename( $file ) {
global $wp_plugin_paths;
foreach ( $wp_plugin_paths as $dir => $realdir ) {
if ( strpos( $file, $realdir ) === 0 ) {
$file = $dir . substr( $file, strlen( $realdir ) );
}
}
$file = wp_normalize_path( $file );
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
$file = trim($file, '/');
return $file;
}
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.5.0 | wp-includes/plugin.php:679 | 17 | 1 function |