{"id":93,"date":"2013-11-28T19:00:03","date_gmt":"2013-11-28T19:00:03","guid":{"rendered":"http:\/\/justinandco.com\/justinsblog\/?p=93"},"modified":"2013-11-28T12:37:17","modified_gmt":"2013-11-28T12:37:17","slug":"overwrite-author-name","status":"publish","type":"post","link":"https:\/\/justinandco.com\/justinsblog\/overwrite-author-name\/","title":{"rendered":"Overwrite Author Name"},"content":{"rendered":"<p>Are you currently giving multiple users the same login details?  If &#8216;yes&#8217; then read on&#8230;<\/p>\n<p>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. \u00a0If 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.<\/p>\n<p>So in comes &#8216;<em>Overwrite Author Name<\/em>&#8216; 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. \u00a0The 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. \u00a0It 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 &#8216;<em>Overwrite Author Name<\/em>&#8216; plugin.<\/p>\n<p>Off-course to\u00a0to re-edit the post\/page users will need the &#8216;<strong><em>edit_others_posts<\/em><\/strong>&#8216; or &#8216;<strong><em>edit_others_pages<\/em><\/strong>&#8216; wordpress capability respectively and likewise for any custom post types used.<\/p>\n<p>You could always put something like the following code into your functions.php file..<\/p>\n<pre><code>add_action('save_post', 'overwrite_author_name');\r\n\r\nfunction overwrite_author_name($post_id) {\r\n    \r\n    \/\/this is the user name ID to be enforced.\r\n    $enforced_author = 7797;\r\n    \r\n    \/\/this is the post types to have an enforced user name.\r\n    $author_post_types = array('post', 'page');\r\n    if ($parent_id = wp_is_post_revision($post_id))\r\n        $post_id = $parent_id;\r\n        \r\n    $post = get_post( $post_id );\r\n    if (( $post->post_author != $enforced_author ) && (in_array($post->post_type, $author_post_types))) {\r\n    \r\n        \/\/ unhook this function so it doesn't loop infinitely due to the use of save_post within overwrite_author_name\r\n        remove_action('save_post', 'overwrite_author_name');\r\n        \r\n        \/\/ update the post, which calls save_post again\r\n        wp_update_post(array('ID' => $post_id, 'post_author' => $enforced_author));\r\n        \r\n        \/\/ re-hook this function\r\n        add_action('save_post', 'overwrite_author_name');\r\n}\r\n<\/code><\/pre>\n<p>..but that ties you into the theme, having the plugin allows you to swap themes and not loose the functionality.<\/p>\n<p>I&#8217;ll be releasing to the wordpress plugin repository in the next day or so.<\/p>\n<p><a href=\"https:\/\/github.com\/justinticktock\/overwrite-author-name\" rel=\"nofollow\">GitHub page<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you currently giving multiple users the same login details? If &#8216;yes&#8217; then read on&#8230; 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. \u00a0If you see any of the posts that wordpress.tv make its always &hellip; <a href=\"https:\/\/justinandco.com\/justinsblog\/overwrite-author-name\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Overwrite Author Name&#8221;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[11,13,12],"class_list":["post-93","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-author","tag-plugin-2","tag-user"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/posts\/93","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/comments?post=93"}],"version-history":[{"count":5,"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/posts\/93\/revisions"}],"predecessor-version":[{"id":118,"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/posts\/93\/revisions\/118"}],"wp:attachment":[{"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/media?parent=93"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/categories?post=93"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/justinandco.com\/justinsblog\/wp-json\/wp\/v2\/tags?post=93"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}