Skip to content

Latest commit

 

History

History
 
 

plugins

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Plugins

Plugins API

The plugins API contains the following methods:

wp.plugins.registerPlugin( name: string, settings: Object )

This method registers a new plugin.

This method takes two arguments:

  1. name: A string identifying the plugin. Must be unique across all registered plugins.
  2. settings: An object containing the following data:
    • render: A component containing the UI elements to be rendered.

See the edit-post module documentation for available components.

Example:

const { Fragment } = wp.element;
const { PluginSidebar, PluginSidebarMoreMenuItem } = wp.editPost;
const { registerPlugin } = wp.plugins;

const Component = () => (
	<Fragment>
		<PluginSidebarMoreMenuItem
			target="sidebar-name"
			icon="smiley"
		>
			My Sidebar
		</PluginSidebarMoreMenuItem>
		<PluginSidebar
			name="sidebar-name"
			title="My Sidebar"
		>
			Content of the sidebar
		</PluginSidebar>
	</Fragment>
);

registerPlugin( 'plugin-name', {
	render: Component,
} );

wp.plugins.unregisterPlugin( name: string )

This method unregisters an existing plugin.

This method takes one argument:

  1. name: A string identifying the plugin.

Example:

const { unregisterPlugin } = wp.plugins;

unregisterPlugin( 'plugin-name' );

Components

PluginArea

A component that renders all registered plugins in a hidden div.

Example:

const { PluginArea } = wp.plugins;

const Layout = () => (
	<div>
		Content of the page
		<PluginArea />
	</div>
);