Skip to content

Commit 3af1ea7

Browse files
authored
fix: avoid redeclaration of global function (#2264)
* fix: avoid redeclaration of global function * chore: remove unnecessary <?
1 parent be0b57e commit 3af1ea7

File tree

1 file changed

+52
-56
lines changed

1 file changed

+52
-56
lines changed

src/modal-checkout/templates/thankyou.php

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -29,63 +29,59 @@
2929
* order-received.php template with an order details summary so the experience
3030
* matches whether or not the email address used is already associated with an
3131
* existing customer account.
32+
* phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
3233
*/
33-
function newspack_blocks_replace_login_with_order_summary() {
34-
$order = isset( $_GET['order_id'] ) ? \wc_get_order( \absint( \wp_unslash( $_GET['order_id'] ) ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
35-
$key = isset( $_GET['key'] ) ? \wc_clean( \sanitize_text_field( \wp_unslash( $_GET['key'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
36-
$is_valid = $order && is_a( $order, 'WC_Order' ) && hash_equals( $order->get_order_key(), $key ); // Validate order key to prevent CSRF.
34+
$key = isset( $_GET['key'] ) ? \wc_clean( \sanitize_text_field( \wp_unslash( $_GET['key'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
35+
$is_valid = $order && is_a( $order, 'WC_Order' ) && hash_equals( $order->get_order_key(), $key ); // Validate order key to prevent CSRF.
3736

38-
if ( ! $is_valid ) {
39-
return;
40-
}
41-
42-
$is_success = ! $order->has_status( 'failed' );
43-
$after_success_behavior = isset( $_GET['after_success_behavior'] ) ? \sanitize_text_field( \wp_unslash( $_GET['after_success_behavior'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
44-
$after_success_url = isset( $_GET['after_success_url'] ) ? esc_url( \sanitize_url( \wp_unslash( $_GET['after_success_url'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
45-
$after_success_label = isset( $_GET['after_success_button_label'] ) ? \sanitize_text_field( \wp_unslash( $_GET['after_success_button_label'] ) ) : \Newspack_Blocks\Modal_Checkout::get_modal_checkout_labels( 'after_success' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
46-
$checkout_data = Checkout_Data::get_checkout_data( $order );
47-
?>
48-
<div class="woocommerce-order">
49-
<?php if ( $is_success ) : ?>
50-
<div class="newspack-ui__box newspack-ui__box--success newspack-ui__box--text-center">
51-
<span class="newspack-ui__icon newspack-ui__icon--success">
52-
<?php // TODO: Replace with newspack-ui icons when available. ?>
53-
<svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
54-
<path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path>
55-
</svg>
56-
</span>
57-
<p id="modal-checkout-product-details" data-checkout='<?php echo wp_json_encode( $checkout_data ); ?>'>
58-
<strong>
59-
<?php
60-
echo esc_html( Modal_Checkout::get_post_checkout_success_text() );
61-
?>
62-
</strong>
63-
</p>
64-
</div>
65-
<form>
66-
<?php if ( $after_success_behavior ) : ?>
67-
<input type="hidden" name="after_success_behavior" value="<?php echo esc_attr( $after_success_behavior ); ?>">
68-
<?php endif; ?>
69-
<?php if ( $after_success_behavior ) : ?>
70-
<input type="hidden" name="after_success_url" value="<?php echo esc_attr( $after_success_url ); ?>">
71-
<?php endif; ?>
72-
<button class="newspack-ui__button newspack-ui__button--primary newspack-ui__button--wide" id="checkout-after-success" onclick="parent.newspackCloseModalCheckout();">
73-
<?php echo esc_html( $after_success_label ); ?>
74-
</button>
75-
</form>
76-
<?php else : ?>
77-
<div class="newspack-ui__box newspack-ui__box__error newspack-ui__box--text-center">
78-
<p>
79-
<?php esc_html_e( 'Unfortunately your order cannot be processed. Please attempt your purchase again.', 'newspack-blocks' ); ?>
80-
</p>
81-
</div>
82-
<a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="newspack-blocks-ui__button newspack-ui__button--primary newspack-ui__button--wide"><?php esc_html_e( 'Pay', 'newspack-blocks' ); ?></a>
83-
<?php if ( is_user_logged_in() ) : ?>
84-
<a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>" class="newspack-blocks-ui__button newspack-ui__button--ghost newspack-ui__button--wide"><?php esc_html_e( 'My account', 'newspack-blocks' ); ?></a>
85-
<?php endif; ?>
86-
<?php
87-
endif;
88-
do_action( 'newpack_blocks_modal_checkout_thankyou' );
37+
if ( ! $is_valid ) {
38+
return;
8939
}
9040

91-
newspack_blocks_replace_login_with_order_summary();
41+
$is_success = ! $order->has_status( 'failed' );
42+
$after_success_behavior = isset( $_GET['after_success_behavior'] ) ? \sanitize_text_field( \wp_unslash( $_GET['after_success_behavior'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
43+
$after_success_url = isset( $_GET['after_success_url'] ) ? esc_url( \sanitize_url( \wp_unslash( $_GET['after_success_url'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
44+
$after_success_label = isset( $_GET['after_success_button_label'] ) ? \sanitize_text_field( \wp_unslash( $_GET['after_success_button_label'] ) ) : \Newspack_Blocks\Modal_Checkout::get_modal_checkout_labels( 'after_success' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
45+
$checkout_data = Checkout_Data::get_checkout_data( $order );
46+
?>
47+
<div class="woocommerce-order">
48+
<?php if ( $is_success ) : ?>
49+
<div class="newspack-ui__box newspack-ui__box--success newspack-ui__box--text-center">
50+
<span class="newspack-ui__icon newspack-ui__icon--success">
51+
<?php // TODO: Replace with newspack-ui icons when available. ?>
52+
<svg aria-hidden="true" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
53+
<path d="M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"></path>
54+
</svg>
55+
</span>
56+
<p id="modal-checkout-product-details" data-checkout='<?php echo wp_json_encode( $checkout_data ); ?>'>
57+
<strong>
58+
<?php
59+
echo esc_html( Modal_Checkout::get_post_checkout_success_text() );
60+
?>
61+
</strong>
62+
</p>
63+
</div>
64+
<form>
65+
<?php if ( $after_success_behavior ) : ?>
66+
<input type="hidden" name="after_success_behavior" value="<?php echo esc_attr( $after_success_behavior ); ?>">
67+
<?php endif; ?>
68+
<?php if ( $after_success_behavior ) : ?>
69+
<input type="hidden" name="after_success_url" value="<?php echo esc_attr( $after_success_url ); ?>">
70+
<?php endif; ?>
71+
<button class="newspack-ui__button newspack-ui__button--primary newspack-ui__button--wide" id="checkout-after-success" onclick="parent.newspackCloseModalCheckout();">
72+
<?php echo esc_html( $after_success_label ); ?>
73+
</button>
74+
</form>
75+
<?php else : ?>
76+
<div class="newspack-ui__box newspack-ui__box__error newspack-ui__box--text-center">
77+
<p>
78+
<?php esc_html_e( 'Unfortunately your order cannot be processed. Please attempt your purchase again.', 'newspack-blocks' ); ?>
79+
</p>
80+
</div>
81+
<a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="newspack-blocks-ui__button newspack-ui__button--primary newspack-ui__button--wide"><?php esc_html_e( 'Pay', 'newspack-blocks' ); ?></a>
82+
<?php if ( is_user_logged_in() ) : ?>
83+
<a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>" class="newspack-blocks-ui__button newspack-ui__button--ghost newspack-ui__button--wide"><?php esc_html_e( 'My account', 'newspack-blocks' ); ?></a>
84+
<?php endif; ?>
85+
<?php
86+
endif;
87+
do_action( 'newpack_blocks_modal_checkout_thankyou' );

0 commit comments

Comments
 (0)