PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.0
GiveWP – Donation Plugin and Fundraising Platform v2.0.0
4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-logging.php
give / includes Last commit date
admin 8 years ago api 8 years ago deprecated 8 years ago donors 8 years ago emails 8 years ago forms 8 years ago gateways 8 years ago libraries 8 years ago payments 8 years ago actions.php 8 years ago ajax-functions.php 8 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 8 years ago class-give-cache.php 8 years ago class-give-cli-commands.php 8 years ago class-give-cron.php 8 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 8 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 8 years ago class-give-db-meta.php 8 years ago class-give-db-payment-meta.php 8 years ago class-give-db.php 8 years ago class-give-donate-form.php 8 years ago class-give-donor.php 8 years ago class-give-email-access.php 8 years ago class-give-gravatars.php 8 years ago class-give-html-elements.php 8 years ago class-give-license-handler.php 8 years ago class-give-logging.php 8 years ago class-give-roles.php 8 years ago class-give-session.php 8 years ago class-give-stats.php 8 years ago class-give-template-loader.php 9 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 8 years ago country-functions.php 8 years ago currency-functions.php 8 years ago error-tracking.php 8 years ago filters.php 8 years ago formatting.php 8 years ago import-functions.php 8 years ago install.php 8 years ago login-register.php 8 years ago misc-functions.php 8 years ago plugin-compatibility.php 8 years ago post-types.php 8 years ago price-functions.php 8 years ago process-donation.php 8 years ago scripts.php 8 years ago shortcodes.php 8 years ago template-functions.php 8 years ago user-functions.php 8 years ago
class-give-logging.php
746 lines
1 <?php
2 /**
3 * Class for logging events and errors
4 *
5 * @package Give
6 * @subpackage Classes/Give_Logging
7 * @copyright Copyright (c) 2016, WordImpress
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Give_Logging Class
19 *
20 * A general use class for logging events and errors.
21 *
22 * @since 1.0
23 */
24 class Give_Logging {
25 /**
26 * Logs data operation handler object.
27 *
28 * @since 2.0
29 * @access private
30 * @var Give_DB_Logs
31 */
32 public $log_db;
33
34 /**
35 * Log meta data operation handler object.
36 *
37 * @since 2.0
38 * @access private
39 * @var Give_DB_Log_Meta
40 */
41 public $logmeta_db;
42
43 /**
44 * Class Constructor
45 *
46 * Set up the Give Logging Class.
47 *
48 * @since 1.0
49 * @access public
50 */
51 public function __construct() {
52 /**
53 * Setup properties
54 */
55
56 require_once GIVE_PLUGIN_DIR . 'includes/class-give-db-logs.php';
57 require_once GIVE_PLUGIN_DIR . 'includes/class-give-db-logs-meta.php';
58 $this->log_db = new Give_DB_Logs();
59 $this->logmeta_db = new Give_DB_Log_Meta();
60
61 /**
62 * Setup hooks.
63 */
64
65 add_action( 'save_post_give_payment', array( $this, 'background_process_delete_cache' ) );
66 add_action( 'save_post_give_forms', array( $this, 'background_process_delete_cache' ) );
67 add_action( 'save_post_give_log', array( $this, 'background_process_delete_cache' ) );
68 add_action( 'give_delete_log_cache', array( $this, 'delete_cache' ) );
69 add_action( 'update_log_metadata', array( $this, 'bc_200_set_payment_as_log_parent' ), 10, 4 );
70
71 // Backward compatibility.
72 if ( ! give_has_upgrade_completed( 'v20_logs_upgrades' ) ) {
73 // Create the log post type
74 add_action( 'init', array( $this, 'register_post_type' ), -2 );
75 }
76
77 // Create types taxonomy and default types
78 // @todo: remove this taxonomy, some addon use this taxonomy with there custom log post type for example: recurring
79 // Do not use this taxonomy with your log type because we will remove it in future releases.
80 add_action( 'init', array( $this, 'register_taxonomy' ), -2 );
81 }
82
83
84 /**
85 * Log Post Type
86 *
87 * Registers the 'give_log' Post Type.
88 *
89 * @since 1.0
90 * @access public
91 *
92 * @return void
93 */
94 public function register_post_type() {
95 /* Logs post type */
96 $log_args = array(
97 'labels' => array(
98 'name' => esc_html__( 'Logs', 'give' ),
99 ),
100 'public' => false,
101 'exclude_from_search' => true,
102 'publicly_queryable' => false,
103 'show_ui' => false,
104 'query_var' => false,
105 'rewrite' => false,
106 'capability_type' => 'post',
107 'supports' => array( 'title', 'editor' ),
108 'can_export' => true,
109 );
110
111 register_post_type( 'give_log', $log_args );
112 }
113
114 /**
115 * Log Type Taxonomy
116 *
117 * Registers the "Log Type" taxonomy. Used to determine the type of log entry.
118 *
119 * @since 1.0
120 * @access public
121 *
122 * @return void
123 */
124 public function register_taxonomy() {
125 register_taxonomy( 'give_log_type', 'give_log', array(
126 'public' => false,
127 ) );
128 }
129
130 /**
131 * Log Types
132 *
133 * Sets up the default log types and allows for new ones to be created.
134 *
135 * @since 1.0
136 * @access public
137 *
138 * @return array $terms
139 */
140 public function log_types() {
141 $terms = array(
142 'sale',
143 'gateway_error',
144 'api_request',
145 );
146
147 return apply_filters( 'give_log_types', $terms );
148 }
149
150 /**
151 * Check if a log type is valid
152 *
153 * Checks to see if the specified type is in the registered list of types.
154 *
155 * @since 1.0
156 * @access public
157 *
158 * @param string $type Log type.
159 *
160 * @return bool Whether log type is valid.
161 */
162 public function valid_type( $type ) {
163 return in_array( $type, $this->log_types() );
164 }
165
166 /**
167 * Create new log entry
168 *
169 * This is just a simple and fast way to log something. Use $this->insert_log()
170 * if you need to store custom meta data.
171 *
172 * @since 1.0
173 * @access public
174 *
175 * @param string $title Log entry title. Default is empty.
176 * @param string $message Log entry message. Default is empty.
177 * @param int $parent Log entry parent. Default is 0.
178 * @param string $type Log type. Default is empty string.
179 *
180 * @return int Log ID.
181 */
182 public function add( $title = '', $message = '', $parent = 0, $type = '' ) {
183 $log_data = array(
184 'post_title' => $title,
185 'post_content' => $message,
186 'post_parent' => $parent,
187 'log_type' => $type,
188 );
189
190 return $this->insert_log( $log_data );
191 }
192
193 /**
194 * Get Logs
195 *
196 * Retrieves log items for a particular object ID.
197 *
198 * @since 1.0
199 * @access public
200 *
201 * @param int $object_id Log object ID. Default is 0.
202 * @param string $type Log type. Default is empty string.
203 * @param int $paged Page number Default is null.
204 *
205 * @return array An array of the connected logs.
206 */
207 public function get_logs( $object_id = 0, $type = '', $paged = null ) {
208 return $this->get_connected_logs( array(
209 'log_parent' => $object_id,
210 'paged' => $paged,
211 'log_type' => $type,
212 ) );
213 }
214
215 /**
216 * Stores a log entry
217 *
218 * @since 1.0
219 * @access public
220 *
221 * @param array $log_data Log entry data.
222 * @param array $log_meta Log entry meta.
223 *
224 * @return int The ID of the newly created log item.
225 */
226 public function insert_log( $log_data = array(), $log_meta = array() ) {
227 $log_id = 0;
228
229 $defaults = array(
230 'log_parent' => 0,
231 'log_content' => '',
232 'log_type' => false,
233
234 // Backward compatibility.
235 'post_type' => 'give_log',
236 'post_status' => 'publish',
237 );
238
239 $args = wp_parse_args( $log_data, $defaults );
240 $this->bc_200_validate_params( $args, $log_meta );
241
242 if ( ! give_has_upgrade_completed( 'v20_logs_upgrades' ) ) {
243 global $wpdb;
244
245 // Backward Compatibility.
246 if ( ! $wpdb->get_var( "SELECT ID from {$this->log_db->table_name} ORDER BY id DESC LIMIT 1" ) ) {
247 $latest_log_id = $wpdb->get_var( "SELECT ID from $wpdb->posts ORDER BY id DESC LIMIT 1" );
248 $latest_log_id = empty( $latest_log_id ) ? 1 : ++ $latest_log_id;
249
250 $args['ID'] = $latest_log_id;
251 $this->log_db->insert( $args );
252 }
253 }
254
255 $log_id = $this->log_db->add( $args );
256
257 // Set log meta, if any
258 if ( $log_id && ! empty( $log_meta ) ) {
259 foreach ( (array) $log_meta as $key => $meta ) {
260 $this->logmeta_db->update_meta( $log_id, '_give_log_' . sanitize_key( $key ), $meta );
261 }
262 }
263
264
265 // Delete cache.
266 $this->delete_cache();
267
268 return $log_id;
269 }
270
271 /**
272 * Update and existing log item
273 *
274 * @since 1.0
275 * @access public
276 *
277 * @param array $log_data Log entry data.
278 * @param array $log_meta Log entry meta.
279 *
280 * @return bool|null True if successful, false otherwise.
281 */
282 public function update_log( $log_data = array(), $log_meta = array() ) {
283 $log_id = 0;
284
285 /**
286 * Fires before updating log entry.
287 *
288 * @since 1.0
289 *
290 * @param array $log_data Log entry data.
291 * @param array $log_meta Log entry meta.
292 */
293 do_action( 'give_pre_update_log', $log_data, $log_meta );
294
295 $defaults = array(
296 'log_parent' => 0,
297
298 // Backward compatibility.
299 'post_type' => 'give_log',
300 'post_status' => 'publish',
301 );
302
303 $args = wp_parse_args( $log_data, $defaults );
304 $this->bc_200_validate_params( $args, $log_meta );
305
306 // Store the log entry
307 if ( ! give_has_upgrade_completed( 'v20_logs_upgrades' ) ) {
308 // Backward compatibility.
309 $log_id = wp_update_post( $args );
310
311 if ( $log_id && ! empty( $log_meta ) ) {
312 foreach ( (array) $log_meta as $key => $meta ) {
313 if ( ! empty( $meta ) ) {
314 give_update_meta( $log_id, '_give_log_' . sanitize_key( $key ), $meta );
315 }
316 }
317 }
318 } else {
319 $log_id = $this->log_db->add( $args );
320
321 if ( $log_id && ! empty( $log_meta ) ) {
322 foreach ( (array) $log_meta as $key => $meta ) {
323 if ( ! empty( $meta ) ) {
324 $this->logmeta_db->update_meta( $log_id, '_give_log_' . sanitize_key( $key ), $meta );
325 }
326 }
327 }
328 }
329
330 /**
331 * Fires after updating log entry.
332 *
333 * @since 1.0
334 *
335 * @param int $log_id Log entry id.
336 * @param array $log_data Log entry data.
337 * @param array $log_meta Log entry meta.
338 */
339 do_action( 'give_post_update_log', $log_id, $log_data, $log_meta );
340 }
341
342 /**
343 * Retrieve all connected logs
344 *
345 * Used for retrieving logs related to particular items, such as a specific donation.
346 * For new table params check: Give_DB_Logs::get_column_defaults and Give_DB_Logs::get_sql#L262
347 *
348 * @since 1.0
349 * @since 2.0 Added new table logic.
350 * @access public
351 *
352 * @param array $args Query arguments.
353 *
354 * @return array|false Array if logs were found, false otherwise.
355 */
356 public function get_connected_logs( $args = array() ) {
357 $logs = array();
358
359 $defaults = array(
360 'number' => 20,
361 'paged' => get_query_var( 'paged' ),
362 'log_type' => false,
363
364 // Backward compatibility.
365 'post_type' => 'give_log',
366 'post_status' => 'publish',
367 );
368 $query_args = wp_parse_args( $args, $defaults );
369 $this->bc_200_validate_params( $query_args );
370
371 if ( ! give_has_upgrade_completed( 'v20_logs_upgrades' ) ) {
372 // Backward compatibility.
373 $logs = get_posts( $query_args );
374 $this->bc_200_add_new_properties( $logs );
375 } else {
376 $logs = $this->log_db->get_logs( $query_args );
377 }
378
379 return ( ! empty( $logs ) ? $logs : false );
380 }
381
382 /**
383 * Retrieve Log Count
384 *
385 * Retrieves number of log entries connected to particular object ID.
386 *
387 * @since 1.0
388 * @access public
389 *
390 * @param int $object_id Log object ID. Default is 0.
391 * @param string $type Log type. Default is empty string.
392 * @param array $meta_query Log meta query. Default is null.
393 * @param array $date_query Log data query. Default is null.
394 *
395 * @return int Log count.
396 */
397 public function get_log_count( $object_id = 0, $type = '', $meta_query = null, $date_query = null ) {
398 $logs_count = 0;
399
400 $query_args = array(
401 'number' => - 1,
402
403 // Backward comatibility.
404 'post_type' => 'give_log',
405 'post_status' => 'publish',
406 );
407
408 if ( $object_id ) {
409 $query_args['log_parent'] = $object_id;
410 }
411
412 if ( ! empty( $type ) && $this->valid_type( $type ) ) {
413 $query_args['log_type'] = $type;
414 }
415
416 if ( ! empty( $meta_query ) ) {
417 $query_args['meta_query'] = $meta_query;
418 }
419
420 if ( ! empty( $date_query ) ) {
421 $query_args['date_query'] = $date_query;
422 }
423
424 $this->bc_200_validate_params( $query_args );
425
426 if ( ! give_has_upgrade_completed( 'v20_logs_upgrades' ) ) {
427 // Backward compatibility.
428 $logs = new WP_Query( $query_args );
429 $logs_count = (int) $logs->post_count;
430 } else {
431 $logs_count = $this->log_db->count( $query_args );
432 }
433
434 return $logs_count;
435 }
436
437 /**
438 * Delete Logs
439 *
440 * Remove log entries connected to particular object ID.
441 *
442 * @since 1.0
443 * @access public
444 *
445 * @param int $object_id Log object ID. Default is 0.
446 * @param string $type Log type. Default is empty string.
447 * @param array $meta_query Log meta query. Default is null.
448 *
449 * @return void
450 */
451 public function delete_logs( $object_id = 0, $type = '', $meta_query = null ) {
452 $query_args = array(
453 'log_parent' => $object_id,
454 'number' => - 1,
455 'fields' => 'ID',
456
457 // Backward compatibility.
458 'post_type' => 'give_log',
459 'post_status' => 'publish',
460 );
461
462 if ( ! empty( $type ) && $this->valid_type( $type ) ) {
463 $query_args['log_type'] = $type;
464 }
465
466 if ( ! empty( $meta_query ) ) {
467 $query_args['meta_query'] = $meta_query;
468 }
469
470 $this->bc_200_validate_params( $query_args );
471
472 if ( ! give_has_upgrade_completed( 'v20_logs_upgrades' ) ) {
473 // Backward compatibility.
474 $logs = get_posts( $query_args );
475
476 if ( $logs ) {
477 foreach ( $logs as $log ) {
478 wp_delete_post( $log, true );
479 }
480 }
481 } else {
482 $logs = $this->log_db->get_logs( $query_args );
483
484 if ( $logs ) {
485 foreach ( $logs as $log ) {
486 if ( $this->log_db->delete( $log->ID ) ) {
487 $this->logmeta_db->delete_row( $log->ID );
488 }
489 }
490 }
491 }
492
493 $this->delete_cache();
494 }
495
496 /**
497 * Setup cron to delete log cache in background.
498 *
499 * @since 1.7
500 * @access public
501 *
502 * @param int $post_id
503 */
504 public function background_process_delete_cache( $post_id ) {
505 // Delete log cache immediately
506 wp_schedule_single_event( time() - 5, 'give_delete_log_cache' );
507 }
508
509 /**
510 * Delete all logging cache when form, log or payment updates
511 *
512 * @since 1.7
513 * @access public
514 *
515 * @return bool
516 */
517 public function delete_cache() {
518 // Add log related keys to delete.
519 $cache_give_logs = Give_Cache::get_options_like( 'give_logs' );
520 $cache_give_log_count = Give_Cache::get_options_like( 'log_count' );
521
522 $cache_option_names = array_merge( $cache_give_logs, $cache_give_log_count );
523
524 // Bailout.
525 if ( empty( $cache_option_names ) ) {
526 return false;
527 }
528
529 Give_Cache::delete( $cache_option_names );
530 }
531
532 /**
533 * Validate query params.
534 *
535 * @since 2.0
536 * @access private
537 *
538 * @param array $log_query
539 * @param array $log_meta
540 */
541 private function bc_200_validate_params( &$log_query, &$log_meta = array() ) {
542 $query_params = array(
543 'log_title' => 'post_title',
544 'log_parent' => 'post_parent',
545 'log_content' => 'post_content',
546 'log_type' => 'tax_query',
547 'log_date' => 'post_date',
548 'log_date_gmt' => 'post_date_gmt',
549 'number' => 'posts_per_page',
550 'meta_query' => 'meta_query',
551 );
552
553 if ( ! give_has_upgrade_completed( 'v20_logs_upgrades' ) ) {
554 // Set old params.
555 foreach ( $query_params as $new_query_param => $old_query_param ) {
556
557 if ( isset( $log_query[ $old_query_param ] ) && empty( $log_query[ $new_query_param ] ) ) {
558 $log_query[ $new_query_param ] = $log_query[ $old_query_param ];
559 continue;
560 } elseif ( ! isset( $log_query[ $new_query_param ] ) ) {
561 continue;
562 } elseif( empty( $log_query[ $new_query_param ] ) ) {
563 continue;
564 }
565
566 switch ( $new_query_param ) {
567 case 'log_type':
568 $log_query['tax_query'] = array(
569 array(
570 'taxonomy' => 'give_log_type',
571 'field' => 'slug',
572 'terms' => $log_query[ $new_query_param ],
573 ),
574 );
575 break;
576
577 case 'meta_query':
578 if( ! empty( $log_query['meta_query'] ) && empty( $log_query['post_parent'] ) ) {
579 foreach ( $log_query['meta_query'] as $index => $meta_query ){
580 if( ! is_array( $meta_query ) || empty( $meta_query['key'] ) ) {
581 continue;
582 }
583
584 switch ( $meta_query['key'] ) {
585 case '_give_log_form_id':
586 $log_query['post_parent'] = $meta_query['value'];
587 unset( $log_query['meta_query'][$index] );
588 break;
589 }
590 }
591 }
592 break;
593
594 default:
595 switch( $new_query_param ){
596 case 'log_parent':
597 $log_query['meta_query'][] = array(
598 'key' => '_give_log_payment_id',
599 'value' => $log_query[ $new_query_param ]
600 );
601
602 break;
603
604 default:
605 $log_query[ $old_query_param ] = $log_query[ $new_query_param ];
606 }
607 }
608 }
609 } else {
610 // Set only old params.
611 $query_params = array_flip( $query_params );
612 foreach ( $query_params as $old_query_param => $new_query_param ) {
613 if ( isset( $log_query[ $new_query_param ] ) && empty( $log_query[ $old_query_param ] ) ) {
614 $log_query[ $old_query_param ] = $log_query[ $new_query_param ];
615 continue;
616 } elseif ( ! isset( $log_query[ $old_query_param ] ) ) {
617 continue;
618 }
619
620 switch ( $old_query_param ) {
621 case 'tax_query':
622 if ( isset( $log_query[ $old_query_param ][0]['terms'] ) ) {
623 $log_query[ $new_query_param ] = $log_query[ $old_query_param ][0]['terms'];
624 }
625 break;
626
627 default:
628 $log_query[ $new_query_param ] = $log_query[ $old_query_param ];
629 }
630 }
631 }
632 }
633
634 /**
635 * Set new log properties.
636 *
637 * @since 2.0
638 * @access private
639 *
640 * @param array $logs
641 */
642 private function bc_200_add_new_properties( &$logs ) {
643 if ( empty( $logs ) ) {
644 return;
645 }
646
647 $query_params = array(
648 'log_title' => 'post_title',
649 'log_parent' => 'post_parent',
650 'log_content' => 'post_content',
651 'log_date' => 'post_date',
652 'log_date_gmt' => 'post_date_gmt',
653 'log_type' => 'give_log_type',
654 );
655
656 if ( ! give_has_upgrade_completed( 'v20_logs_upgrades' ) ) {
657 foreach ( $logs as $index => $log ) {
658 foreach ( $query_params as $new_query_param => $old_query_param ) {
659 if ( ! property_exists( $log, $old_query_param ) ) {
660 /**
661 * Set unmatched properties.
662 */
663
664 // 1. log_type
665 $term = get_the_terms( $log->ID, 'give_log_type' );
666 $term = ! is_wp_error( $term ) && ! empty( $term ) ? $term[0] : array();
667
668 $logs[ $index ]->{$new_query_param} = ! empty( $term ) ? $term->slug : '';
669
670 continue;
671 }
672
673 switch ( $old_query_param ) {
674 case 'post_parent':
675 $logs[ $index ]->{$new_query_param} = give_get_meta( $log->ID, '_give_log_payment_id', true );
676 break;
677
678 default:
679 $logs[ $index ]->{$new_query_param} = $log->{$old_query_param};
680 }
681 }
682 }
683 }
684 }
685
686 /**
687 * Change log parent to payment if set to form.
688 *
689 * @since 2.0
690 * @access public
691 *
692 * @param mixed $check
693 * @param int $log_id
694 * @param array $meta_key
695 * @param array $meta_value
696 *
697 * @return mixed
698 */
699 public function bc_200_set_payment_as_log_parent( $check, $log_id, $meta_key, $meta_value ) {
700 global $wpdb;
701 $update_status = false;
702 $post_type = get_post_type( $log_id );
703
704 // Bailout.
705 if (
706 'give_payment' === $post_type ||
707 '_give_log_payment_id' !== $meta_key
708 ) {
709 return $check;
710 }
711
712 $form_id = $wpdb->get_var(
713 $wpdb->prepare(
714 "
715 SELECT log_parent FROM {$this->log_db->table_name}
716 WHERE ID=%d
717 ",
718 $log_id
719 )
720 );
721
722 if ( $form_id ) {
723 $this->logmeta_db->delete_meta( $log_id, '_give_log_payment_id' );
724 $this->logmeta_db->update_meta( $log_id, '_give_log_form_id', $form_id );
725
726 $update_status = $wpdb->update(
727 $this->log_db->table_name,
728 array(
729 'log_parent' => $meta_value,
730 ),
731 array(
732 'ID' => $log_id,
733 ),
734 array(
735 '%s',
736 ),
737 array(
738 '%d',
739 )
740 );
741 }
742
743 return $update_status;
744 }
745 }
746