diff --git a/includes/class-syndication-wp-xmlrpc-client.php b/includes/class-syndication-wp-xmlrpc-client.php index f9534e7b5711ee945165eca75b8f175cff16bac7..d35862d4e0ab7f4e2410b6d1c6c4ee0601fd1c0f 100644 --- a/includes/class-syndication-wp-xmlrpc-client.php +++ b/includes/class-syndication-wp-xmlrpc-client.php @@ -40,6 +40,7 @@ class Syndication_WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements Syndica } function post_push_send_thumbnail( $remote_post_id, $post_id ) { + $thumbnail_meta_keys = $this->get_thumbnail_meta_keys( $post_id ); foreach ( $thumbnail_meta_keys as $thumbnail_meta ) { @@ -47,8 +48,9 @@ class Syndication_WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements Syndica $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 ) ) + 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; @@ -70,11 +72,16 @@ class Syndication_WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements Syndica continue; } - if ( $syndicated_thumbnail_id == $thumbnail_id ) + if ( $syndicated_thumbnail_id == $thumbnail_id ) { continue; + } list( $thumbnail_url ) = wp_get_attachment_image_src( $thumbnail_id, 'full' ); - + //pass thumbnail data and meta into the addThumnail to sync caption, description and alt-text + //has to be this way since mw_newMediaObject doesn't allow to pass description and caption along + $thumbnail_post_data = get_post( $thumbnail_id ); + $thumbnail_alt_text = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true ); + $result = $this->query( 'syndication.addThumbnail', '1', @@ -82,7 +89,9 @@ class Syndication_WP_XMLRPC_Client extends WP_HTTP_IXR_Client implements Syndica $this->password, $remote_post_id, $thumbnail_url, - $thumbnail_meta + $thumbnail_meta, + $thumbnail_post_data, + $thumbnail_alt_text ); if ( $result ) { @@ -424,12 +433,14 @@ class Syndication_WP_XMLRPC_Client_Extensions { $wp_xmlrpc_server->escape( $args ); - $blog_id = (int) $args[0]; - $username = $args[1]; - $password = $args[2]; - $post_ID = (int)$args[3]; - $thumbnail_url = esc_url_raw( $args[4] ); - $meta_key = ! empty( $args[5] ) ? sanitize_text_field( $args[5] ) : '_thumbnail_id'; + $blog_id = (int) $args[0]; + $username = $args[1]; + $password = $args[2]; + $post_ID = (int) $args[3]; + $thumbnail_url = esc_url_raw( $args[4] ); + $meta_key = ! empty( $args[5] ) ? sanitize_text_field( $args[5] ) : '_thumbnail_id'; + $thumbnail_post_data = $args[6]; + $thumbnail_alt_text = $args[7]; if ( ! $post_ID ) return new IXR_Error( 500, __( 'Please specify a valid post_ID.', 'syndication' ) ); @@ -446,9 +457,9 @@ class Syndication_WP_XMLRPC_Client_Extensions { $username, $password, array( - 'name' => $thumbnail_filename, - 'type' => $thumbnail_type['type'], - 'bits' => $thumbnail_raw, + 'name' => $thumbnail_filename, + 'type' => $thumbnail_type['type'], + 'bits' => $thumbnail_raw, 'overwrite' => false, ), ); @@ -470,6 +481,26 @@ class Syndication_WP_XMLRPC_Client_Extensions { if ( ! $thumbnail_set ) return new IXR_Error( 403, __( 'Could not attach post thumbnail.' ) ); + + $args = array( + $blog_id, + $username, + $password, + $thumbnail_id, + array( + 'post_title' => $thumbnail_post_data['post_title'], + 'post_content' => $thumbnail_post_data['post_content'], + 'post_excerpt' => $thumbnail_post_data['post_excerpt'], + ), + ); + //update caption and description of the image + $result = $wp_xmlrpc_server->wp_editPost( $args ); + if ( $result !== true ) { + //failed to update atatchment post details + //handle it th way you want it (log it, message it) + } + //update alt text of the image + update_post_meta($thumbnail_id, '_wp_attachment_image_alt', $thumbnail_alt_text); return $thumbnail_id; } @@ -482,7 +513,7 @@ class Syndication_WP_XMLRPC_Client_Extensions { $blog_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; - $post_ID = (int)$args[3]; + $post_ID = (int) $args[3]; $meta_key = ! empty( $args[4] ) ? sanitize_text_field( $args[4] ) : '_thumbnail_id'; if ( !$user = $wp_xmlrpc_server->login( $username, $password ) )