钩入postbox_classes
. postbox_classes
是将输出元数据库类的函数。
apply_filters( "postbox_classes_{$page}_{$id}", $classes )
您的代码可能如下所示:
add_action( \'add_meta_boxes\', \'add_my_metabox\' );
function add_my_metabox() {
$id = \'my-metabox\';
$title = \'My Metabox\';
$callback = \'my_metabox_content\';
$page = \'post\';
add_meta_box( $id, $title, $callback, $page );
add_filter( "postbox_classes_{$page}_{$id}", \'minify_my_metabox\' );
}
function my_metabox_content() { ... }
/*
* $classes is an array
*/
function minify_my_metabox( $classes ) {
if ( isset( $_POST[\'my_condition\'] ) && \'my_condition\' == $_POST[\'my_condition\'] ) {
array_push( $classes, \'closed\' );
}
return $classes;
}