函数原型
plugin_basename( string $file ): string
函数描述
Gets the basename of a plugin.
是否弃用
未弃用
函数参数
-
$file
string
Required - The filename of plugin.
函数返回值
string The name of a plugin.
函数位置
File: wp-includes/plugin.php.
函数源码
function plugin_basename( $file ) {
global $wp_plugin_paths;
// $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 ) );
}
}
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
// Get relative path from plugins directory.
$file = preg_replace( '#^' . preg_quote( $plugin_dir, '#' ) . '/|^' . preg_quote( $mu_plugin_dir, '#' ) . '/#', '', $file );
$file = trim( $file, '/' );
return $file;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |

