Skip to content

Instantly share code, notes, and snippets.

@Jany-M
Last active June 6, 2021 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jany-M/31bb0c7e5c2d6cd77a71 to your computer and use it in GitHub Desktop.
Save Jany-M/31bb0c7e5c2d6cd77a71 to your computer and use it in GitHub Desktop.
[WordPress] Update Author on post update
<?php
// Change Author on Update
function change_on_edit() {
global $post;
$id = $post->ID;
$original_author = $post-> post_author ;
$current_author = get_current_user_id();
if (!wp_is_post_revision($id)) {
remove_action('publish_post', 'change_on_edit');
$my_post = array(
'ID' => $id,
'post_author' => get_current_user_id(),
);
wp_update_post( $my_post );
add_action('publish_post', 'change_on_edit');
}
}
if (is_admin && 'post.php' == $pagenow) {
add_action('publish_post', 'change_on_edit');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment