Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Consolidate editor filters and actions #42356

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,19 @@
"parent": "reference-guides"
},
{
"title": "Filter Reference",
"title": "Hooks Reference",
"slug": "filters",
"markdown_source": "../docs/reference-guides/filters/README.md",
"parent": "reference-guides"
},
{
"title": "Block Filters",
"title": "Block Hooks",
"slug": "block-filters",
"markdown_source": "../docs/reference-guides/filters/block-filters.md",
"parent": "filters"
},
{
"title": "Editor Filters",
"title": "Editor Hooks",
"slug": "editor-filters",
"markdown_source": "../docs/reference-guides/filters/editor-filters.md",
"parent": "filters"
Expand Down
9 changes: 5 additions & 4 deletions docs/reference-guides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
- [Metadata](/docs/reference-guides/block-api/block-metadata.md)
- [Variations](/docs/reference-guides/block-api/block-variations.md)

## [Filter Reference](/docs/reference-guides/filters/README.md)
## [Hooks Reference](/docs/reference-guides/filters/README.md)

- [Block Filters](/docs/reference-guides/filters/block-filters.md)
- [Editor Filters (Experimental)](/docs/reference-guides/filters/editor-filters.md)
- [Parser Filters](/docs/reference-guides/filters/parser-filters.md)
- [Block Hooks](/docs/reference-guides/filters/block-filters.md)
- [Editor Hooks](/docs/reference-guides/filters/editor-filters.md)
- [i18n Hooks](/docs/reference-guides/filters/i18n-filters.md)
gziolo marked this conversation as resolved.
Show resolved Hide resolved
- [Parser Hooks](/docs/reference-guides/filters/parser-filters.md)
- [Autocomplete](/docs/reference-guides/filters/autocomplete-filters.md)

## [SlotFills Reference](/docs/reference-guides/slotfills/README.md)
Expand Down
24 changes: 0 additions & 24 deletions docs/reference-guides/actions/editor-actions.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/reference-guides/filters/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Filter Reference
# Hooks Reference

[Hooks](https://developer.wordpress.org/plugins/hooks/) are a way for one piece of code to interact/modify another piece of code. They provide one way for plugins and themes to interact with the editor, but they’re also used extensively by WordPress Core itself.

Expand Down
16 changes: 6 additions & 10 deletions docs/reference-guides/filters/block-filters.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Block Filters
# Block Hooks

To modify the behavior of existing blocks, WordPress exposes several APIs:
To modify the behavior of existing blocks, WordPress exposes several APIs.

## Registration

Expand Down Expand Up @@ -92,23 +92,19 @@ _Example:_
Wraps a cover block into an outer container.

```js
function wrapCoverBlockInContainer(element, blockType, attributes) {
function wrapCoverBlockInContainer( element, blockType, attributes ) {
// skip if element is undefined
if (!element) {
if ( ! element ) {
return;
}

// only apply to cover blocks
if ( (blockType.name !== 'core/cover') ) {
if ( blockType.name !== 'core/cover' ) {
return element;
}

// return the element wrapped in a div
return (
<div className="cover-block-wrapper">
{ element }
</div>
);
return <div className="cover-block-wrapper">{ element }</div>;
}

wp.hooks.addFilter(
Expand Down
39 changes: 34 additions & 5 deletions docs/reference-guides/filters/editor-filters.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Editor Filters
# Editor Hooks

To modify the behavior of the editor experience, the following Filters are exposed:
To modify the behavior of the editor experience, WordPress exposes several APIs.

## Editor features

The following filters are available to extend the editor features.

### `editor.PostFeaturedImage.imageSize`

Expand Down Expand Up @@ -124,7 +128,32 @@ Default `true`. Indicates whether the user can access the code editor **in addit

If set to false the user will not be able to switch between visual and code editor. The option in the settings menu will not be available and the keyboard shortcut for switching editor types will not fire.

### Block Directory
## Logging errors

gziolo marked this conversation as resolved.
Show resolved Hide resolved
_**Note:** Since WordPress 6.1._

A JavaScript error in a part of the UI shouldn’t break the whole app. To solve this problem for users, React library uses a concept of an [“error boundary”](https://reactjs.org/docs/error-boundaries.html). Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, and display a fallback UI instead of the component tree that crashed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The brief background about Error Boundaries in React really helps give some useful context before hoping into the hook! 👍🏻


### `editor.ErrorBoundary.errorLogged`

Allows you to hook into the [Error Boundaries](https://reactjs.org/docs/error-boundaries.html) and gives you access to the error object.

You can use this action if you want to get hold of the error object that's handled by the boundaries, i.e to send them to an external error tracking tool.

_Example_:

```js
addAction(
'editor.ErrorBoundary.errorLogged',
'mu-plugin/error-capture-setup',
( error ) => {
// error is the exception's error object
ErrorCaptureTool.captureError( error );
}
);
```

## Block Directory

The Block Directory enables installing new block plugins from [WordPress.org.](https://wordpress.org/plugins/browse/block/) It can be disabled by removing the actions that enqueue it. In WordPress core, the function is `wp_enqueue_editor_block_directory_assets`. To remove the feature, use [`remove_action`,](https://developer.wordpress.org/reference/functions/remove_action/) like this:

Expand All @@ -135,9 +164,9 @@ The Block Directory enables installing new block plugins from [WordPress.org.](h
remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );
```

### Block Patterns
## Block Patterns

#### `should_load_remote_block_patterns`
### `should_load_remote_block_patterns`

Default `true`. The filter is checked when registering remote block patterns, set to false to disable.

Expand Down