WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Plugin_Upgrader::delete_old_plugin() public WP 2.8.0

Deletes the old plugin during an upgrade.

Hooked to the 'upgrader_clear_destination' filter by Plugin_Upgrader::upgrade() and Plugin_Upgrader::bulk_upgrade().

Это метод класса: Plugin_Upgrader{}

Хуков нет.

Возвращает

true/false/WP_Error.

Использование

$Plugin_Upgrader = new Plugin_Upgrader();
$Plugin_Upgrader->delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin );
$removed(true/false/WP_Error) (обязательный)
Whether the destination was cleared. True on success, WP_Error on failure.
$local_destination(строка) (обязательный)
The local package destination.
$remote_destination(строка) (обязательный)
The remote package destination.
$plugin(массив) (обязательный)
Extra arguments passed to hooked filters.

Заметки

  • Global. WP_Filesystem_Base. $wp_filesystem WordPress filesystem subclass.

Список изменений

С версии 2.8.0 Введена.

Код Plugin_Upgrader::delete_old_plugin() WP 5.5.1

wp-admin/includes/class-plugin-upgrader.php
<?php
public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
	global $wp_filesystem;

	if ( is_wp_error( $removed ) ) {
		return $removed; // Pass errors through.
	}

	$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
	if ( empty( $plugin ) ) {
		return new WP_Error( 'bad_request', $this->strings['bad_request'] );
	}

	$plugins_dir     = $wp_filesystem->wp_plugins_dir();
	$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );

	if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { // If it's already vanished.
		return $removed;
	}

	// If plugin is in its own directory, recursively delete the directory.
	// Base check on if plugin includes directory separator AND that it's not the root plugin folder.
	if ( strpos( $plugin, '/' ) && $this_plugin_dir !== $plugins_dir ) {
		$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
	} else {
		$deleted = $wp_filesystem->delete( $plugins_dir . $plugin );
	}

	if ( ! $deleted ) {
		return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
	}

	return true;
}