# PluginInterface

interface

The base interface for CKEditor plugins.

In its minimal form a plugin can be a simple function that accepts [the editor](module_core_editor_editor-Editor.md) as a parameter:

```typescript
// A simple plugin that enables a data processor.
function MyPlugin( editor ) {
	editor.data.processor = new MyDataProcessor();
}
```

In most cases however, you will want to inherit from the [`Plugin`](module_core_plugin-Plugin.md) class which implements the [`Observable`](module_utils_observablemixin-Observable.md) and is, therefore, more convenient:

```typescript
class MyPlugin extends Plugin {
	init() {
		// `listenTo()` and `editor` are available thanks to `Plugin`.
		// By using `listenTo()` you will ensure that the listener is removed when
		// the plugin is destroyed.
		this.listenTo( this.editor.data, 'ready', () => {
			// Do something when the data is ready.
		} );
	}
}
```

The plugin class can have `pluginName` and `requires` static members. See [`PluginStaticMembers`](module_core_plugin-PluginStaticMembers.md) for more details.

The plugin can also implement methods (e.g. [`init()`](#function-init) or [`destroy()`](#function-destroy)) which, when present, will be used to properly initialize and destroy the plugin.

**Note:** When defined as a plain function, the plugin acts as a constructor and will be called in parallel with other plugins' [constructors](module_core_plugin-PluginConstructor.md). This means the code of that plugin will be executed **before** [`init()`](#function-init) and [`afterInit()`](#function-afterInit) methods of other plugins and, for instance, you cannot use it to extend other plugins' [schema](../framework/architecture/editing-engine.md#schema) rules as they are defined later on during the `init()` stage.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugin.ts#L207)

<a id="methods">

## Methods

<a id="function-afterInit">

### `afterInit() → void | Promise<unknown> | null | undefined`

The third (and last) stage of the plugin initialization. See also [`PluginConstructor`](module_core_plugin-PluginConstructor.md) and [`init`](#function-init).

**Note:** This method is optional. A plugin instance does not need to have it defined.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugin.ts#L225)

#### Returns

* `void | Promise<unknown> | null | undefined`

<a id="function-destroy">

### `destroy() → void | Promise<unknown> | null | undefined`

Destroys the plugin.

**Note:** This method is optional. A plugin instance does not need to have it defined.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugin.ts#L232)

#### Returns

* `void | Promise<unknown> | null | undefined`

<a id="function-init">

### `init() → void | Promise<unknown> | null | undefined`

The second stage (after plugin constructor) of the plugin initialization. Unlike the plugin constructor this method can be asynchronous.

A plugin's `init()` method is called after its [dependencies](module_core_plugin-PluginStaticMembers.md#member-requires) are initialized, so in the same order as the constructors of these plugins.

**Note:** This method is optional. A plugin instance does not need to have it defined.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-core/src/plugin.ts#L218)

#### Returns

* `void | Promise<unknown> | null | undefined`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
