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

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

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

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