Code Duplication    Length = 28-28 lines in 2 locations

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

@@ 207-234 (lines=28) @@
204
		return $where;
205
	}
206
207
	function handle_date_range( $where ) {
208
		global $wpdb;
209
210
		switch ( count( $this->date_range ) ) {
211
		case 2 :
212
			$where .= $wpdb->prepare(
213
				" AND `$wpdb->posts`.post_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) ",
214
				$this->date_range['after'],
215
				$this->date_range['before']
216
			);
217
			break;
218
		case 1 :
219
			if ( isset( $this->date_range['before'] ) ) {
220
				$where .= $wpdb->prepare(
221
					" AND `$wpdb->posts`.post_date <= CAST( %s AS DATETIME ) ",
222
					$this->date_range['before']
223
				);
224
			} else {
225
				$where .= $wpdb->prepare(
226
					" AND `$wpdb->posts`.post_date >= CAST( %s AS DATETIME ) ",
227
					$this->date_range['after']
228
				);
229
			}
230
			break;
231
		}
232
233
		return $where;
234
	}
235
236
	function handle_orderby_for_page_handle( $orderby ) {
237
		global $wpdb;

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

@@ 266-293 (lines=28) @@
263
		return $return;
264
	}
265
266
	function handle_date_range( $where ) {
267
		global $wpdb;
268
269
		switch ( count( $this->date_range ) ) {
270
		case 2 :
271
			$where .= $wpdb->prepare(
272
				" AND `$wpdb->posts`.post_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) ",
273
				$this->date_range['after'],
274
				$this->date_range['before']
275
			);
276
			break;
277
		case 1 :
278
			if ( isset( $this->date_range['before'] ) ) {
279
				$where .= $wpdb->prepare(
280
					" AND `$wpdb->posts`.post_date <= CAST( %s AS DATETIME ) ",
281
					$this->date_range['before']
282
				);
283
			} else {
284
				$where .= $wpdb->prepare(
285
					" AND `$wpdb->posts`.post_date >= CAST( %s AS DATETIME ) ",
286
					$this->date_range['after']
287
				);
288
			}
289
			break;
290
		}
291
292
		return $where;
293
	}
294
}
295