get_block_categories

The timeline below displays how wordpress function get_block_categories has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.8

/**
 * Returns all the categories for block types that will be shown in the block editor.
 *
 * @since 5.0.0
 * @since 5.8.0 It is possible to pass the block editor context as param.
 *
 * @param WP_Post|WP_Block_Editor_Context $post_or_block_editor_context The current post object or
 *                                                                      the block editor context.
 *
 * @return array[] Array of categories for block types.
 */
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;
}

WordPress Version: 5.6

/**
 * Returns all the block categories that will be shown in the block editor.
 *
 * @since 5.0.0
 *
 * @param WP_Post $post Post object.
 * @return array[] Array of block categories.
 */
function get_block_categories($post)
{
    $default_categories = array(array('slug' => 'text', 'title' => _x('Text', 'block category'), 'icon' => null), array('slug' => 'media', 'title' => _x('Media', 'block category'), 'icon' => null), array('slug' => 'design', 'title' => _x('Design', 'block category'), 'icon' => null), array('slug' => 'widgets', 'title' => _x('Widgets', 'block category'), 'icon' => null), array('slug' => 'embed', 'title' => _x('Embeds', 'block category'), 'icon' => null), array('slug' => 'reusable', 'title' => _x('Reusable Blocks', 'block category'), 'icon' => null));
    /**
     * Filters the default array of block categories.
     *
     * @since 5.0.0
     *
     * @param array[] $default_categories Array of block categories.
     * @param WP_Post $post               Post being loaded.
     */
    return apply_filters('block_categories', $default_categories, $post);
}

WordPress Version: 5.5

/**
 * Returns all the block categories that will be shown in the block editor.
 *
 * @since 5.0.0
 *
 * @param WP_Post $post Post object.
 * @return array[] Array of block categories.
 */
function get_block_categories($post)
{
    $default_categories = array(array('slug' => 'text', 'title' => _x('Text', 'block category'), 'icon' => null), array('slug' => 'media', 'title' => _x('Media', 'block category'), 'icon' => null), array('slug' => 'design', 'title' => _x('Design', 'block category'), 'icon' => null), array('slug' => 'widgets', 'title' => _x('Widgets', 'block category'), 'icon' => null), array('slug' => 'embed', 'title' => _x('Embeds', 'block category'), 'icon' => null), array('slug' => 'reusable', 'title' => _x('Reusable Blocks', 'block category'), 'icon' => null));
    /**
     * Filter the default array of block categories.
     *
     * @since 5.0.0
     *
     * @param array[] $default_categories Array of block categories.
     * @param WP_Post $post               Post being loaded.
     */
    return apply_filters('block_categories', $default_categories, $post);
}

WordPress Version: 5.4

/**
 * Returns all the block categories that will be shown in the block editor.
 *
 * @since 5.0.0
 *
 * @param WP_Post $post Post object.
 * @return array[] Array of block categories.
 */
function get_block_categories($post)
{
    $default_categories = array(array('slug' => 'common', 'title' => __('Common Blocks'), 'icon' => null), array('slug' => 'formatting', 'title' => __('Formatting'), 'icon' => null), array('slug' => 'layout', 'title' => __('Layout Elements'), 'icon' => null), array('slug' => 'widgets', 'title' => __('Widgets'), 'icon' => null), array('slug' => 'embed', 'title' => __('Embeds'), 'icon' => null), array('slug' => 'reusable', 'title' => __('Reusable Blocks'), 'icon' => null));
    /**
     * Filter the default array of block categories.
     *
     * @since 5.0.0
     *
     * @param array[] $default_categories Array of block categories.
     * @param WP_Post $post               Post being loaded.
     */
    return apply_filters('block_categories', $default_categories, $post);
}

WordPress Version: 5.0

/**
 * Returns all the block categories that will be shown in the block editor.
 *
 * @since 5.0.0
 *
 * @param WP_Post $post Post object.
 * @return array Array of block categories.
 */
function get_block_categories($post)
{
    $default_categories = array(array('slug' => 'common', 'title' => __('Common Blocks'), 'icon' => null), array('slug' => 'formatting', 'title' => __('Formatting'), 'icon' => null), array('slug' => 'layout', 'title' => __('Layout Elements'), 'icon' => null), array('slug' => 'widgets', 'title' => __('Widgets'), 'icon' => null), array('slug' => 'embed', 'title' => __('Embeds'), 'icon' => null), array('slug' => 'reusable', 'title' => __('Reusable Blocks'), 'icon' => null));
    /**
     * Filter the default array of block categories.
     *
     * @since 5.0.0
     *
     * @param array   $default_categories Array of block categories.
     * @param WP_Post $post               Post being loaded.
     */
    return apply_filters('block_categories', $default_categories, $post);
}