由于这个答案,我解决了这个问题:Serialized settings in rest api.
我能够将所有选项存储为json对象:
/**
* Create plugin options schema as an object and prepare it for the rest api.
* WP >=5.3
*/
function my_register_settings() {
$general_options = [
\'show_in_rest\' => [
\'schema\' => [
\'type\' => \'object\',
\'properties\' => [
\'is_show_post\' => [
\'type\' => \'string\',
\'default\' => \'true\',
],
\'is_show_page\' => [
\'type\' => \'string\',
\'default\' => \'true\',
],
\'is_show_cpt\' => [
\'type\' => \'string\',
\'default\' => \'\',
],
\'featured_post_id\' => [
\'type\' => \'string\',
\'default\' => \'\',
],
],
],
],
];
// register plugin options as an object
register_setting(
\'awg_settings\',
\'awg_options\',
$general_options
);
}
add_action( \'init\', \'my_register_settings\' );