Overwrite Author Name

Are you currently giving multiple users the same login details? If ‘yes’ then read on…

I came across the need to create a consistent author name across a site, very much like how wordpress.tv seems to be, looking from the public front end.  If you see any of the posts that wordpress.tv make its always the same author name even though all the content is obviously being provided by many different users/authors.

So in comes ‘Overwrite Author Name‘ to do a similar job for any of your sites which has multiple authors providing content but you want to have a clean authorship used across the site.  The obvious workround for this would be to give all the users (for example office staff) the same username and password details, but this is very inflexible and weakens site security.  It would be much better to allow all users to login to the site with their own access rights and capabilities and automatically change the name of the author at the time of post save and this is the reason I created the ‘Overwrite Author Name‘ plugin.

Off-course to to re-edit the post/page users will need the ‘edit_others_posts‘ or ‘edit_others_pages‘ wordpress capability respectively and likewise for any custom post types used.

You could always put something like the following code into your functions.php file..

add_action('save_post', 'overwrite_author_name');

function overwrite_author_name($post_id) {
    
    //this is the user name ID to be enforced.
    $enforced_author = 7797;
    
    //this is the post types to have an enforced user name.
    $author_post_types = array('post', 'page');
    if ($parent_id = wp_is_post_revision($post_id))
        $post_id = $parent_id;
        
    $post = get_post( $post_id );
    if (( $post->post_author != $enforced_author ) && (in_array($post->post_type, $author_post_types))) {
    
        // unhook this function so it doesn't loop infinitely due to the use of save_post within overwrite_author_name
        remove_action('save_post', 'overwrite_author_name');
        
        // update the post, which calls save_post again
        wp_update_post(array('ID' => $post_id, 'post_author' => $enforced_author));
        
        // re-hook this function
        add_action('save_post', 'overwrite_author_name');
}

..but that ties you into the theme, having the plugin allows you to swap themes and not loose the functionality.

I’ll be releasing to the wordpress plugin repository in the next day or so.

GitHub page.