我终于弄明白了。自定义元框和字段插件有一个清理设置,您可以在其中添加自己的清理功能或使用默认wordpress清理功能之一。在我的例子中,Wordpress已经有了一个清理功能,它可以完全满足我的需要。请参见下面的代码,特别是行“\'sanitization\\u cb\'=>\'sanitize\\u html\\u class\'”
array(
\'name\' => __( \'Custom Body Class\', \'cmb\' ),
\'id\' => $prefix . \'wnd_bodyclass\',
\'type\' => \'text_medium\',
\'sanitization_cb\' => \'sanitize_html_class\', // custom sanitization callback. see this page for details: https://codex.wordpress.org/Function_Reference/sanitize_text_field
),
array(
\'name\' => __( \'Custom Post Class\', \'cmb\' ),
\'id\' => $prefix . \'wnd_postclass\',
\'type\' => \'text_medium\',
),