谁能告诉我如何限制用户只能编辑他的帖子。我使用了角色编辑器插件,但它允许用户编辑所有用户的帖子。我正在创建一个用户可以发布的分类站点插件(自定义帖子类型),他可以编辑他的帖子。
问问题
1852 次
2 回答
0
You can user advanced access manager plugin for same.
于 2013-08-24T10:29:08.347 回答
0
You can limit a user to only edit their own posts using this bit of code.
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' );
Hope this helps you :-)
于 2013-11-21T14:56:38.990 回答