Code Duplication    Length = 18-18 lines in 3 locations

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

@@ 129-146 (lines=18) @@
126
		$args['type'] = isset( $args['type'] ) ? $args['type'] : 'post';
127
128
		// make sure the user can read or edit the requested post type(s)
129
		if ( is_array( $args['type'] ) ) {
130
			$allowed_types = array();
131
			foreach ( $args['type'] as $post_type ) {
132
				if ( $this->current_user_can_access_post_type( $post_type, $args['context'] ) ) {
133
				   	$allowed_types[] = $post_type;
134
				}
135
			}
136
137
			if ( empty( $allowed_types ) ) {
138
				return array( 'found' => 0, 'posts' => array() );
139
			}
140
			$args['type'] = $allowed_types;
141
		}
142
		else {
143
			if ( ! $this->current_user_can_access_post_type( $args['type'], $args['context'] ) ) {
144
				return array( 'found' => 0, 'posts' => array() );
145
			}
146
		}
147
148
		$query = array(
149
			'posts_per_page' => $args['number'],

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

@@ 142-159 (lines=18) @@
139
		$args['type'] = isset( $args['type'] ) ? $args['type'] : 'post';
140
141
		// make sure the user can read or edit the requested post type(s)
142
		if ( is_array( $args['type'] ) ) {
143
			$allowed_types = array();
144
			foreach ( $args['type'] as $post_type ) {
145
				if ( $site->current_user_can_access_post_type( $post_type, $args['context'] ) ) {
146
					$allowed_types[] = $post_type;
147
				}
148
			}
149
150
			if ( empty( $allowed_types ) ) {
151
				return array(
152
					'found' => 0,
153
					'posts' => array(),
154
				);
155
			}
156
			$args['type'] = $allowed_types;
157
		} else {
158
			if ( ! $site->current_user_can_access_post_type( $args['type'], $args['context'] ) ) {
159
				return array(
160
					'found' => 0,
161
					'posts' => array(),
162
				);

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

@@ 107-124 (lines=18) @@
104
		}
105
106
		// make sure the user can read or edit the requested post type(s)
107
		if ( is_array( $args['type'] ) ) {
108
			$allowed_types = array();
109
			foreach ( $args['type'] as $post_type ) {
110
				if ( $site->current_user_can_access_post_type( $post_type, $args['context'] ) ) {
111
					$allowed_types[] = $post_type;
112
				}
113
			}
114
115
			if ( empty( $allowed_types ) ) {
116
				return array(
117
					'found' => 0,
118
					'posts' => array(),
119
				);
120
			}
121
			$args['type'] = $allowed_types;
122
		} else {
123
			if ( ! $site->current_user_can_access_post_type( $args['type'], $args['context'] ) ) {
124
				return array(
125
					'found' => 0,
126
					'posts' => array(),
127
				);