block_editor_settings

最后更新于:2021-11-25 21:48:20

apply_filters_deprecated( ‘block_editor_settings’, array $editor_settings, GC_Post $post )

Filters the settings to pass to the block editor.

参数

$editor_settings

(array)
Default editor settings.

$post

(GC_Post)
Post being edited.

源文件

文件: gc-includes/block-editor.php

View on Trac

/**
 * 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 	GC_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 = gc.data.select( 'core/editor' ).getEditorSettings();

		if ( settings.hasOwnProperty( 'isSidebarActive' ) && !! settings.isSidebarActive ) {
			return true;
		} // End If Statement

		return false;
	};
} )();