PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 All 211 releases
← All changes | includes/admin/reports/class-charitable-export-donations.php +61 -5 1.7.0.2 → 1.8.13 View file →
@@ -3,9 +3,9 @@
3 3 * Class that is responsible for generating a CSV export of donations.
4 4 *
5 5 * @package Charitable/Classes/Charitable_Export_Donations
6 6 * @author David Bisset
7 - * @copyright Copyright (c) 2022, WP Charitable LLC
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.0.0
10 10 * @version 1.6.45
11 11 */
@@ -63,11 +63,21 @@
63 63 */
64 64 protected $donations = array();
65 65
66 66 /**
67 + * Format money fields.
68 + *
69 + * @since 1.8.1.4
70 + *
71 + * @var mixed[]
72 + */
73 + protected $format_money_fields = array();
74 +
75 + /**
67 76 * Create class object.
68 77 *
69 78 * @since 1.0.0
79 + * @since 1.8.1.4 Added formatting money fields.
70 80 *
71 81 * @param mixed[] $args Arguments for the report.
72 82 */
73 83 public function __construct( $args ) {
@@ -80,12 +90,58 @@
80 90
81 91 $this->statuses = charitable_get_valid_donation_statuses();
82 92 $this->fields = array_map( array( $this, 'get_field_label' ), charitable()->donation_fields()->get_export_fields() );
83 93
94 + add_filter( 'charitable_export_data_key_value', array( $this, 'suppliment_charitable_export_data' ), 10, 3 );
95 +
96 + $this->format_money_fields = apply_filters(
97 + 'charitable_export_donations_format_money_fields',
98 + array(
99 + 'amount',
100 + 'subtotal',
101 + 'total',
102 + 'total_donation_with_fees',
103 + )
104 + );
105 +
84 106 parent::__construct( $args );
85 107 }
86 108
87 109 /**
110 + * Suppliments the data exported for campaigns with custom field data.
111 + *
112 + * @param mixed[]|false $custom_field_data Optional. Custom field data to add to the exported data. Default false.
113 + * @param string|false $key Optional. The key to use for the custom field data. Default false.
114 + * @param mixed[] $data Optional. The exported data. Default empty array.
115 + *
116 + * @return mixed[] The exported data with custom field data added.
117 + */
118 + public function suppliment_charitable_export_data( $custom_field_data = false, $key = false, $data = array() ) {
119 +
120 + if ( in_array( $key, $this->format_money_fields, true ) ) {
121 + /*
122 + * Core 'subtotal' and 'total' have no value_callback, so they arrive here as
123 + * raw database amounts (period as the decimal separator, e.g. "101.78"). Other
124 + * money fields ('amount', and addon-provided totals such as Fee Relief's
125 + * 'total_donation_with_fees') arrive already localized. On comma-decimal locales,
126 + * running a raw DB amount through charitable_format_money() without the db_format
127 + * flag makes the "." read as a thousands separator and get stripped
128 + * (101.78 -> "10 178,00"). So pass db_format = true only for the raw DB amounts.
129 + */
130 + $db_format_fields = apply_filters(
131 + 'charitable_export_donations_db_format_money_fields',
132 + array( 'subtotal', 'total' )
133 + );
134 + $db_format = in_array( $key, $db_format_fields, true );
135 +
136 + return html_entity_decode( trim( charitable_format_money( $custom_field_data, false, $db_format ) ) );
137 + }
138 +
139 + return $custom_field_data;
140 + }
141 +
142 +
143 + /**
88 144 * Filter the date and time fields.
89 145 *
90 146 * @since 1.0.0
91 147 *
@@ -187,13 +243,13 @@
187 243 protected function get_data() {
188 244 $query_args = array();
189 245
190 246 if ( strlen( $this->args['start_date'] ) ) {
191 - $query_args['start_date'] = charitable_sanitize_date( $this->args['start_date'], 'Y-m-d 00:00:00' );
247 + $query_args['start_date'] = charitable_sanitize_date_alt_format( $this->args['start_date'], 'Y-m-d 00:00:00' );
192 248 }
193 249
194 250 if ( strlen( $this->args['end_date'] ) ) {
195 - $query_args['end_date'] = charitable_sanitize_date( $this->args['end_date'], 'Y-m-d 23:59:59' );
251 + $query_args['end_date'] = charitable_sanitize_date_alt_format( $this->args['end_date'], 'Y-m-d 23:59:59' );
196 252 }
197 253
198 254 if ( 'all' !== $this->args['campaign_id'] ) {
199 255 $query_args['campaign_id'] = $this->args['campaign_id'];
@@ -198,9 +254,9 @@
198 254 if ( 'all' !== $this->args['campaign_id'] ) {
199 255 $query_args['campaign_id'] = $this->args['campaign_id'];
200 256 }
201 257
202 - if ( 'all' != $this->args['status'] ) {
258 + if ( 'all' !== $this->args['status'] ) {
203 259 $query_args['status'] = $this->args['status'];
204 260 }
205 261
206 262 /**
@@ -209,9 +265,9 @@
209 265 * @deprecated 1.7.0
210 266 *
211 267 * @since 1.3.5
212 268 */
213 - $query_args = apply_filters( 'chairtable_export_donations_query_args', $query_args, $this->args );
269 + $query_args = apply_filters( 'chairtable_export_donations_query_args', $query_args, $this->args ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- 'chairtable_export_donations_query_args' is a legacy hook (note: typo in hook name) that cannot be renamed.
214 270
215 271 /**
216 272 * Filter donations query arguments.
217 273 *