From cc4f0812b986e9e3cf848176bbf9cf7bdd12503d Mon Sep 17 00:00:00 2001 From: Mohammad Jangda <batmoo@gmail.com> Date: Tue, 10 Sep 2013 20:31:06 +0000 Subject: [PATCH] Better handling for thumbnails and multiple sites The way we were preventing repetitive syndication on every update was also breaking syndicating the thumbnail to multiple sites. This stores each thumbnail syndication alongside the site ID so that one site result cannot stomp on another. Also updates the meta key to make it more specific. fixes #36 --- includes/class-syndication-wp-xmlrpc-client.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/class-syndication-wp-xmlrpc-client.php b/includes/class-syndication-wp-xmlrpc-client.php index d767335..b8dd678 100644 --- a/includes/class-syndication-wp-xmlrpc-client.php +++ b/includes/class-syndication-wp-xmlrpc-client.php @@ -44,8 +44,13 @@ class Syndication_WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements Syndica foreach ( $thumbnail_meta_keys as $thumbnail_meta ) { $thumbnail_id = get_post_meta( $post_id, $thumbnail_meta, true ); - $syn_local_meta_key = '_syn_push_syndicated_' . $thumbnail_meta; - $syndicated_thumbnail_id = get_post_meta( $post_id, $syn_local_meta_key, true ); + $syn_local_meta_key = '_syn_push_thumb_' . $thumbnail_meta; + $syndicated_thumbnails_by_site = get_post_meta( $post_id, $syn_local_meta_key, true ); + + if ( ! is_array( $syndicated_thumbnails_by_site ) ) + $syndicated_thumbnails_by_site = array(); + + $syndicated_thumbnail_id = isset( $syndicated_thumbnails_by_site[ $this->site_ID ] ) ? $syndicated_thumbnails_by_site[ $this->site_ID ] : false; if ( ! $thumbnail_id ) { if ( $syndicated_thumbnail_id ) { @@ -58,7 +63,8 @@ class Syndication_WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements Syndica $thumbnail_meta ); - delete_post_meta( $post_id, $syn_local_meta_key ); + unset( $syndicated_thumbnails_by_site[ $this->site_ID ] ); + update_post_meta( $post_id, $syn_local_meta_key, $syndicated_thumbnails_by_site ); } continue; @@ -80,7 +86,8 @@ class Syndication_WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements Syndica ); if ( $result ) { - update_post_meta( $post_id, $syn_local_meta_key, $thumbnail_id ); + $syndicated_thumbnails_by_site[ $this->site_ID ] = $thumbnail_id; + update_post_meta( $post_id, $syn_local_meta_key, $syndicated_thumbnails_by_site ); } } } -- GitLab