挂接帖子状态转换,以便在发布或更新帖子时,可以检查作者是否是管理员。如果是,请将作者更新为非管理员。首先,获取要设置为作者的非管理员用户的ID。
// 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));
}
}
}