Test Failed
Push — release/1.8.12 ( b58a2f...d255b1 )
by Ravinder
375:09 queued 372:17
created

templates/shortcode-receipt.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This template is used to display the donation summary with [give_receipt]
4
 */
5
6
global $give_receipt_args, $payment;
7
8
// Validation: Ensure $payment var is set.
9
if ( empty( $payment ) ) {
10
	$payment = ! empty( $give_receipt_args['id'] ) ? get_post( $give_receipt_args['id'] ) : 0;
11
}
12
13
// Double-Validation: Check for $payment global.
14
if ( empty( $payment ) ) {
15
	Give()->notices->print_frontend_notice( __( 'The specified receipt ID appears to be invalid.', 'give' ) );
16
17
	return;
18
}
19
20
$donation_id    = $payment->ID;
21
$form_id        = give_get_payment_meta( $donation_id, '_give_payment_form_id', true );
22
$meta           = give_get_payment_meta( $donation_id );
23
$donation       = give_get_payment_form_title( $meta );
24
$user           = give_get_payment_meta_user_info( $donation_id );
25
$email          = give_get_payment_user_email( $donation_id );
26
$status         = $payment->post_status;
27
$status_label   = give_get_payment_status( $payment, true );
28
29
/**
30
 * Generate Donation Receipt Arguments.
31
 *
32
 * Added donation receipt array to global variable $give_receipt_args to manage it from single variable
33
 *
34
 * @since 1.8.8
35
 */
36
$give_receipt_args['donation_receipt']['donor'] = array(
37
	'name'      => __( 'Donor', 'give' ),
38
	'value'     => $user['first_name'] . ' ' . $user['last_name'],
0 ignored issues
show
Expected next thing to be a escaping function, not '$user'
Loading history...
39
	'display'   => $give_receipt_args['donor'],
40
);
41
42
$give_receipt_args['donation_receipt']['date'] = array(
43
	'name'      => __( 'Date', 'give' ),
44
	'value'     => date_i18n( give_date_format(), strtotime( $meta['date'] ) ),
45
	'display'   => $give_receipt_args['date'],
46
);
47
48
$give_receipt_args['donation_receipt']['total_donation'] = array(
49
	'name'      => __( 'Total Donation', 'give' ),
50
	'value'     => give_payment_amount( $donation_id ),
51
	'display'   => true,
52
);
53
54
$give_receipt_args['donation_receipt']['donation'] = array(
55
	'name'      => __( 'Donation', 'give' ),
56
	'value'     => $donation,
57
	'display'   => true,
58
);
59
60
$give_receipt_args['donation_receipt']['donation_status'] = array(
61
	'name'      => __( 'Donation Status', 'give' ),
62
	'value'     => esc_attr( $status ),
63
	'display'   => $give_receipt_args['payment_status'],
64
);
65
66
$give_receipt_args['donation_receipt']['donation_id'] = array(
67
	'name'      => __( 'Donation ID', 'give' ),
68
	'value'     => $donation_id,
69
	'display'   => ($give_receipt_args['payment_id'])?true:false,
70
);
71
72
$give_receipt_args['donation_receipt']['payment_details'] = array(
73
	'name'      => __( 'Payment:', 'give' ),
74
	'value'     => __( 'Details:', 'give' ),
75
	'display'   => ($give_receipt_args['payment_id'])?false:true,
76
);
77
78
$give_receipt_args['donation_receipt']['payment_key'] = array(
79
	'name'      => __( 'Payment Key', 'give' ),
80
	'value'     => get_post_meta( $donation_id, '_give_payment_purchase_key', true ),
81
	'display'   => $give_receipt_args['payment_key'],
82
);
83
84
$give_receipt_args['donation_receipt']['payment_method'] = array(
85
	'name'      => __( 'Payment Method', 'give' ),
86
	'value'     => give_get_gateway_checkout_label( give_get_payment_gateway( $donation_id ) ),
87
	'display'   => true,
88
);
89
90
/**
91
 * Extend Give Donation Receipt
92
 *
93
 * You can easily extend the donation receipt argument using the filter give_donation_receipt_args
94
 *
95
 * @params array $give_receipt_args['donation_receipt'] Array of arguments for Donation Receipt.
96
 * @params int   $donation_id                           Donation ID.
97
 * @params int   $form_id                               Donation Form ID.
98
 *
99
 * @since 1.8.8
100
 */
