我相信在remove_post_type_support
你可以做到这一点。但首先,你需要保留一个用户元,其中包含他/她可以编辑的帖子ID列表。您可以通过以下功能实现这一点-
update_user_meta( $user_id, $meta_key, $meta_value, $prev_value )
因此,无论何时加载帖子,您都可以检查他/她可编辑帖子ID的数组,并在此基础上调用或撤销帖子类型支持。查看以下代码-
// Don\'t stick with the `admin_init` hook only. If it doesn\'t work please try with other hooks also
add_action( \'admin_init\', \'codemascot_invoke_or_revoke_post_supports\' );
function codemascot_invoke_or_revoke_post_supports() {
// By setting the last parameter from `false` to `true` you will get return an array.
// Here I\'m using get_current_user_id() to get current logged in user ID.
$editable_posts = get_user_meta( get_current_user_id(), $meta_key, true );
// change the post type support based on your custom user permission
if ( ! in_array( get_the_ID(), $editable_posts ) ) {
remove_post_type_support( \'post\', \'editor\' );
}
}
NB. You can store the user IDs with the permission to edit the post in post meta too. But querying a post meta has some drawbacks as post meta table usually has the higher probability of growth than user meta which may cause slow query.
上述代码块只是一个想法或概念
not tested 在WordPess环境中。因此,一些重要的预防措施是-
不要坚持admin_init
仅挂钩。如果它不工作,请尝试与其他挂钩也让我知道。我会更新我的答案请阅读函数文档以了解有关此处所述函数的更多信息,在将代码投入生产之前测试代码希望我的回答能帮助你。