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

Handle updating a plugin’s status.


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


Top ↑

Return Return

(true|WP_Error)


Top ↑

Source 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;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.