WP_REST_Plugins_Controller::handle_plugin_status() WordPress Method

This method is responsible for handling the plugin status. It is called when the user clicks on the "activate" or "deactivate" link for a plugin. If the user does not have the required capability, this method will return an error.

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.


Top ↑

Return

(true|WP_Error)


Top ↑

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
VersionDescription
5.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.