Hàm lưu tự động lại tất cả bài viết theo post type tùy chỉnh
21/11/2024
27/05/2024 - 174
// thêm quyền chờ duyệt cho vai trò tác giả
function set_author_post_status_pending($data, $postarr)
{
if(isset($data['post_type']) && $data['post_type'] === 'post' && isset($postarr['post_author'])) {
$author = get_userdata($postarr['post_author']);
$allowed_roles = array('author'); // Các vai trò tác giả có thể thay đổi
if(array_intersect($allowed_roles, $author->roles)) {
$data['post_status'] = 'pending';
}
}
return $data;
}
add_filter('wp_insert_post_data', 'set_author_post_status_pending', 10, 2);
Bạn có thể thêm đoạn mã sau vào file functions.php của theme WordPress