101
$give_receipt_args['donation_receipt'] = apply_filters( 'give_donation_receipt_args', $give_receipt_args['donation_receipt'], $donation_id, $form_id );
102
103
// Show payment status notice based on shortcode attribute.
104
if ( filter_var( $give_receipt_args['status_notice'], FILTER_VALIDATE_BOOLEAN ) ) {
105
	$notice_message = '';
106
	$notice_type    = 'warning';
107
108
	switch ( $status ) {
109
		case 'publish':
110
			$notice_message = __( 'Payment Complete: Thank you for your donation.', 'give' );
111
			$notice_type    = 'success';
112
			break;
113
		case 'pending':
114
			$notice_message = __( 'Payment Pending: Your donation is currently processing.', 'give' );
115
			$notice_type    = 'warning';
116
			break;
117
		case 'refunded':
118
			$notice_message = __( 'Payment Refunded: Your donation has been refunded.', 'give' );
119
			$notice_type    = 'warning';
120
			break;
121
		case 'preapproval':
122
			$notice_message = __( 'Payment Preapproved: Thank you for your donation.', 'give' );
123
			$notice_type    = 'warning';
124
			break;
125
		case 'failed':
126
			$notice_message = __( 'Payment Failed: Please contact the site owner for assistance.', 'give' );
127
			$notice_type    = 'error';
128
			break;
129
		case 'cancelled':
130
			$notice_message = __( 'Payment Cancelled: Your donation has been cancelled.', 'give' );
131
			$notice_type    = 'error';
132
			break;
133
		case 'abandoned':
134
			$notice_message = __( 'Payment Abandoned: This donation has not been completed.', 'give' );
135
			$notice_type    = 'error';
136
			break;
137
		case 'revoked':
138
			$notice_message = __( 'Payment Revoked: Please contact the site owner for assistance.', 'give' );
139
			$notice_type    = 'error';
140
			break;
141
	}
142
143
	if ( ! empty( $notice_message ) ) {
144
		/**
145
		 * Filters payment status notice for receipts.
146
		 *
147
		 * By default, a success, warning, or error notice appears on the receipt
148
		 * with payment status. This filter allows the HTML markup
149
		 * and messaging for that notice to be customized.
150
		 *
151
		 * @since 1.0
152
		 *
153
		 * @param string $notice HTML markup for the default notice.
154
		 * @param int    $id     Post ID where the notice is displayed.
155
		 * @param string $status Payment status.
156
		 * @param array  $meta   Array of meta data related to the payment.
157
		 */
158
		echo apply_filters( 'give_receipt_status_notice', Give()->notices->print_frontend_notice( $notice_message, false, $notice_type ), $id, $status, $meta );
0 ignored issues
show
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
159
	}
160
}// End if().
161
162
/**
163
 * Fires in the payment receipt shortcode, before the receipt main table.
164
 *
165
 * Allows you to add elements before the table.
166
 *
167
 * @since 1.0
168
 *
169
 * @param object $payment           The payment object.
170
 * @param array  $give_receipt_args Receipt_argument.
171
 */
172
do_action( 'give_payment_receipt_before_table', $payment, $give_receipt_args );
173
?>
174
175
	<table id="give_donation_receipt" class="give-table">
176
		<thead>
177
		<?php
178
		/**
179
		 * Fires in the payment receipt shortcode, before the receipt first header item.
180
		 *
181
		 * Allows you to add new <th> elements before the receipt first header item.
182
		 *
183
		 * @since 1.7
184
		 *
185
		 * @param object $payment           The payment object.
186
		 * @param array  $give_receipt_args Receipt_argument.
187
		 */
188
		do_action( 'give_payment_receipt_header_before', $payment, $give_receipt_args );
189
		?>
190
		<tr>
191
			<th scope="colgroup" colspan="2">
192
				<span class="give-receipt-thead-text"><?php esc_html_e( 'Donation Receipt', 'give' ) ?></span>
193
			</th>
194
		</tr>
195
		<?php
196
		/**
197
		 * Fires in the payment receipt shortcode, after the receipt last header item.
198
		 *
199
		 * Allows you to add new <th> elements after the receipt last header item.
200
		 *
201
		 * @since 1.7
202
		 *
203
		 * @param object $payment           The payment object.
204
		 * @param array  $give_receipt_args Receipt_argument.
205
		 */
206
		do_action( 'give_payment_receipt_header_after', $payment, $give_receipt_args );
207
		?>
208
		</thead>
209
210
		<tbody>
211
		<?php
212
		/**
213
		 * Fires in the payment receipt shortcode, before the receipt first item.
214
		 *
215
		 * Allows you to add new <td> elements before the receipt first item.
216
		 *
217
		 * @since 1.7
218
		 *
219
		 * @param object $payment           The payment object.
220
		 * @param array  $give_receipt_args Receipt_argument.
221
		 */
222
		do_action( 'give_payment_receipt_before', $payment, $give_receipt_args );
223
		?>
224
225
		<?php foreach ( $give_receipt_args['donation_receipt'] as $receipt_item ) { ?>
226
			<?php if ( filter_var( $receipt_item['display'], FILTER_VALIDATE_BOOLEAN ) ) : ?>
227
			<tr>
228
				<td scope="row"><strong><?php echo $receipt_item['name']; ?></strong></td>
0 ignored issues
show
Expected next thing to be a escaping function, not '$receipt_item'
Loading history...
229
				<td><?php echo $receipt_item['value']; ?></td>
0 ignored issues
show
Expected next thing to be a escaping function, not '$receipt_item'
Loading history...
230
			</tr>
231
			<?php endif; ?>
232
		<?php } ?>
233
234
		<?php
235
		/**
236
		 * Fires in the payment receipt shortcode, after the receipt last item.
237
		 *
238
		 * Allows you to add new <td> elements after the receipt last item.
239
		 *
240
		 * @since 1.7
241
		 *
242
		 * @param object $payment           The payment object.
243
		 * @param array  $give_receipt_args Receipt_argument.
244
		 */
245
		do_action( 'give_payment_receipt_after', $payment, $give_receipt_args );
246
		?>
247
		</tbody>
248
	</table>
249
250
<?php
251
/**
252
 * Fires in the payment receipt shortcode, after the receipt main table.
253
 *
254
 * Allows you to add elements after the table.
255
 *
256
 * @since 1.7
257
 *
258
 * @param object $payment           The payment object.
259
 * @param array  $give_receipt_args Receipt_argument.
260
 */
261
do_action( 'give_payment_receipt_after_table', $payment, $give_receipt_args );
262
?>
263