On this page
get_block_categories( WP_Post|WP_Block_Editor_Context $post_or_block_editor_context ): array[]
Returns all the categories for block types that will be shown in the block editor.
Parameters
$post_or_block_editor_contextWP_Post|WP_Block_Editor_Context Required-
The current post object or the block editor context.
Return
array[] Array of categories for block types.
Source
File: wp-includes/block-editor.php. View all references
function get_block_categories( $post_or_block_editor_context ) {
$block_categories = get_default_block_categories();
$block_editor_context = $post_or_block_editor_context instanceof WP_Post ?
new WP_Block_Editor_Context(
array(
'post' => $post_or_block_editor_context,
)
) : $post_or_block_editor_context;
/**
* Filters the default array of categories for block types.
*
* @since 5.8.0
*
* @param array[] $block_categories Array of categories for block types.
* @param WP_Block_Editor_Context $block_editor_context The current block editor context.
*/
$block_categories = apply_filters( 'block_categories_all', $block_categories, $block_editor_context );
if ( ! empty( $block_editor_context->post ) ) {
$post = $block_editor_context->post;
/**
* Filters the default array of categories for block types.
*
* @since 5.0.0
* @deprecated 5.8.0 Use the {@see 'block_categories_all'} filter instead.
*
* @param array[] $block_categories Array of categories for block types.
* @param WP_Post $post Post being loaded.
*/
$block_categories = apply_filters_deprecated( 'block_categories', array( $block_categories, $post ), '5.8.0', 'block_categories_all' );
}
return $block_categories;
}
Hooks
- apply_filters_deprecated( 'block_categories',
array[] $block_categories ,WP_Post $post ) -
Filters the default array of categories for block types.
- apply_filters( 'block_categories_all',
array[] $block_categories ,WP_Block_Editor_Context $block_editor_context ) -
Filters the default array of categories for block types.
Related
Uses
| Uses | Description |
|---|---|
| WP_Block_Editor_Context::__construct() wp-includes/class-wp-block-editor-context.php | Constructor. |
| get_default_block_categories() wp-includes/block-editor.php | Returns the list of default categories for block types. |
| apply_filters_deprecated() wp-includes/plugin.php | Fires functions attached to a deprecated filter hook. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| get_block_editor_settings() wp-includes/block-editor.php | Returns the contextualized block editor settings for a selected editor context. |
| WP_Customize_Widgets::enqueue_scripts() wp-includes/class-wp-customize-widgets.php | Enqueues scripts and styles for Customizer panel and export data to JavaScript. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_block_categories