# plugin_basename()

URL: https://chugunov.pro/api-wordpress/functions/plugin_basename/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 1.5.0.

## Сигнатура

```php
plugin_basename( string $file ): string
```

## Описание

Этот метод извлекает имя плагина из его имени файла.

## Параметры

- `$file` `string` — обязательный. Имя файла плагина.

## Возвращаемое значение

`string`

## Исходный код

Файл: `wp-includes/plugin.php:775`

```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 ( 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;
}
```

## История изменений

- 1.5.0 — Introduced.

## Связанные

Использует: [`wp_normalize_path`](https://chugunov.pro/api-wordpress/functions/wp_normalize_path/).
Используется в: `WP_REST_Templates_Controller::get_wp_templates_author_text_field`, `WP_REST_Plugins_Controller::validate_plugin_param`, `WP_REST_Plugins_Controller::sanitize_plugin_param`, [`wp_skip_paused_plugins`](https://chugunov.pro/api-wordpress/functions/wp_skip_paused_plugins/), [`wp_ajax_delete_plugin`](https://chugunov.pro/api-wordpress/functions/wp_ajax_delete_plugin/), [`wp_ajax_update_plugin`](https://chugunov.pro/api-wordpress/functions/wp_ajax_update_plugin/), [`is_uninstallable_plugin`](https://chugunov.pro/api-wordpress/functions/is_uninstallable_plugin/), [`uninstall_plugin`](https://chugunov.pro/api-wordpress/functions/uninstall_plugin/), [`add_menu_page`](https://chugunov.pro/api-wordpress/functions/add_menu_page/), [`add_submenu_page`](https://chugunov.pro/api-wordpress/functions/add_submenu_page/), [`deactivate_plugins`](https://chugunov.pro/api-wordpress/functions/deactivate_plugins/), [`activate_plugin`](https://chugunov.pro/api-wordpress/functions/activate_plugin/), [`get_plugin_data`](https://chugunov.pro/api-wordpress/functions/get_plugin_data/), [`_get_plugin_data_markup_translate`](https://chugunov.pro/api-wordpress/functions/_get_plugin_data_markup_translate/), [`get_plugin_files`](https://chugunov.pro/api-wordpress/functions/get_plugin_files/), [`get_plugins`](https://chugunov.pro/api-wordpress/functions/get_plugins/), [`plugins_url`](https://chugunov.pro/api-wordpress/functions/plugins_url/), [`register_activation_hook`](https://chugunov.pro/api-wordpress/functions/register_activation_hook/), [`register_deactivation_hook`](https://chugunov.pro/api-wordpress/functions/register_deactivation_hook/), [`register_uninstall_hook`](https://chugunov.pro/api-wordpress/functions/register_uninstall_hook/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/plugin_basename/
