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

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