是否有方法为所有用户设置帖子列表中的默认可见列?
如何为所有用户设置帖子列表中的默认可见列
2 个回复
SO网友:Thomas
因为问题是关于列而不是元框的,我需要这个解决方案,Ioannis的回答让我走上了正确的轨道。
有问题的过滤器挂钩是default_hidden_columns
.
这就是我最终得到的解决方案ad_shortcode
默认情况下要隐藏的列。您应该知道这只是默认设置。访问该页面后,将不再使用默认设置。查找包含以下内容的元密钥columnshidden
在里面wp_usermeta
并在测试时将其移除。
add_filter( \'default_hidden_columns\', \'hide_ad_list_columns\', 10, 2 );
function hide_ad_list_columns( $hidden, $screen ) {
// "edit-advanced_ads" needs to be adjusted to your own screen ID, this one is for my "advanced_ads" post type
if( isset( $screen->id ) && \'edit-advanced_ads\' === $screen->id ){
$hidden[] = \'ad_shortcode\';
}
return $hidden;
}
SO网友:JChario
要更改默认值,只需挂接到default\\u hidden\\u meta\\u box过滤器,并提供自己的PHP数组,列出默认情况下想要隐藏的meta box。在下面的示例中,我隐藏了作者元框和修订元框。这样,除非用户决定在屏幕选项中启用它们,否则它们对用户是隐藏的。
<?php
/**
* vpm_default_hidden_meta_boxes
*/
function vpm_default_hidden_meta_boxes( $hidden, $screen ) {
// Grab the current post type
$post_type = $screen->post_type;
// If we\'re on a \'post\'...
if ( $post_type == \'post\' ) {
// Define which meta boxes we wish to hide
$hidden = array(
\'authordiv\',
\'revisionsdiv\',
);
// Pass our new defaults onto WordPress
return $hidden;
}
// If we are not on a \'post\', pass the
// original defaults, as defined by WordPress
return $hidden;
}
add_action( \'default_hidden_meta_boxes\', \'vpm_default_hidden_meta_boxes\', 10, 2 );
还可以看看How to set default screen options?
和https://www.vanpattenmedia.com/2014/code-snippet-hide-post-meta-boxes-wordpress