WordPress at a glance
function is not described

WP_REST_Plugins_Controller::handle_plugin_status() protected WP 5.5.0

Handle updating a plugin's status.

{} It's a method of the class: WP_REST_Plugins_Controller{}

No Hooks.

Return

true/WP_Error.

Usage

// protected - for code of main (parent) or child class
$result = $this->handle_plugin_status( $plugin, $new_status, $current_status );
$plugin(string) (required)
The plugin file to update.
$new_status(string) (required)
The plugin's new status.
$current_status(string) (required)
The plugin's current status.

Changelog

Since 5.5.0 Introduced.

Code of WP_REST_Plugins_Controller::handle_plugin_status() WP 5.5.3

<?php
protected function handle_plugin_status( $plugin, $new_status, $current_status ) {
	if ( 'inactive' === $new_status ) {
		deactivate_plugins( $plugin, false, 'network-active' === $current_status );

		return true;
	}

	if ( 'active' === $new_status && 'network-active' === $current_status ) {
		return true;
	}

	$network_activate = 'network-active' === $new_status;

	if ( is_multisite() && ! $network_activate && is_network_only_plugin( $plugin ) ) {
		return new WP_Error(
			'rest_network_only_plugin',
			__( 'Network only plugin must be network activated.' ),
			array( 'status' => 400 )
		);
	}

	$activated = activate_plugin( $plugin, '', $network_activate );

	if ( is_wp_error( $activated ) ) {
		$activated->add_data( array( 'status' => 500 ) );

		return $activated;
	}

	return true;
}