apply_filters( 'block_editor_settings', array $editor_settings, WP_Post $post )

Filters the settings to pass to the block editor.


Description Description


Parameters Parameters

$editor_settings

(array) Default editor settings.

$post

(WP_Post) Post being edited.


Top ↑

Source Source

File: wp-admin/edit-form-blocks.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Mahdi Yazdani
    /**
     * Adds a custom parameter to the editor settings that is used
     * to track whether the main sidebar has widgets.
     *
     * @param 	array   	$settings 	Default editor settings.
     * @param 	WP_Post 	$post 		Post being edited.
     * @return 	array 		$settings 	Filtered block editor settings.
     */
    function prefix_custom_editor_settings( $settings, $post ) {
    	$settings['isSidebarActive'] = FALSE;
    	
    	// Determines whether a sidebar is in use.
    	if ( is_active_sidebar( 'sidebar-1' ) ) {
    		$settings['isSidebarActive'] = TRUE;
    	} // End If Statement
    	
    	return $settings;
    }
    add_filter( 'block_editor_settings', 'prefix_custom_editor_settings', 10, 2 );
    
    ( function() {
    	/**
    	 * Check if the main sidebar is active (has widgets).
    	 *
    	 * This uses a custom property `isSidebarActive` added via the
    	 * `block_editor_settings` filter.
    	 *
    	 * @return 	{boolean} 	Whether sidebar is active.
    	 */
    	const sidebarIsActive = () => {
    		let settings = wp.data.select( 'core/editor' ).getEditorSettings();
    
    		if ( settings.hasOwnProperty( 'isSidebarActive' ) && !! settings.isSidebarActive ) {
    			return true;
    		} // End If Statement
    
    		return false;
    	};
    } )();
    

You must log in before being able to contribute a note or feedback.