Force "Submit to review" when a post is updated

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)

Topic review users posts Wordpress

Category Web


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


The user with author role is somebody who can publish and manage their own posts. So you can't change the default capability of your author user to disable publish post. You can set all users (authors) to contributors. Then they can only write posts and manage their posts but not publish them.

For reference : Roles and Capabilities

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.