Code Duplication    Length = 23-23 lines in 2 locations

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

@@ 661-683 (lines=23) @@
658
	 *
659
	 * @return int|object Post ID on success, WP_Error object on failure
660
	 **/
661
	protected function get_post_id_by_name( $name ) {
662
		$name = sanitize_title( $name );
663
664
		if ( ! $name ) {
665
			return new WP_Error( 'invalid_post', 'Invalid post', 400 );
666
		}
667
668
		$posts = get_posts( array( 'name' => $name ) );
669
670
		if ( ! $posts || ! isset( $posts[0]->ID ) || ! $posts[0]->ID ) {
671
			$page = get_page_by_path( $name );
672
673
			if ( ! $page ) {
674
				return new WP_Error( 'unknown_post', 'Unknown post', 404 );
675
			}
676
677
			$post_id = $page->ID;
678
		} else {
679
			$post_id = (int) $posts[0]->ID;
680
		}
681
682
		return $post_id;
683
	}
684
}
685

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

@@ 688-710 (lines=23) @@
685
	 *
686
	 * @return int|object Post ID on success, WP_Error object on failure
687
	 **/
688
	protected function get_post_id_by_name( $name ) {
689
		$name = sanitize_title( $name );
690
691
		if ( ! $name ) {
692
			return new WP_Error( 'invalid_post', 'Invalid post', 400 );
693
		}
694
695
		$posts = get_posts( array( 'name' => $name ) );
696
697
		if ( ! $posts || ! isset( $posts[0]->ID ) || ! $posts[0]->ID ) {
698
			$page = get_page_by_path( $name );
699
700
			if ( ! $page ) {
701
				return new WP_Error( 'unknown_post', 'Unknown post', 404 );
702
			}
703
704
			$post_id = $page->ID;
705
		} else {
706
			$post_id = (int) $posts[0]->ID;
707
		}
708
709
		return $post_id;
710
	}
711
712
}
713