W3cubDocs

/WordPress

WP_REST_Plugins_Controller::handle_plugin_status( string $plugin, string $new_status, string $current_status )

Handle updating a plugin’s status.

Parameters

$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.

Return

(true|WP_Error)

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.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;
	}

Changelog

Version Description
5.5.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_plugins_controller/handle_plugin_status