Serialized settings in rest api

JSON Schema

It’s supported if you explicitly register the object JSON schema as:

$args = array(
    'show_in_rest' => array(
        'schema' => array(
            'type'       => 'object',
            'properties' => array(
                'post' => array(
                    'type' => 'string',
                ),
                'blog' => array(
                    'type' => 'string',
                ),
            )
        ),
    ),
);

register_setting( 'default_sidebars', 'default_sidebars', $args );

Resulting in the following object:

default_sidebars: {
  post: "general",
  blog: "sidebar_1"
}

in /wp-json/wp/v2/settings for the serialized option data:

a:2:{s:4:"post";s:7:"general";s:4:"blog";s:9:"sidebar_1";}

See similar object schema support for register_meta() in 5.3:

https://make.wordpress.org/core/2019/10/03/wp-5-3-supports-object-and-array-meta-types-in-the-rest-api/

Leave a Comment