Editor Filters Edit

To modify the behavior of the editor experience, the following Filters are exposed:

editor.PostFeaturedImage.imageSize editor.PostFeaturedImage.imageSize

Used to modify the image size displayed in the Post Featured Image component. It defaults to 'post-thumbnail', and will fail back to the full image size when the specified image size doesn’t exist in the media object. It’s modeled after the admin_post_thumbnail_size filter in the classic editor.

Example:

var withImageSize = function ( size, mediaId, postId ) {
    return 'large';
};

wp.hooks.addFilter(
    'editor.PostFeaturedImage.imageSize',
    'my-plugin/with-image-size',
    withImageSize
);

Top ↑

editor.PostPreview.interstitialMarkup editor.PostPreview.interstitialMarkup

Filters the interstitial message shown when generating previews.

Example:

var customPreviewMessage = function () {
    return '<b>Post preview is being generated!</b>';
};

wp.hooks.addFilter(
    'editor.PostPreview.interstitialMarkup',
    'my-plugin/custom-preview-message',
    customPreviewMessage
);

Top ↑

media.crossOrigin media.crossOrigin

Used to set or modify the crossOrigin attribute for foreign-origin media elements (i.e <img>, <audio> , <img> , <link> , <script>, <video>). See this article for more information the crossOrigin attribute, its values and how it applies to each element.

One example of it in action is in the Image block’s transform feature to allow cross-origin images to be used in a <canvas>.

Example:

addFilter(
    'media.crossOrigin',
    'my-plugin/with-cors-media',
    // The callback accepts a second `mediaSrc` argument which references
    // the url to actual foreign media, useful if you want to decide
    // the value of crossOrigin based upon it.
    ( crossOrigin, mediaSrc ) => {
        if ( mediaSrc.startsWith( 'https://example.com' ) ) {
            return 'use-credentials';
        }
        return crossOrigin;
    }
);

Editor settings Editor settings

Top ↑

block_editor_settings_all block_editor_settings_all

Note: Before WordPress 5.8 known as block_editor_settings. In the case when you want to support older versions of WordPress you might need a way to detect which filter should be used – the deprecated one vs the new one. The recommended way to proceed is to check if the WP_Block_Editor_Context class exists.

This is a PHP filter which is applied before sending settings to the WordPress block editor.

You may find details about this filter on its WordPress Code Reference page.

The filter will send any setting to the initialized Editor, which means any editor setting that is used to configure the editor at initialiation can be filtered by a PHP WordPress plugin before being sent.

Example:

<?php
// my-plugin.php

function filter_block_editor_settings_when_post_provided( $editor_settings, $editor_context ) {
    if ( ! empty( $editor_context->post ) ) {
        $editor_settings['maxUploadFileSize'] = 12345;
    }
    return $editor_settings;
}

add_filter( 'block_editor_settings_all', 'filter_block_editor_settings_when_post_provided', 10, 2 );

block_editor_rest_api_preload_paths block_editor_rest_api_preload_paths

Filters the array of REST API paths that will be used to preloaded common data to use with the block editor.

Example:

<?php
// my-plugin.php

function filter_block_editor_rest_api_preload_paths_when_post_provided( $preload_paths, $editor_context ) {
    if ( ! empty( $editor_context->post ) ) {
        array_push( $preload_paths, array( '/wp/v2/blocks', 'OPTIONS' ) );
    }
    return $preload_paths;
}

add_filter( 'block_editor_rest_api_preload_paths', 'filter_block_editor_rest_api_preload_paths_when_post_provided', 10, 2 );

Top ↑

Available default editor settings Available default editor settings

Top ↑

richEditingEnabled richEditingEnabled

If it is true the user can edit the content using the visual editor.

It is set by default to the return value of the user_can_richedit function. It checks if the user can access the visual editor and whether it’s supported by the user’s browser.

Top ↑

codeEditingEnabled codeEditingEnabled

Default true. Indicates whether the user can access the code editor in addition to the visual editor.

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.

Top ↑

Block Directory Block Directory

The Block Directory enables installing new block plugins from WordPress.org. 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, like this:

<?php
// my-plugin.php

remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );