获取插件的基名。
原型
plugin_basename( string $file )
描述
此方法从其文件名中提取插件的名称。
参数
$file
(string)
(Required)
插件的文件名。
返回值
(string)
插件的名称。
源文件
路径:wp-includes/plugin.php
<?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 );
$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
$file = trim($file, '/');
return $file;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/plugin_basename/