← All changes
|
includes/users/class-charitable-donor-consent-log.php
+21
-12
1.6.8
→
1.8.13
View file →
| @@ -2,13 +2,13 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Responsible for getting and updating a donor's consent log. |
| 4 | 4 | * |
| 5 | 5 | * @package Charitable/Classes/Charitable_Donor_Consent_Log |
| 6 | - * @author Eric Daams | |
| 7 | - * @copyright Copyright (c) 2019, Studio 164a | |
| 6 | + * @author David Bisset | |
| 7 | + * @copyright Copyright (c) 2023, WP Charitable LLC | |
| 8 | 8 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 | 9 | * @since 1.6.0 |
| 10 | - * @version 1.6.0 | |
| 10 | + * @version 1.6.57 | |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | // Exit if accessed directly. |
| 14 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -63,23 +63,32 @@ | ||
| 63 | 63 | * @return int|boolean Meta ID if the key didn't exist, true on successful update, |
| 64 | 64 | * false on failure or if the log has not changed. |
| 65 | 65 | */ |
| 66 | 66 | public function add( $consent_given, $consent_statement ) { |
| 67 | - $log = $this->get_log(); | |
| 68 | - $last_log = end( $log ); | |
| 69 | - $consent_changed = $last_log['consent_given'] != $consent_given; | |
| 70 | - $statement_changed = $last_log['statement'] != $consent_statement; | |
| 67 | + $log = $this->get_log(); | |
| 68 | + $last_log = end( $log ); | |
| 71 | 69 | |
| 70 | + if ( is_array( $last_log ) ) { | |
| 71 | + $consent_changed = $last_log['consent_given'] !== $consent_given; | |
| 72 | + $statement_changed = $last_log['statement'] !== $consent_statement; | |
| 73 | + } else { | |
| 74 | + $consent_changed = true; | |
| 75 | + $statement_changed = true; | |
| 76 | + } | |
| 77 | + | |
| 72 | 78 | /* Neither the consent nor the statement has changed. */ |
| 73 | 79 | if ( ! $consent_changed && ! $statement_changed ) { |
| 74 | 80 | return false; |
| 75 | 81 | } |
| 76 | 82 | |
| 77 | - array_push( $log, array( | |
| 78 | - 'time' => time(), | |
| 79 | - 'consent_given' => $consent_given, | |
| 80 | - 'statement' => $consent_statement, | |
| 81 | - ) ); | |
| 83 | + array_push( | |
| 84 | + $log, | |
| 85 | + array( | |
| 86 | + 'time' => time(), | |
| 87 | + 'consent_given' => $consent_given, | |
| 88 | + 'statement' => $consent_statement, | |
| 89 | + ) | |
| 90 | + ); | |
| 82 | 91 | |
| 83 | 92 | $ret = update_metadata( 'donor', $this->donor_id, 'consent_log', $log ); |
| 84 | 93 | |
| 85 | 94 | /* Clear the meta_log */ |