我已经知道如何从自定义帖子类型编辑页面中删除元数据库。然而,我想删除评论元框,但仍然允许对帖子发表评论。因为我注意到当我删除它时,它会禁用注释。我可以使用什么功能?
删除评论Metabox,但仍允许评论
5 个回复
最合适的回答,由SO网友:bueltge 整理而成
不要通过CSS删除此内容。\\u POST部分也处于活动状态,WP保存数据!使用挂钩移除金属盒;按草稿编写代码。
function fb_remove_comments_meta_boxes() {
remove_meta_box( \'commentstatusdiv\', \'post\', \'normal\' );
remove_meta_box( \'commentstatusdiv\', \'page\', \'normal\' );
// remove trackbacks
remove_meta_box( \'trackbacksdiv\', \'post\', \'normal\' );
remove_meta_box( \'trackbacksdiv\', \'page\', \'normal\' );
}
add_action( \'admin_init\', \'fb_remove_comments_meta_boxes\' );
有关删除所有UI元素和注释功能的插件的更多信息:https://github.com/bueltge/Remove-Comments-AbsolutelySO网友:Bainternet
您可以使用UI将其删除:
单击编辑屏幕右上方的“屏幕选项”
并取消选中讨论复选框
或者,如果您想通过代码实现,只需隐藏容器div bystyle="display:none;"
function hide_comments_div() {
global $pagenow;
if ($pagenow==\'post-new.php\' OR $pagenow==\'post.php\')
echo \'<style>#commentstatusdiv{ display:none; }</style>\';
}
add_action(\'admin_head\', \'hide_comments_div\');
SO网友:OzzyCzech
文件中有问题/wp-includes/post.php
作用wp_insert_post()
if ( empty($comment_status) ) {
if ( $update )
$comment_status = \'closed\';
else
$comment_status = get_option(\'default_comment_status\');
}
更新后,您的评论将关闭。解决方案是安装commentstatusdiv的更改回调:add_action(
\'add_meta_boxes\', function () {
global $wp_meta_boxes, $current_screen;
$wp_meta_boxes[$current_screen->id][\'normal\'][\'core\'][\'commentstatusdiv\'][\'callback\'] = function () {
global $post;
echo \'<input type="hidden" value="\' . $post->comment_status . \'" name="comment_status"/>\';
echo \'<input type="hidden" value="\' . $post->ping_status . \'" name="ping_status"/>\';
echo \'<style type="text/css">#commentstatusdiv {display: none;}</style>\';
};
}
);
SO网友:Alexey
将此添加到functions.php
你的主题
function tune_admin_area() {
echo \'<style>#commentstatusdiv{ display:none; }</style>\';
}
add_action(\'admin_head\', \'tune_admin_area\');
SO网友:Paul T.
这是我用来隐藏一些元框的内容,包括注释状态框:
if (is_admin()) :
function my_remove_meta_boxes() {
if( !current_user_can(\'manage_options\') ) {
remove_meta_box(\'postcustom\', \'post\', \'normal\');
remove_meta_box(\'trackbacksdiv\', \'post\', \'normal\');
remove_meta_box(\'commentstatusdiv\', \'post\', \'normal\');
remove_meta_box(\'slugdiv\', \'post\', \'normal\');
}
}
add_action( \'admin_menu\', \'my_remove_meta_boxes\' );
function handle_comments_setting( $data ) {
if( !current_user_can(\'manage_options\') ) {
$data[\'comment_status\'] = "open";
}
return $data;
}
add_filter( \'wp_insert_post_data\', \'handle_comments_setting\' );
endif;
这样一来,所有贡献者(而不是管理员)都可以隐藏元框。在第二个函数中comment_status
设置为"open"
仅当满足导致注释首先被禁用的相同条件时。
结束