如何限制wordpress中的用户

如何限制wordpress中的用户,wordpress,custom-post-type,Wordpress,Custom Post Type,有谁能告诉我如何限制用户只编辑他的帖子。我使用了角色编辑器插件,但它允许用户编辑所有用户的帖子。我正在创建一个分类网站插件,用户可以在其中发布帖子(自定义帖子类型)他可以编辑自己的帖子。你也可以使用插件。你可以限制用户只使用这段代码编辑自己的帖子 function my_authored_content($query) { //get current user info to see if they are allowed to access ANY posts and pages $curr

有谁能告诉我如何限制用户只编辑他的帖子。我使用了角色编辑器插件,但它允许用户编辑所有用户的帖子。我正在创建一个分类网站插件,用户可以在其中发布帖子(自定义帖子类型)他可以编辑自己的帖子。

你也可以使用插件。

你可以限制用户只使用这段代码编辑自己的帖子

function my_authored_content($query) {

//get current user info to see if they are allowed to access ANY posts and pages
$current_user = wp_get_current_user();
// set current user to $is_user
$is_user = $current_user->user_login;

//if is admin or 'is_user' does not equal #username
if (!current_user_can('manage_options')){
    //if in the admin panel
    if($query->is_admin) {

        global $user_ID;
        $query->set('author',  $user_ID);

    }
    return $query;
}
return $query;
}
add_filter('pre_get_posts', 'my_authored_content');

function remove_menu_items() {
$current_user = wp_get_current_user();
if ( !current_user_can( 'manage_options' ) ) {
    //hides comments menu
    remove_menu_page( 'edit-comments.php' );
    // hides posts menu
    remove_menu_page( 'edit.php' );
    hides pages menu
    remove_menu_page( 'edit.php?post_type=page' );
}
}
add_action( 'admin_menu', 'remove_menu_items' );

希望这对您有所帮助:-)

角色编辑器插件可以工作,您不能在用户管理页面中将用户角色设置为作者吗?根据抄本上的那一页,它可以做你想做的。@Hobo我已经试过了,但是运气不好,你能给我举个例子吗please@JothiKannan尝试过,但用户可以编辑每个人的帖子。我只希望他只编辑自己的帖子。您必须设置
作者
角色,用户才能发布帖子并管理自己的帖子