WP_REST_Plugins_Controller::handle_plugin_status
Handle updating a plugin's status.
Метод класса: WP_REST_Plugins_Controller{}
Хуков нет.
Возвращает
true|WP_Error.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->handle_plugin_status( $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::handle_plugin_status() WP REST Plugins Controller::handle plugin status WP 6.9.4
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;
}