在WordPress中,如何限制用戶(基於Capabilities)在自定義時間後編輯發佈的帖子。限制用戶根據帖子的年齡來編輯帖子
例如,用戶可以publish_posts
(作者)可以不編輯可以moderate_comments
(編輯)不能編輯是20歲以上的任何職位的職位,如果是年齡超過3天,用戶天。顯然,管理員可以隨時編輯。
這是怎麼回事?
在WordPress中,如何限制用戶(基於Capabilities)在自定義時間後編輯發佈的帖子。限制用戶根據帖子的年齡來編輯帖子
例如,用戶可以publish_posts
(作者)可以不編輯可以moderate_comments
(編輯)不能編輯是20歲以上的任何職位的職位,如果是年齡超過3天,用戶天。顯然,管理員可以隨時編輯。
這是怎麼回事?
這是a question on wordpress.stackexchange.com重複。我在下面複製了我的答案。
I took the example code from the Wordpress user_has_cap filter codex page and modified it. Add this code to your theme functions.php:
function restrict_editing_old_posts($allcaps, $cap, $args) { // Bail out if we're not asking to edit a post ... if('edit_post' != $args[0] // ... or user is admin || ! empty($allcaps['manage_options']) // ... or user already cannot edit the post || empty($allcaps['edit_posts'])) return $allcaps; // Load the post data: $post = get_post($args[2]); // Bail out if the post isn't published: if('publish' != $post->post_status) return $allcaps; $post_date = strtotime($post->post_date); //if post is older than 30 days ... if($post_date < strtotime('-30 days') // ... or if older than 4 days and user is not Editor || (empty($allcaps['moderate_comments']) && $post_date < strtotime('-4 days'))) { $allcaps[$cap[0]] = FALSE; } return $allcaps; } add_filter('user_has_cap', 'restrict_editing_old_posts', 10, 3);
這應該插件
function remove_edit() {
// Adjust 604800 to the number of days in seconds that you want to check against. Posts will only appear if they are newer than that time.//
if (!current_user_can('manage_options') && (current_user_can('edit_posts') && ((current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset') * 3600)) < 604800))
{
unset($actions['edit']);
}
}
add_filter('post_row_actions','remove_edit',10,1);
內工作從WordPress的抄本http://codex.wordpress.org/Roles_and_Capabilities#edit_posts
edit_posts
Since 2.0
Allows access to Administration Panel options:
Posts
Posts > Add New
Comments
Comments > Awaiting Moderation
您能否詳細說明此代碼的工作原理?據我所知,沒有辦法設置哪些用戶適用於?我如何在此添加功能......? –
檢查代碼中的tis函數http://codex.wordpress.org/Function_Reference/current_user_can。 – Udan
您可以在您的代碼示例中添加該功能嗎? –
或者,也可以在自定義時間後鎖定帖子以免編輯。 –
http://copypress.stackexchange.com/questions/69577/restrict-users-from-editing-post-based-on-the-age-of-the-post的副本 – fuxia