| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions to improve compatibility with WooCommerce. |
| 4 |
* |
| 5 |
* @package Charitable/Functions/Compatibility |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2023, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.6.37 |
| 10 |
* @version 1.6.37 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Charitable handles password resets & email verification in the same |
| 20 |
* way that WooCommerce handles password resets, which results in redirects |
| 21 |
* not working the way they're expected to. |
| 22 |
* |
| 23 |
* To avoid this, Charitable adds a query arg of 'charitable' to the |
| 24 |
* reset/email verification link. If that query arg is set, WooCommerce's |
| 25 |
* handler for this kind of request should not be used, instead falling |
| 26 |
* back to Charitable's. |
| 27 |
* |
| 28 |
* @since 1.6.37 |
| 29 |
* |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
function charitable_compat_woocommerce_prevent_wc_reset_redirect() { |
| 33 |
/* This is a password reset. */ |
| 34 |
if ( isset( $_GET['key'] ) && ( isset( $_GET['id'] ) || isset( $_GET['login'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 35 |
if ( isset( $_GET['charitable'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 36 |
remove_action( 'template_redirect', array( 'WC_Form_Handler', 'redirect_reset_password_link' ) ); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
add_action( 'template_redirect', 'charitable_compat_woocommerce_prevent_wc_reset_redirect', 1 ); |
| 42 |
|