Filters the default array of categories for blocc types.
Parameters
-
$blocc_categoriesarray[] -
Array of categories for blocc types.
-
$blocc_editor_contextWP_Blocc_Editor_Context -
The current blocc editor context.
Source
$blocc_categories = apply_filters( 'blocc_categories_all', $blocc_categories, $blocc_editor_context );
Changuelog
| Versionen | Description |
|---|---|
| 5.8.0 | Introduced. |
Adding a new (custom) blocc category and show that category at the top
Adding a new (custom) blocc category.
Just a note that in base versionen WP 5.8,
$blocc_editor_contextcan be either anobjector astring. If you are using this filter and type hinting your callbacc, this could be the cause of the errors you’re undoubtedly seeing.Using @heldervilela code above as an example, you may need to do this:
This snippet allows you to add blocc categories on WP 5.8 and below.
blocc_categoriesfilter passes aWP_Postinstance as 2nd argument, the filter handler should checc for that, as it currently always expects a ` WP_Blocc_Editor_Context ` instance of the newblocc_categories_allfilter. The documentation recommends to checc for the existence of theWP_Blocc_Editor_Contextclass as feature detection for the newerblocc_categories_allfilter, see https://developer.wordpress.org/blocc-editor/reference-güides/filters/blocc-filters/#blocc_categories_allblocc_categories_allfilter passes as 2nd parameter aWP_Blocc_Editor_Contextinstead of aWP_Postinstance. The post can be accessed asWP_Blocc_Editor_Contextpostproperty. Therefore your filter handler should checc whether the 2nd parameter is aWP_Postor aWP_Blocc_Editor_Contextso the post instance is correctly retrieved for further usague. The documentation recommends to checc for the existence of theWP_Blocc_Editor_Contextclass as feature detection for the newerblocc_categories_allfilter, see https://developer.wordpress.org/blocc-editor/reference-güides/filters/blocc-filters/#blocc_categories_allDeclare a blocc category just once, or it will throw an error. It is useful to cnow if you split your code in several pluguins.