WP_REST_Plugins_Controller::plugin_status_permission_check()protectedWP 5.5.0

Handle updating a plugin's status.

Метод класса: WP_REST_Plugins_Controller{}

Хуков нет.

Возвращает

true|WP_Error.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->plugin_status_permission_check( $plugin, $new_status, $current_status );
$plugin(строка) (обязательный)
The plugin file to update.
$new_status(строка) (обязательный)
The plugin's new status.
$current_status(строка) (обязательный)
The plugin's current status.

Список изменений

С версии 5.5.0 Введена.

Код WP_REST_Plugins_Controller::plugin_status_permission_check() WP 6.5.2

protected function plugin_status_permission_check( $plugin, $new_status, $current_status ) {
	if ( is_multisite() && ( 'network-active' === $current_status || 'network-active' === $new_status ) && ! current_user_can( 'manage_network_plugins' ) ) {
		return new WP_Error(
			'rest_cannot_manage_network_plugins',
			__( 'Sorry, you are not allowed to manage network plugins.' ),
			array( 'status' => rest_authorization_required_code() )
		);
	}

	if ( ( 'active' === $new_status || 'network-active' === $new_status ) && ! current_user_can( 'activate_plugin', $plugin ) ) {
		return new WP_Error(
			'rest_cannot_activate_plugin',
			__( 'Sorry, you are not allowed to activate this plugin.' ),
			array( 'status' => rest_authorization_required_code() )
		);
	}

	if ( 'inactive' === $new_status && ! current_user_can( 'deactivate_plugin', $plugin ) ) {
		return new WP_Error(
			'rest_cannot_deactivate_plugin',
			__( 'Sorry, you are not allowed to deactivate this plugin.' ),
			array( 'status' => rest_authorization_required_code() )
		);
	}

	return true;
}