wpseek.com
WordPress开发者和主题制作者的搜索引擎



plugin_basename › WordPress Function

Since1.5.0
已弃用n/a
plugin_basename ( $file )
参数:
  • (string) $file The filename of plugin.
    Required: Yes
返回:
  • (string) The name of a plugin.
定义在:
文档:

Gets the basename of a plugin.

This method extracts the name of a plugin from its filename.


源码

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 ( str_starts_with( $file, $realdir ) ) {
			$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;
}