正如@rarst所言,设置全局$wp_meta_boxes 到空数组可以是一种解决方案。
关于定时问题,重置变量的最佳位置是在使用变量之前。元数据库通过以下方式打印:do_meta_boxes() 函数中没有挂钩,但它包含
get_user_option( "meta-box-order_$page" )
 以及
get_user_option() 启动过滤器
\'get_user_option_{$option}\' 所以你可以用它来进行清洁。
类似这样:
function remove_all_metaboxes($type) {
  add_filter("get_user_option_meta-box-order_{$type}", function() use($type) {
      global $wp_meta_boxes;
      $wp_meta_boxes[$type] = array();
      return array();
  }, PHP_INT_MAX);
}
 然而,定时问题并不是唯一的问题。
另一个问题是,如果$wp_meta_boxes 到空数组all 删除了元框,甚至是核心元框,例如用于保存帖子的框。
因此,解决方案不是将其设置为空数组,而是设置为包含要保留的框的数组。
E、 g.要仅保留带有“发布”按钮的框,请使用:
function remove_all_metaboxes($type) {
  add_filter("get_user_option_meta-box-order_{$type}", function() use($type) {
      global $wp_meta_boxes;
      $publishbox = $wp_meta_boxes[$type][\'side\'][\'core\'][\'submitdiv\'];
      $wp_meta_boxes[$type] = array(
        \'side\' => array(\'core\' => array(\'submitdiv\' => $publishbox))
      );
      return array();
  }, PHP_INT_MAX);
} 
add_action(\'admin_init\', function() {
  // replace with the slug of the post type you want to target
  remove_all_metaboxes(\'post\'); 
});