Plugin_Upgrader::delete_old_plugin()

最后更新于:2021-11-25 20:38:36

Plugin_Upgrader::delete_old_plugin( bool|GC_Error$removed, string$local_destination, string$remote_destination, array$plugin)

Deletes the old plugin during an upgrade.

参数

$removed

(bool|GC_Error) (Required) Whether the destination was cleared. True on success, GC_Error on failure.

$local_destination

(string) (Required) The local package destination.

$remote_destination

(string) (Required) The remote package destination.

$plugin

(array) (Required) Extra arguments passed to hooked filters.

响应

(bool|GC_Error)

源文件

文件: gc-admin/includes/class-plugin-upgrader.php

	public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
		global $gc_filesystem;

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

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

		$plugins_dir     = $gc_filesystem->gc_plugins_dir();
		$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );

		if ( ! $gc_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 = $gc_filesystem->delete( $this_plugin_dir, true );
		} else {
			$deleted = $gc_filesystem->delete( $plugins_dir . $plugin );
		}

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

		return true;
	}