Code Duplication    Length = 17-17 lines in 3 locations

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

@@ 205-221 (lines=17) @@
202
			$query['post__not_in'] = array_merge( $query['post__not_in'], (array) $args['exclude'] );
203
		}
204
205
		if ( isset( $args['exclude_tree'] ) && is_post_type_hierarchical( $args['type'] ) ) {
206
			// get_page_children is a misnomer; it supports all hierarchical post types
207
			$page_args = array(
208
					'child_of' => $args['exclude_tree'],
209
					'post_type' => $args['type'],
210
					// since we're looking for things to exclude, be aggressive
211
					'post_status' => 'publish,draft,pending,private,future,trash',
212
				);
213
			$post_descendants = get_pages( $page_args );
214
215
			$exclude_tree = array( $args['exclude_tree'] );
216
			foreach ( $post_descendants as $child ) {
217
				$exclude_tree[] = $child->ID;
218
			}
219
220
			$query['post__not_in'] = isset( $query['post__not_in'] ) ? array_merge( $query['post__not_in'], $exclude_tree ) : $exclude_tree;
221
		}
222
223
		if ( isset( $args['category'] ) ) {
224
			$category = get_term_by( 'slug', $args['category'], 'category' );

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

@@ 230-246 (lines=17) @@
227
			$query['post__not_in'] = isset( $query['post__not_in'] ) ? array_merge( $query['post__not_in'], $excluded_ids ) : $excluded_ids;
228
		}
229
230
		if ( isset( $args['exclude_tree'] ) && is_post_type_hierarchical( $args['type'] ) ) {
231
			// get_page_children is a misnomer; it supports all hierarchical post types
232
			$page_args        = array(
233
				'child_of'    => $args['exclude_tree'],
234
				'post_type'   => $args['type'],
235
				// since we're looking for things to exclude, be aggressive
236
				'post_status' => 'publish,draft,pending,private,future,trash',
237
			);
238
			$post_descendants = get_pages( $page_args );
239
240
			$exclude_tree = array( $args['exclude_tree'] );
241
			foreach ( $post_descendants as $child ) {
242
				$exclude_tree[] = $child->ID;
243
			}
244
245
			$query['post__not_in'] = isset( $query['post__not_in'] ) ? array_merge( $query['post__not_in'], $exclude_tree ) : $exclude_tree;
246
		}
247
248
		if ( isset( $args['category'] ) ) {
249
			$category = get_term_by( 'slug', $args['category'], 'category' );

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

@@ 224-240 (lines=17) @@
221
			$query['post__not_in'] = isset( $query['post__not_in'] ) ? array_merge( $query['post__not_in'], $excluded_ids ) : $excluded_ids;
222
		}
223
224
		if ( isset( $args['exclude_tree'] ) && is_post_type_hierarchical( $args['type'] ) ) {
225
			// get_page_children is a misnomer; it supports all hierarchical post types
226
			$page_args        = array(
227
				'child_of'    => $args['exclude_tree'],
228
				'post_type'   => $args['type'],
229
				// since we're looking for things to exclude, be aggressive
230
				'post_status' => 'publish,draft,pending,private,future,trash',
231
			);
232
			$post_descendants = get_pages( $page_args );
233
234
			$exclude_tree = array( $args['exclude_tree'] );
235
			foreach ( $post_descendants as $child ) {
236
				$exclude_tree[] = $child->ID;
237
			}
238
239
			$query['post__not_in'] = isset( $query['post__not_in'] ) ? array_merge( $query['post__not_in'], $exclude_tree ) : $exclude_tree;
240
		}
241
242
		if ( isset( $args['category'] ) ) {
243
			$category = get_term_by( 'slug', $args['category'], 'category' );