I think that everything is in the title. I would like to find a way to change the status of a post to “pending” when the post is updated when the user is an “author”. I already tried with differents plugin but none of them worked. I’m new to wordpress so i don’t really understand how am i suppose to modify the code to get this feature.
Thx for your help !
(Sorry for my english)
It is possible to stop author to publish post, and force him to Submit For Preview. Just add this code to your functions.php
and you are all done.
<?php
function take_away_publish_permissions() {
$user = get_role('author');
$user->add_cap('publish_posts',false);
}
add_action('init', 'take_away_publish_permissions' );
?>
** Updated Code **
This code shared here is for setting post status to preview or pending whenever a author update a post.
function postPending($post_ID)
{
if(get_role('author'))
{
//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);
NOTE: If you are calling a function such as wp_update_post that
includes the save_post hook, your hooked function will create an infinite loop. To avoid this, unhook your function before calling the
function you need, then re-hook it afterward. For details look into this link