Meta Registration
Post meta registration is required for any post meta key/value pairs to be available to the Gutenberg Block editor. Rather than defining the register_meta parameters for every post meta to register, we are defining a shorthand and using helpers to quickly register 'post', 'comment', 'term', 'user', or any other object type meta associated with those meta tables.
How to Register Meta
In each src/blocks/block_name, src/slotfills/slotfill_name, src/sidebars/sidebar_name, or src/filters/filter_name directories you may add a meta.json file which gets read and registered when the block, slotfill, sidebar, or filter gets registered.
The json file expects post meta registration in this format:
{
"post_meta_key": {
"object_type": "post", // Default "post". The Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', or any other object type with an associated meta table.
"default": 0, // Should match the type.
"brand": [ "thr", "wwd" ], // Only register for these brands, defined by PMC_SITE_NAME.
"exclude_brand": [ "variety" ], // Exclude meta registration for these brands.
"post_types": [ "post", "page" ], // Default, if no post type array is defined, assume "all".
"type": "integer", // Default, string.
"schema": [ ... ]
}
}Any of the register_meta $args (opens in a new tab) parameters are supported.
Defining an auth_callback or sanitize_callback would require the we ensure that namespaced functions are provided and properly escaped. Core functions do not require namespace. For example:
{
"$schema": "../../../src/config/schema/meta.json",
"post_meta_key": {
"auth_callback": "Variety\\Namespace\\function_name",
"sanitize_callback": "wp_kses_post",
}
}The exclude_brand arg can be used to define brands that we don't want to register meta to. Similar to the brand arg which would assign only to those brands, exclude_brand excludes.
Registration defaults
[
'object_subtype' => '',
'type' => 'string',
'description' => '',
'default' => '',
'single' => true,
'sanitize_callback' => null,
'auth_callback' => null,
'show_in_rest' => true,
]If the "brand" arg is not defined, all JSON is loaded regardless of brand for the defined object_subtypes or for all post types if object_subtypes is omitted.