[wp-hackers] Getting post_author to update with an autosave.

Mark Slade markandrewslade at gmail.com
Tue Nov 17 16:56:54 UTC 2009


I am trying to resolve an issue in my WPMU 2.8 installation causing a
page's original author to be carried over when it is autosaved by a
different author.

I have hooked into edit_page_form and am using it to spit out a hidden
input named "post_author_override" with a value of the current user's
ID.  In an autosave this is translated to "post_author" and survives all
the way to wp_create_post_autosave(), defined in

At this point _wp_post_revision_fields() is called, defined in
wp-includes/post.php, which removes the post_author field because it is
protected.  I can hook into the '_wp_post_revision_fields' filter and
add it, but it's hard-coded to be removed so this does me no good.

As a result, the autosave is created/updated without post_author being
changed, and autosaves are always attributed to the original author and
not the actual author.

I can fix this by directly editing _wp_post_revision_fields so that
post_author is not in the array of protected keys, but am concerned that
it was put there for a reason and this will cause something to break.

Can anyone lend some insight?  Is it by design that autosaves keep the
original author, and not the actual author?

Thank you,

More information about the wp-hackers mailing list