Automattic\WooCommerce\Admin\API

MarketingOverview::activate_plugin()publicWC 1.0

Return installed marketing extensions data.

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

Хуков нет.

Возвращает

\WP_Error|\WP_REST_Response.

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

$MarketingOverview = new MarketingOverview();
$MarketingOverview->activate_plugin( $request );
$request(\WP_REST_Request) (обязательный)
Request data.

Код MarketingOverview::activate_plugin() WC 9.3.3

public function activate_plugin( $request ) {
	$plugin_slug = $request->get_param( 'plugin' );

	if ( ! PluginsHelper::is_plugin_installed( $plugin_slug ) ) {
		return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'Invalid plugin.', 'woocommerce' ), 404 );
	}

	$result = activate_plugin( PluginsHelper::get_plugin_path_from_slug( $plugin_slug ) );

	if ( ! is_null( $result ) ) {
		return new \WP_Error( 'woocommerce_rest_invalid_plugin', __( 'The plugin could not be activated.', 'woocommerce' ), 500 );
	}

	// IMPORTANT - Don't return the active plugins data here.
	// Instead we will get that data in a separate request to ensure they are loaded.
	return rest_ensure_response(
		array(
			'status' => 'success',
		)
	);
}