WordPress at a glance

plugin_basename() WP 1.0

Gets the basename of a plugin.

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

  • Global. Array. $wp_plugin_paths
✈ 1 time = 0.000039s = very fast | 50000 times = 0.63s = very fast

No Hooks.

Return

String. The name of a plugin.

Usage

plugin_basename( $file );
$file(string) (required)
The filename of plugin.

Code of plugin_basename: wp-includes/plugin.php VER 5.0

<?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;
}

Related Functions

From tag: plugin

More from category: Plugins, Hooks

No comments
    Hello, !     Log In . Register