Support » Plugins » Hacks » Changing post status with pre_post_update hook

  • I’m trying to conditionally change the post status with this code:

    // if contributor edits published post, change the status to pending
    function contributor_status_to_pending($post_id) {
          $post = get_post($post_id);
          if ($post->post_status == 'publish') {
                $post->post_status = 'pending';
    if ( current_user_can('contributor')  )

    Through debugging, I can see that the function fires for a contributor, that execution gets inside the if, and that $post->post_status is set to ‘pending’.

    But the post remains ‘publish’.

    Any help would be appreciated

Viewing 1 replies (of 1 total)
  • I should add that a previous hook was implemented that allowed a contributor to edit a published post, like so:

    / contributor can edit published posts (but leaves published, want to set to pending)
    function allow_contributor_edit_published_posts() {
    	$contributor = get_role('contributor');
    if ( current_user_can('contributor') && !current_user_can('edit_published_posts') )
    	add_action('admin_init', 'allow_contributor_edit_published_posts');

    This code comes before the other hook.

Viewing 1 replies (of 1 total)
  • The topic ‘Changing post status with pre_post_update hook’ is closed to new replies.