Set a User as Author of all ‘New Posts’ posted

An Author ‘XYZ’ is need to be set as the Default author of all New Posts. Irrespective of the actual Author posting the content, the post should be saved by this author ‘XYZ’.

Is there a Plugin or custom functions, which serves this purpose?

Read More

Note : The existing posts should stay as it is, no 'change of author' for old posts, only new one should be effected.

Related posts

Leave a Reply

1 comment

  1. function wp84782_replace_author( $post_ID )  
    {
      $my_post = array();
      $my_post['ID'] = $post_ID;
      $my_post['post_author'] = 1 ; //This is the ID number of whatever author you want to assign
    
    // Update the post into the database
      wp_update_post( $my_post );
    }
    add_action( 'publish_post', 'wp84782_replace_author' );
    

    Update:
    This hook runs as the post is being published, not after, so the command is trying to overwrite what the system is doing at the same time. So here’s a modified version that cancels all of this is the post was previously published. If you’re wanting it to never allow user’s to update the author, perhaps you could hide that meta field. I’m not aware of a hook that runs immediately after publish of a post, but if there were one, hooking into it would allow solve this problem.

    function wp84782_replace_author( $post_ID )  
    {
        if(get_post_status( $post_ID ) == 'publish'){
            return;
        }
        else {
            $my_post = array();
            $my_post['ID'] = $post_ID;
            $my_post['post_author'] = 1 ; //This is the ID number of whatever author you want to assign
    
            // Update the post into the database
            wp_update_post( $my_post );
        }
    }
    add_action( 'publish_post', 'wp84782_replace_author' );
    

    Disclaimer: All this code is not tested, so there may be minor edits needed.