Code Duplication    Length = 19-19 lines in 2 locations

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

@@ 912-930 (lines=19) @@
909
		return $featured_image_id;
910
	}
911
912
	private function parse_and_set_author( $author = null, $post_type = 'post' ) {
913
		if ( empty( $author ) || ! post_type_supports( $post_type, 'author' ) )
914
			return get_current_user_id();
915
916
		$author = (string) $author;
917
		if ( ctype_digit( $author ) ) {
918
			$_user = get_user_by( 'id', $author );
919
			if ( ! $_user || is_wp_error( $_user ) )
920
				return new WP_Error( 'invalid_author', 'Invalid author provided' );
921
922
			return $_user->ID;
923
		}
924
925
		$_user = get_user_by( 'login', $author );
926
		if ( ! $_user || is_wp_error( $_user ) )
927
			return new WP_Error( 'invalid_author', 'Invalid author provided' );
928
929
		return $_user->ID;
930
	}
931
}
932

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

@@ 980-998 (lines=19) @@
977
		return $featured_image_id;
978
	}
979
980
	protected function parse_and_set_author( $author = null, $post_type = 'post' ) {
981
		if ( empty( $author ) || ! post_type_supports( $post_type, 'author' ) )
982
			return get_current_user_id();
983
984
		$author = (string) $author;
985
		if ( ctype_digit( $author ) ) {
986
			$_user = get_user_by( 'id', $author );
987
			if ( ! $_user || is_wp_error( $_user ) )
988
				return new WP_Error( 'invalid_author', 'Invalid author provided' );
989
990
			return $_user->ID;
991
		}
992
993
		$_user = get_user_by( 'login', $author );
994
		if ( ! $_user || is_wp_error( $_user ) )
995
			return new WP_Error( 'invalid_author', 'Invalid author provided' );
996
997
		return $_user->ID;
998
	}
999
1000
	protected function should_untrash_post( $last_status, $new_status, $post ) {
1001
		return 'trash' === $last_status && 'trash' !== $new_status && isset( $post->ID );