Học PHP cơ bản - Tìm hiểu về mảng trong PHP ( CH001 - Bài 1.1)
Wp hoi-thao-phan-quyen
1. Phân quyền và phân quyền mở rộng trong Worpdress
ww.zend.vn
2. Tự giới thiệu
Họ tên: Phạm Vũ Khánh
Năm sinh: 1978
Kinh nghiệm: Nghiên cứu và làm việc trong lĩnh vực
thiết kế và lập trình Website từ 1999
Các vị trí đã từng đảm nhận: Developer, Designer,
Leader, BA, R&D manager, PM, IT manager…
Công việc hiện tại: CEO & Founder of ZendVN
Điện thoại: 090 889 33 26
Email: vukhanh2212@gmail.com
ww.zend.vn
3. Nội dung trình bày
A. Giới thiệu Roles ( ~ Nhóm người dùng)
B. Giới thiệu Capabilities (~ Quyền hạn)
C. Roles & Capabilities
D. Tạo Custom roles
E. Tạo Custom capabilities
F. Kết hợp Custom roles & Custom capabilities
G. Demo: phân quyền cho Article plugin
ww.zend.vn
5. A. Giới thiệu Roles
1. Super Admin
2. Administrator
3. Editor
4. Author
5. Contributor
6. Subscriber
https://codex.wordpress.org/Roles_and_Capabilities
ww.zend.vn
6. A. Giới thiệu Roles
1. Super Admin:
somebody with access to the site network
administration features and all other features. See
the Create a Network article.
2. Administrator:
somebody who has access to all the administration
features within a single site.
3. Editor (Biên tập viên):
somebody who can publish and manage posts
including the posts of other users.
ww.zend.vn
7. A. Giới thiệu Roles
4. Author (tác giả):
somebody who can publish and manage their own
posts.
5. Contributor (cộng tác viên):
somebody who can write and manage their own
posts but cannot publish them.
6. Subscriber (Người đọc):
somebody who can only manage their profile.
ww.zend.vn
9. B. Giới thiệu Capabilities
1. Super Admin:
manage_network
manage_sites
manage_network_users
manage_network_plugins
manage_network_themes
manage_network_options
ww.zend.vn
10. B. Giới thiệu Capabilities
Để thấy rõ quyền của các nhóm chúng ta có 2 cách:
- https://codex.wordpress.org/Roles_and_Capabilities
- Sử dụng WPFront User Role Editor plugin
ww.zend.vn
13. C. Roles & Capabilities
- Mỗi Role (nhóm) trong WP sẽ được thiết lập một số
quyền (Capability) nhất định
- Để thay đổi quyền hạn của một nhóm nào đó chúng
ta có 2 cách
- Dùng một số plugin hỗ trợ phân quyền
- Viết mã bổ xung trong Custom plugin của chúng ta
ww.zend.vn
14. C. Roles & Capabilities
Những thao tác cơ bản trên WPFront User Role Editor
All Roles
Add New (Role)
Restore
Add/Remove Cap
Settings
ww.zend.vn
15. C.1. Thông tin của User
Lấy thông tin user hiện thời
global $current_user;
$user = $current_user;// Cách 1
$user = wp_get_current_user(); // Cách 2
Lấy thông tin của một user bất kỳ
$user = new WP_User(3);
print_r($user);
ww.zend.vn
16. C.1. Thông tin của User
Cấu trúc đối tượng WP_User
WP_User
(
[data]
[ID]
[caps]
[cap_key]
[roles
[allcaps]
[filter]
)
ww.zend.vn
17. C.2. Thay đổi Role của User
Thêm Role cho user
$user = new WP_User(3); //ID=3 – Editor
$user->add_role( 'subscriber' );
Loại Role của user
$user = new WP_User(3);
$user->remove_role('editor');
ww.zend.vn
18. C.2. Thay đổi Role của User
Thiết lập lại Role cho user
$user = new WP_User(3);
$user->set_role('editor');
19. C.3. Thay đổi quyền hạn cho User
Thêm Cap cho user
$user = new WP_User(3);
$user->add_cap('activate_plugins',true);
Xóa Cap của user
$user = new WP_User(3);
$user->remove_cap('activate_plugins');
20. C.3. Thay đổi quyền hạn cho User
Xóa toàn bộ Cap cho user
$user = new WP_User(3);
$user->remove_all_caps();
Kiểm tra quyền (Cap) của user
$user = new WP_User(3);
if(!$user->has_cap('edit_users')){
echo '<br/>' . 'User này không có edit user';
}
ww.zend.vn
21. C.4. Caps của nhóm (roles)
Lấy thông tin của một nhóm
$role = get_role( 'editor' );
print_r($role);
ww.zend.vn
22. C.4. Caps của nhóm (roles)
Lấy thông tin của một nhóm
WP_Role Object
(
[name] => editor
[capabilities] => Array
(
[moderate_comments] => 1
[manage_categories] => 1
...
)
)
ww.zend.vn
23. C.4. Caps của nhóm (roles)
Thêm quyền cho nhóm
$role = get_role( 'editor' );
$role->add_cap('switch_themes');
$role->add_cap('manage_options');
Xóa quyền của nhóm
$role = get_role( 'editor' );
$role->remove_cap('switch_themes');
$role->remove_cap('manage_options');
ww.zend.vn
25. D. Tạo Custom Roles
Thêm một nhóm mới
add_role( 'zendvn_student',
'Student of ZendVN', array());
Thêm một nhóm mới và sao chép quyền
$role = get_role( 'author' );
$caps = $role->capabilities;
add_role( 'zendvn_student', 'Student of ZendVN',
$caps );
ww.zend.vn