Code Duplication    Length = 22-22 lines in 2 locations

json-endpoints/class.wpcom-json-api-update-post-endpoint.php 1 location

@@ 700-721 (lines=22) @@
697
		return $this->get_post_by( 'ID', $post->ID, $args['context'] );
698
	}
699
700
	private function parse_and_set_featured_image( $post_id, $delete_featured_image, $featured_image ) {
701
		if ( $delete_featured_image ) {
702
			delete_post_thumbnail( $post_id );
703
			return;
704
		}
705
706
		$featured_image = (string) $featured_image;
707
708
		// if we got a post ID, we can just set it as the thumbnail
709
		if ( ctype_digit( $featured_image ) && 'attachment' == get_post_type( $featured_image ) ) {
710
			set_post_thumbnail( $post_id, $featured_image );
711
			return $featured_image;
712
		}
713
714
		$featured_image_id = $this->handle_media_sideload( $featured_image, $post_id, 'image' );
715
716
		if ( empty( $featured_image_id ) || ! is_int( $featured_image_id ) )
717
			return false;
718
719
		set_post_thumbnail( $post_id, $featured_image_id );
720
		return $featured_image_id;
721
	}
722
723
	private function parse_and_set_author( $author = null, $post_type = 'post' ) {
724
		if ( empty( $author ) || ! post_type_supports( $post_type, 'author' ) )

json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php 1 location

@@ 766-787 (lines=22) @@
763
		return $this->get_post_by( 'ID', $post->ID, $args['context'] );
764
	}
765
766
	protected function parse_and_set_featured_image( $post_id, $delete_featured_image, $featured_image ) {
767
		if ( $delete_featured_image ) {
768
			delete_post_thumbnail( $post_id );
769
			return;
770
		}
771
772
		$featured_image = (string) $featured_image;
773
774
		// if we got a post ID, we can just set it as the thumbnail
775
		if ( ctype_digit( $featured_image ) && 'attachment' == get_post_type( $featured_image ) ) {
776
			set_post_thumbnail( $post_id, $featured_image );
777
			return $featured_image;
778
		}
779
780
		$featured_image_id = $this->handle_media_sideload( $featured_image, $post_id, 'image' );
781
782
		if ( empty( $featured_image_id ) || ! is_int( $featured_image_id ) )
783
			return false;
784
785
		set_post_thumbnail( $post_id, $featured_image_id );
786
		return $featured_image_id;
787
	}
788
789
	protected function parse_and_set_author( $author = null, $post_type = 'post' ) {
790
		if ( empty( $author ) || ! post_type_supports( $post_type, 'author' ) )