Code Duplication    Length = 55-62 lines in 2 locations

includes/forms/class-give-forms-query.php 1 location

@@ 92-146 (lines=55) @@
89
	 *
90
	 * @return array
91
	 */
92
	public function get_forms() {
93
		global $post;
94
95
		$results     = array();
96
		$this->forms = array();
97
		$cache_key   = Give_Cache::get_key( 'give_form_query', $this->args, false );
98
		$this->forms = Give_Cache::get_db_query( $cache_key );
99
100
		// Return cached result.
101
		if ( ! is_null( $this->forms ) ) {
102
			return $this->forms;
103
		}
104
105
		/* @var WP_Query $query */
106
		$query = new WP_Query( $this->args );
107
108
		$custom_output = array(
109
			'forms',
110
			'give_forms',
111
		);
112
113
		if ( $query->have_posts() ) {
114
			$this->update_meta_cache( wp_list_pluck( $query->posts, 'ID' ) );
115
116
			if ( ! in_array( $this->args['output'], $custom_output ) ) {
117
				$results = $query->posts;
118
119
			} else {
120
				$previous_post = $post;
121
122
				while ( $query->have_posts() ) {
123
					$query->the_post();
124
125
					$form_id = get_post()->ID;
126
					$form    = new Give_Donate_Form( $form_id );
127
128
					$this->forms[] = apply_filters( 'give_form', $form, $form_id, $this );
129
				}
130
131
				wp_reset_postdata();
132
133
				// Prevent nest loop from producing unexpected results.
134
				if ( $previous_post instanceof WP_Post ) {
135
					$post = $previous_post;
136
					setup_postdata( $post );
137
				}
138
139
				$results = $this->forms;
140
			}
141
		}
142
143
		Give_Cache::set_db_query( $cache_key, $results );
144
145
		return $results;
146
	}
147
148
	/**
149
	 * Update forms meta cache

includes/payments/class-payments-query.php 1 location

@@ 218-279 (lines=62) @@
215
	 *
216
	 * @return array
217
	 */
218
	public function get_payments() {
219
		global $post;
220
221
		$results        = array();
222
		$this->payments = array();
223
		$cache_key      = Give_Cache::get_key( 'give_payment_query', $this->args, false );
224
		$this->payments = Give_Cache::get_db_query( $cache_key );
225
226
		// Return cached result.
227
		if ( ! is_null( $this->payments ) ) {
228
			return $this->payments;
229
		}
230
231
232
		// Modify the query/query arguments before we retrieve payments.
233
		$this->set_filters();
234
235
		/* @var WP_Query $query */
236
		$query = new WP_Query( $this->args );
237
238
		$custom_output = array(
239
			'payments',
240
			'give_payments',
241
		);
242
243
		if ( $query->have_posts() ) {
244
			$this->update_meta_cache( wp_list_pluck( $query->posts, 'ID' ) );
245
246
			if ( ! in_array( $this->args['output'], $custom_output ) ) {
247
				$results = $query->posts;
248
249
			} else{
250
				$previous_post = $post;
251
252
				while ( $query->have_posts() ) {
253
					$query->the_post();
254
255
					$payment_id = get_post()->ID;
256
					$payment    = new Give_Payment( $payment_id );
257
258
					$this->payments[] = apply_filters( 'give_payment', $payment, $payment_id, $this );
259
				}
260
261
				wp_reset_postdata();
262
263
				// Prevent nest loop from producing unexpected results.
264
				if ( $previous_post instanceof WP_Post ) {
265
					$post = $previous_post;
266
					setup_postdata( $post );
267
				}
268
269
				$results = $this->payments;
270
			}
271
		}
272
273
		Give_Cache::set_db_query( $cache_key, $results );
274
275
		// Remove query filters after we retrieve payments.
276
		$this->unset_filters();
277
278
		return $results;
279
	}
280
281
	/**
282
	 * Get payments by group