Code Duplication    Length = 18-18 lines in 3 locations

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

@@ 70-87 (lines=18) @@
67
		$args['type'] = isset( $args['type'] ) ? $args['type'] : 'post';
68
69
		// make sure the user can read or edit the requested post type(s)
70
		if ( is_array( $args['type'] ) ) {
71
			$allowed_types = array();
72
			foreach ( $args['type'] as $post_type ) {
73
				if ( $this->current_user_can_access_post_type( $post_type, $args['context'] ) ) {
74
				   	$allowed_types[] = $post_type;
75
				}
76
			}
77
78
			if ( empty( $allowed_types ) ) {
79
				return array( 'found' => 0, 'posts' => array() );
80
			}
81
			$args['type'] = $allowed_types;
82
		}
83
		else {
84
			if ( ! $this->current_user_can_access_post_type( $args['type'], $args['context'] ) ) {
85
				return array( 'found' => 0, 'posts' => array() );
86
			}
87
		}
88
89
		$query = array(
90
			'posts_per_page' => $args['number'],

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

@@ 81-98 (lines=18) @@
78
		$args['type'] = isset( $args['type'] ) ? $args['type'] : 'post';
79
80
		// make sure the user can read or edit the requested post type(s)
81
		if ( is_array( $args['type'] ) ) {
82
			$allowed_types = array();
83
			foreach ( $args['type'] as $post_type ) {
84
				if ( $site->current_user_can_access_post_type( $post_type, $args['context'] ) ) {
85
				   	$allowed_types[] = $post_type;
86
				}
87
			}
88
89
			if ( empty( $allowed_types ) ) {
90
				return array( 'found' => 0, 'posts' => array() );
91
			}
92
			$args['type'] = $allowed_types;
93
		}
94
		else {
95
			if ( ! $site->current_user_can_access_post_type( $args['type'], $args['context'] ) ) {
96
				return array( 'found' => 0, 'posts' => array() );
97
			}
98
		}
99
100
101
		$query = array(

json-endpoints/class.wpcom-json-api-list-posts-v1-2-endpoint.php 1 location

@@ 54-71 (lines=18) @@
51
		}
52
53
		// make sure the user can read or edit the requested post type(s)
54
		if ( is_array( $args['type'] ) ) {
55
			$allowed_types = array();
56
			foreach ( $args['type'] as $post_type ) {
57
				if ( $site->current_user_can_access_post_type( $post_type, $args['context'] ) ) {
58
					$allowed_types[] = $post_type;
59
				}
60
			}
61
62
			if ( empty( $allowed_types ) ) {
63
				return array( 'found' => 0, 'posts' => array() );
64
			}
65
			$args['type'] = $allowed_types;
66
		}
67
		else {
68
			if ( ! $site->current_user_can_access_post_type( $args['type'], $args['context'] ) ) {
69
				return array( 'found' => 0, 'posts' => array() );
70
			}
71
		}
72
73
		// determine statuses
74
		$status = ( ! empty( $args['status'] ) ) ? explode( ',', $args['status'] ) : array( 'publish' );