• How do you make an image the same as the original post without having to upload the image again? This is based on our site using one image media that crosses sites.

    				// Featured Image.
    				if ( $featured_image ) {
    
    					// Because of the various CDN plugins around we can't just
    					// use media_handle_upload. We have to actually retrieve the
    					// image then re-upload it.
    					$image = wp_remote_get( $featured_image->url );
    
    					if ( 200 === wp_remote_retrieve_response_code( $image ) ) {
    
    						// Upload the image to this site's upload dir.
    						$attachment = wp_upload_bits( basename( $featured_image->path ), null, $image['body'], date( "Y-m", strtotime( $image['headers']['last-modified'] ) ) );
                            $featured_image = $this->prepare_featured_image( $original_post );
    						if ( empty( $attachment['error'] ) ) {
    
    							// Get the filetype.
    							$filetype = wp_check_filetype( basename( $attachment['file'] ), null );
    
    							$filename = $attachment['file'];
    
    							// Setup the attachment data.
    							$attachment_data = array(
    								'post_mime_type' => $filetype['type'],
    								'post_title'     => $featured_image->post_title,
    								'post_excerpt'   => $featured_image->post_excerpt,
    								'post_content'   => '',
    								'post_status'    => 'inherit',
    							);
    
    							// Insert the new attachment data with our basic information.
    							$attachment_id = wp_insert_attachment( $attachment_data, $filename, $aggregated_post_id );
    
    							// Check the wp_generate_attachment_metadata() function exists.
    							if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
    								require_once ( ABSPATH . 'wp-admin/includes/image.php' );
    							}
    
    							// Generate the raw iamge meta data.
    							$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
    
    							// Save the image meta data to the new attachment.
    							wp_update_attachment_metadata( $attachment_id,  $attachment_data );
    
    							// Set as the feature image.
    							set_post_thumbnail( $aggregated_post_id, $attachment_id );
    						} else {
    							error_log( "MSCP: Error uploading attachment. post_id = {$aggregated_post_id}, blog_id = $blog_id", 0 );
    						}
    
    					}
    
    				}

  • The topic ‘[NSFW] Making One Image with Original Post’ is closed to new replies.