Skip to content

Commit

Permalink
SyndicatedPost / fix_revision_meta should use pleasant API set_post_f…
Browse files Browse the repository at this point in the history
…ield not janky direct MySQL. Fix the guid as well as the post_author, to fit a scheme based on the update hash, possibly usable later. Fire an action so that add-ons can make their own adjustments if need be.
  • Loading branch information
radgeek committed Jul 2, 2014
1 parent f2bb802 commit e684697
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions syndicatedpost.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1930,14 +1930,14 @@ function validate_post_id ($dbpost, $is_update, $ns) {
} /* SyndicatedPost::validate_post_id() */

/**
* SyndicatedPost::fix_revision_meta() - Fixes the way WP 2.6+ fucks up
* meta-data (authorship, etc.) when storing revisions of an updated
* syndicated post.
* SyndicatedPost::fix_revision_meta() - Ensures that we get the meta
* data (authorship, guid, etc.) that we want when storing revisions of
* a syndicated post.
*
* In their infinite wisdom, the WordPress coders have made it completely
* impossible for a plugin that uses wp_insert_post() to set certain
* meta-data (such as the author) when you store an old revision of an
* updated post. Instead, it uses the WordPress defaults (= currently
* In their infinite wisdom, the WordPress coders seem to have made it
* completely impossible for a plugin that uses wp_insert_post() to set
* certain meta-data (such as the author) when you store an old revision
* of an updated post. Instead, it uses the WordPress defaults (= cur.
* active user ID if the process is running with a user logged in, or
* = #0 if there is no user logged in). This results in bogus authorship
* data for revisions that are syndicated from off the feed, unless we
Expand All @@ -1953,11 +1953,15 @@ function fix_revision_meta ($revision_id) {

$revision_id = (int) $revision_id;

$wpdb->query("
UPDATE $wpdb->posts
SET post_author={$this->post['post_author']}
WHERE post_type = 'revision' AND ID='$revision_id'
");
// Let's fix the author.
set_post_field('post_author', $this->post['post_author'], $revision_id);

// Let's fix the GUID to a dummy URL with the update hash.
set_post_field('guid', 'http://feedwordpress.radgeek.com/?rev='.$this->update_hash(), $revision_id);

// Let's fire an event for add-ons and filters
do_action('syndicated_post_fix_revision_meta', $revision_id, $this);

} /* SyndicatedPost::fix_revision_meta () */

/**
Expand Down

0 comments on commit e684697

Please sign in to comment.