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

@@ 673-695 (lines=23) @@
670
	 *
671
	 * @return int|object Post ID on success, WP_Error object on failure
672
	 **/
673
	protected function get_post_id_by_name( $name ) {
674
		$name = sanitize_title( $name );
675
676
		if ( ! $name ) {
677
			return new WP_Error( 'invalid_post', 'Invalid post', 400 );
678
		}
679
680
		$posts = get_posts( array( 'name' => $name ) );
681
682
		if ( ! $posts || ! isset( $posts[0]->ID ) || ! $posts[0]->ID ) {
683
			$page = get_page_by_path( $name );
684
685
			if ( ! $page ) {
686
				return new WP_Error( 'unknown_post', 'Unknown post', 404 );
687
			}
688
689
			$post_id = $page->ID;
690
		} else {
691
			$post_id = (int) $posts[0]->ID;
692
		}
693
694
		return $post_id;
695
	}
696
697
}
698