我想让编辑在撰写帖子时提交审核。 但是他们也可以发布其他帖子。 我想我应该使用add_filter。但是我不知道该怎么办。 这是我的代码,仅在刷新页面时有效。 非常感谢。
<?php
global $post, $wpdb, $wp_query, $current_user;
$current_user = wp_get_current_user();
$author_id = $post->post_author;
$actual = $current_user->ID;
$user_meta = get_userdata($actual);
$user_roles = $user_meta->roles;
// capabilities to remove from editors
$caps = array(
'publish_posts',
'edit_published_posts'
);
// Get the role object.
$editor = get_role( 'editor' );
if($user_roles[0] == 'editor' AND $author_id == $actual)
{
foreach ( $caps as $cap ) {
// Remove the capability
$editor->remove_cap($cap);
}
}
else if($user_roles[0] == 'editor' AND $author_id !== $actual)
{
foreach ( $caps as $cap ) {
// Add the capability
$editor->add_cap($cap);
}
}
答案 0 :(得分:0)
参考:https://wordpress.stackexchange.com/questions/265656/force-submit-to-review-when-a-post-is-updated
function postPending($post_ID)
{
if(get_role('editor'))
{
//Unhook this function
remove_action('post_updated', 'postPending', 10, 3);
return wp_update_post(array('ID' => $post_ID, 'post_status' => 'pending'));
// re-hook this function
add_action( 'post_updated', 'postPending', 10, 3 );
}
}
add_action('post_updated', 'postPending', 10, 3);