Tạo post type chỉ dùng cho nhóm admin

Cập nhật lần cuối vào

Nếu bạn muốn tạo post type mới bằng hàm register_post_type của WordPress và bạn chỉ muốn nhóm người dùng admin quản lý được các bài viết trong post type này thì bạn làm như sau:

function hocwp_book_setup_post_type() {
	$args = array(
		'public'       => true,
		'label'        => __( 'Books', 'textdomain' ),
		'menu_icon'    => 'dashicons-book',
		'capabilities' => array(
			'edit_post'          => 'update_core',
			'read_post'          => 'update_core',
			'delete_post'        => 'update_core',
			'edit_posts'         => 'update_core',
			'edit_others_posts'  => 'update_core',
			'delete_posts'       => 'update_core',
			'publish_posts'      => 'update_core',
			'read_private_posts' => 'update_core'
		)
	);
	register_post_type( 'book', $args );
}

add_action( 'init', 'hocwp_book_setup_post_type' );

Ngoài ra, bạn cũng có thể tùy chỉnh capability update_core thành các loại khác như: manage_options, activate_plugins,…

Theo dõi
Thông báo của
guest

1 Comment
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất
Phản hồi nội tuyến
Xem tất cả bình luận
Kim Vàng
6 năm trước

DDown giản dễ hiểu và đã làm thành công. Cảm ơn bác nhiều nhé.