Code Duplication    Length = 28-28 lines in 2 locations

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

@@ 249-276 (lines=28) @@
246
		return $return;
247
	}
248
249
	function handle_date_range( $where ) {
250
		global $wpdb;
251
252
		switch ( count( $this->date_range ) ) {
253
		case 2 :
254
			$where .= $wpdb->prepare(
255
				" AND `$wpdb->posts`.post_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) ",
256
				$this->date_range['after'],
257
				$this->date_range['before']
258
			);
259
			break;
260
		case 1 :
261
			if ( isset( $this->date_range['before'] ) ) {
262
				$where .= $wpdb->prepare(
263
					" AND `$wpdb->posts`.post_date <= CAST( %s AS DATETIME ) ",
264
					$this->date_range['before']
265
				);
266
			} else {
267
				$where .= $wpdb->prepare(
268
					" AND `$wpdb->posts`.post_date >= CAST( %s AS DATETIME ) ",
269
					$this->date_range['after']
270
				);
271
			}
272
			break;
273
		}
274
275
		return $where;
276
	}
277
}
278

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

@@ 193-220 (lines=28) @@
190
		return $where;
191
	}
192
193
	function handle_date_range( $where ) {
194
		global $wpdb;
195
196
		switch ( count( $this->date_range ) ) {
197
		case 2 :
198
			$where .= $wpdb->prepare(
199
				" AND `$wpdb->posts`.post_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) ",
200
				$this->date_range['after'],
201
				$this->date_range['before']
202
			);
203
			break;
204
		case 1 :
205
			if ( isset( $this->date_range['before'] ) ) {
206
				$where .= $wpdb->prepare(
207
					" AND `$wpdb->posts`.post_date <= CAST( %s AS DATETIME ) ",
208
					$this->date_range['before']
209
				);
210
			} else {
211
				$where .= $wpdb->prepare(
212
					" AND `$wpdb->posts`.post_date >= CAST( %s AS DATETIME ) ",
213
					$this->date_range['after']
214
				);
215
			}
216
			break;
217
		}
218
219
		return $where;
220
	}
221
222
	function handle_orderby_for_page_handle( $orderby ) {
223
		global $wpdb;