# wp_ajax_delete_plugin()

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

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

## Сигнатура

```php
wp_ajax_delete_plugin()
```

## Описание

См. alsodelete_plugins()

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

Файл: `wp-admin/includes/ajax-actions.php:4726`

```php
function wp_ajax_delete_plugin() {
	check_ajax_referer( 'updates' );

	if ( empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) {
		wp_send_json_error(
			array(
				'slug'         => '',
				'errorCode'    => 'no_plugin_specified',
				'errorMessage' => __( 'No plugin specified.' ),
			)
		);
	}

	$plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) );

	$status = array(
		'delete' => 'plugin',
		'slug'   => sanitize_key( wp_unslash( $_POST['slug'] ) ),
	);

	if ( ! current_user_can( 'delete_plugins' ) || 0 !== validate_file( $plugin ) ) {
		$status['errorMessage'] = __( 'Sorry, you are not allowed to delete plugins for this site.' );
		wp_send_json_error( $status );
	}

	$plugin_data          = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
	$status['plugin']     = $plugin;
	$status['pluginName'] = $plugin_data['Name'];

	if ( is_plugin_active( $plugin ) ) {
		$status['errorMessage'] = __( 'You cannot delete a plugin while it is active on the main site.' );
		wp_send_json_error( $status );
	}

	// Check filesystem credentials. `delete_plugins()` will bail otherwise.
	$url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked[]=' . $plugin, 'bulk-plugins' );

	ob_start();
	$credentials = request_filesystem_credentials( $url );
	ob_end_clean();

	if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
		global $wp_filesystem;

		$status['errorCode']    = 'unable_to_connect_to_filesystem';
		$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );

		// Pass through the error from WP_Filesystem if one was raised.
		if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
			$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
		}

		wp_send_json_error( $status );
	}

	$result = delete_plugins( array( $plugin ) );

	if ( is_wp_error( $result ) ) {
		$status['errorMessage'] = $result->get_error_message();
		wp_send_json_error( $status );
	} elseif ( false === $result ) {
		$status['errorMessage'] = __( 'Plugin could not be deleted.' );
		wp_send_json_error( $status );
	}

	wp_send_json_success( $status );
}
```

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

- 4.6.0 — Introduced.

## Связанные

Использует: [`is_plugin_active`](https://chugunov.pro/api-wordpress/functions/is_plugin_active/), [`delete_plugins`](https://chugunov.pro/api-wordpress/functions/delete_plugins/), [`get_plugin_data`](https://chugunov.pro/api-wordpress/functions/get_plugin_data/), [`request_filesystem_credentials`](https://chugunov.pro/api-wordpress/functions/request_filesystem_credentials/), [`WP_Filesystem`](https://chugunov.pro/api-wordpress/functions/wp_filesystem/), [`validate_file`](https://chugunov.pro/api-wordpress/functions/validate_file/), [`plugin_basename`](https://chugunov.pro/api-wordpress/functions/plugin_basename/), [`current_user_can`](https://chugunov.pro/api-wordpress/functions/current_user_can/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`sanitize_text_field`](https://chugunov.pro/api-wordpress/functions/sanitize_text_field/), [`wp_unslash`](https://chugunov.pro/api-wordpress/functions/wp_unslash/), [`esc_html`](https://chugunov.pro/api-wordpress/functions/esc_html/), [`sanitize_key`](https://chugunov.pro/api-wordpress/functions/sanitize_key/), [`check_ajax_referer`](https://chugunov.pro/api-wordpress/functions/check_ajax_referer/), [`wp_send_json_error`](https://chugunov.pro/api-wordpress/functions/wp_send_json_error/), [`wp_send_json_success`](https://chugunov.pro/api-wordpress/functions/wp_send_json_success/), [`wp_nonce_url`](https://chugunov.pro/api-wordpress/functions/wp_nonce_url/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).

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