行政编辑可以fix the author manually.
或者,您可以添加自定义post元数据来指定原始作者。然后,钩住publish_post
or transition_post_status
actions (甚至save_post
因此,您可以在发布帖子时检查元数据的存在,如果存在,请使用元数据中的原始作者替换帖子的作者。
试图用一个钩子将其击倒:
function correct_post_data( $strNewStatus, $strOldStatus, $post ) {
/* Only pay attention to posts (i.e. ignore links, attachments, etc. ) */
if( $post->post_type !== \'post\' )
return;
/* If this is a new post, save the original author into the post\'s meta-data. */
if( $strOldStatus === \'new\' ) {
update_post_meta( $post->ID, \'original_author\', $post->post_author );
}
/* If this post is being published, try to restore the original author */
if( $strNewStatus === \'publish\' ) {
$originalAuthor = get_post_meta( $post->ID, \'original_author\' );
/* If this post has an original author and it\'s not who the post says it is, revert the author field. */
if( !empty( $originalAuthor ) && $originalAuthor != $post->post_author ) {
$postData = array(
\'ID\' => $post->ID,
\'post_author\' => $originalAuthor
);
wp_update_post( $postData ); //May wish to check if this returns 0 for error-handling
}
}
}
add_action( \'transition_post_status\', \'correct_post_data\' );
检查
!is_admin()
在那里的某个地方也可以用来确认用户位于站点前端的某个地方。