Code Duplication    Length = 28-28 lines in 2 locations

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

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

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

@@ 325-352 (lines=28) @@
322
		return $return;
323
	}
324
325
	function handle_date_range( $where ) {
326
		global $wpdb;
327
328
		switch ( count( $this->date_range ) ) {
329
		case 2 :
330
			$where .= $wpdb->prepare(
331
				" AND `$wpdb->posts`.post_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) ",
332
				$this->date_range['after'],
333
				$this->date_range['before']
334
			);
335
			break;
336
		case 1 :
337
			if ( isset( $this->date_range['before'] ) ) {
338
				$where .= $wpdb->prepare(
339
					" AND `$wpdb->posts`.post_date <= CAST( %s AS DATETIME ) ",
340
					$this->date_range['before']
341
				);
342
			} else {
343
				$where .= $wpdb->prepare(
344
					" AND `$wpdb->posts`.post_date >= CAST( %s AS DATETIME ) ",
345
					$this->date_range['after']
346
				);
347
			}
348
			break;
349
		}
350
351
		return $where;
352
	}
353
}
354