Hook into a post status transition so that any time a post is published or updated, there’s a check to see if the author is an admin. If so, update the author to a non-admin. First, get the ID of the non-admin user you want to set as the author.
// change author ID to suit your needs
$newAuthor = 3;
// hook our function to fire when any post type's status changes
add_action('transition_post_status', 'wpse_change_author', 10, 3);
function wpse_change_author($new_status, $old_status, $post) {
// only adjust published posts - which are either new or newly updated
if($new_status == 'publish') {
// check whether author is admin
if(user_can($post->post_author, 'administrator')) {
// update the post with new author ID
wp_update_post(array('ID' => $post->ID, 'post_author' => $newAuthor));
}
}
}
Related Posts:
- wp_verify_nonce vs check_admin_referer
- How does admin-ajax.php work?
- Securing Admin Accounts – Username Discovery
- Disable Media Uploads to non Admin Users
- Can I set a default dashboard layout for all users?
- How to let authors revise other authors drafts, but keep them from publishing?
- Is there a way to prevent author change when editor/administrator edits a post?
- Pagination Error on Admin (You do not have sufficient permissions)
- How do I fix “You are not allowed to edit this item.” for Admins on existing posts?
- Page only shows when user is logged in (even with visibility set to public)
- Include admins in author drop-down on edit post screen
- WordPress stripping html and script tags from some admin users on save
- Assuming a theme is properly secured, how save is the WordPress admin?
- Link to post author but exclude administrator (on single.php)
- Showing Post Counts of One’s (Author) Own in the admin post list
- Apply permissions per post
- How do you set up a WordPress blog with multiple authors to allow something like StackExchange’s “community wiki” feature?
- Admin cannot publish
- WordPress ACL (folder + permissions)
- Unable to Access WP Admin or Login buttons after Migration
- using rewrites to secure login page
- How can I merge two authors?
- How do I diagnose a plugin resource 404?
- WordPress Brute Force Prevention
- Changing admin user id for database
- WordPress custom admin functions security
- remove menus for a specific role?
- How to disable Media Library uploads for non-Admin users?
- Does deleting the table users prevent all logins?
- Admin user lacks admin permissions after hack and can’t reinstate
- solution to prevent specific admins from altering site contents
- Wp-Admin FTPS Connection Error unlike Filezilla
- Prevent users in the backend from seeing WP/Plugin notifications and update annoucements?
- Why does my admin email address keep changing to something random?
- Error “Sorry, you are not allowed to access this page”
- Admin Access for specific page(s)
- Where to store publicly-accessible files
- Change the Author name to a custom field?
- My Account Lost Administrator permission
- Unknown phantom user “wordpress” created with admin privileges
- You require permission from “Myself” to delete folder – how to fix
- What are the standard admin CSS id/class tags?
- Admin Ajax is returning 0
- Add custom column to Users admin panel
- Add a Separator to the Admin Menu?
- How to determine whether we are in add New page/post/CPT or in edit page/post/CPT in wordpress admin?
- how to know if admin is in edit page or post [duplicate]
- Modal window from within WordPress admin
- Where in WP can I check history or log of updates of plugins etc?
- Adding a custom admin page
- How to remove entire admin menu?
- How do I remove dashboard access from specific user roles?
- How can I speed up my WP admin section?
- How to pass parameters to admin_notices?
- Admin: very slow edit page caused by core meta query
- if admin is logged in
- Search posts by ID in admin
- What are the recommended database permissions for WordPress?
- How to Change the Default Home Page for the WordPress Dashboard?
- Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
- Find out which moderator approved comment?
- The website cannot display the page
- How To Remove WordPress Version From The Admin Footer
- Sort pages in loop by admin’s page attributes order field?
- Edit “thank you for creating with WordPress” in version 3.3.1
- Hide other users’ posts in admin panel
- Update post counts (published, draft, unattached) in admin interface
- Set Default Admin Colour For All Users
- Editor Styles and Typekit
- WordPress admin stylesheet
- This CSS Stuffing Works, But Is This A Good Practice?
- Is it possible to create a WordPress tour? V3.3.1
- is_admin() returns true when using admin-ajax.php from front end script
- How to save dismissable notice state in WP 4.2?
- How do I optimize a custom post type admin page with 25,000 posts?
- Settings API – adding setting fields dynamically?
- How do I load a CSS style into WordPress admin area only?
- Allowing admin-ajax.php to receive “application/json” instead of “x-www-form-urlencoded”
- Can an admin check passwords of registered users?
- How can I target WordPress 3.8 new interface MP6 with CSS?
- Notification that the admin is online
- Does wordpress create activity, update logs?
- sort child pages on admin
- How-to make the admin area mobile friendly [closed]
- How to remove list view from media library?
- How to disable the “Your site has updated to WordPress x.y.z” admin email?
- Load plugin scripts and styles only on plugin page
- Plugin to remove Admin menu items based on user role?
- How to obtain the user ID of the current profile being edited in WP-Admin?
- 3.3: How do you hide the new dashboard welcome panel?
- Add my own button next to “Screen options” and “Help” in the admin
- WP List Table custom quick edit box – post meta data missing and columns change on submit
- How to hide admin account in BuddyPress? (for security reasons)
- Settings API – easiest way of validating checkboxes?
- Are there any action like ‘init_frontend’
- Should I use is_admin() inside ‘admin_init’ hook callback
- Custom admin email for new user registration
- Send Admin Emails to Multiple Email Addresses
- How do I set up the defualt page icon for admin menu?
- Prevent author from changing their posts if admin has modified