Wp hoi-thao-phan-quyen
-
Upload
khanhpham -
Category
Technology
-
view
343 -
download
0
Transcript of Wp hoi-thao-phan-quyen
![Page 1: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/1.jpg)
Phân quyền và phân quyền mở rộng trong Worpdress
ww.zend.vn
![Page 2: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/2.jpg)
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: [email protected]
ww.zend.vn
![Page 3: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/3.jpg)
Nội dung trình bàyA. 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
![Page 4: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/4.jpg)
https://codex.wordpress.org/Roles_and_Capabilities
ww.zend.vn
![Page 5: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/5.jpg)
A. Giới thiệu Roles1. Super Admin
2. Administrator
3. Editor
4. Author
5. Contributor
6. Subscriber
https://codex.wordpress.org/Roles_and_Capabilities
ww.zend.vn
![Page 6: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/6.jpg)
A. Giới thiệu Roles1. 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
![Page 7: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/7.jpg)
A. Giới thiệu Roles4. 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
![Page 8: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/8.jpg)
https://codex.wordpress.org/Roles_and_Capabilities
ww.zend.vn
![Page 9: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/9.jpg)
B. Giới thiệu Capabilities1. Super Admin:
manage_network
manage_sites
manage_network_users
manage_network_plugins
manage_network_themes
manage_network_options
ww.zend.vn
![Page 10: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/10.jpg)
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
![Page 11: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/11.jpg)
A. Giới thiệu Capabilities
ww.zend.vn
![Page 12: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/12.jpg)
https://codex.wordpress.org/Roles_and_Capabilities
ww.zend.vn
![Page 13: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/13.jpg)
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
![Page 14: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/14.jpg)
C. Roles & CapabilitiesNhữ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
![Page 15: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/15.jpg)
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
![Page 16: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/16.jpg)
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
![Page 17: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/17.jpg)
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
![Page 18: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/18.jpg)
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');
![Page 19: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/19.jpg)
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');
![Page 20: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/20.jpg)
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
![Page 21: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/21.jpg)
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
![Page 22: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/22.jpg)
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
![Page 23: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/23.jpg)
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
![Page 24: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/24.jpg)
ww.zend.vn
![Page 25: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/25.jpg)
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
![Page 26: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/26.jpg)
ww.zend.vn
![Page 27: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/27.jpg)
E. Tạo Custom Capabilities Thêm Caps cho nhóm có sẵn trong WP
$caps = array(
'zendvn_mp_articles',
'zendvn_mp_article_list',
'zendvn_mp_article_add',
'zendvn_mp_article_edit',
'zendvn_mp_article_delete',
'zendvn_mp_article_status'
);
$role = get_role('administrator');
foreach ($caps as $val){
$role->add_cap($val);
}
ww.zend.vn
![Page 28: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/28.jpg)
ww.zend.vn
![Page 29: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/29.jpg)
F. Custom roles & Custom capabilities
Thêm Role mới và Caps cho nhóm
$caps = array(
'zendvn_mp_articles',
'zendvn_mp_article_list',
'zendvn_mp_article_add',
'zendvn_mp_article_edit',
'zendvn_mp_article_delete',
'zendvn_mp_article_status'
);
add_role( 'zendvn_student',
'Student of ZendVN', array());
ww.zend.vn
![Page 30: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/30.jpg)
ww.zend.vn
![Page 31: Wp hoi-thao-phan-quyen](https://reader033.fdocument.pub/reader033/viewer/2022042818/55ace5921a28ab2b608b45ad/html5/thumbnails/31.jpg)