Skip to content

Commit f887e54

Browse files
committed
use regex for other get_callback_url uses
1 parent 4dc6856 commit f887e54

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

php/Blockonomics.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ private function setup_error($msg) {
493493
private function get_callback_url() {
494494
$callback_secret = get_option("blockonomics_callback_secret");
495495
$api_url = WC()->api_request_url('WC_Gateway_Blockonomics');
496+
// strip language prefix to ensure consistent callback URL across all languages / regions for WPML/ Polylang compatibility
497+
// only do this if prefix appears immediately before /wc-api/ to avoid false positives
498+
$api_url = preg_replace('#/[a-z]{2}(-[a-z]{2})?/wc-api/#i', '/wc-api/', $api_url);
496499
return add_query_arg('secret', $callback_secret, $api_url);
497500
}
498501

php/class-blockonomics-setup.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class Blockonomics_Setup {
1313
private function get_callback_url() {
1414
$callback_secret = get_option('blockonomics_callback_secret');
1515
$api_url = WC()->api_request_url('WC_Gateway_Blockonomics');
16+
// strip WPML/Polylang language prefix (i.e. /de/, /en-us/) to ensure consistent callback URL
17+
// only do this if prefix appears immediately before /wc-api/ to avoid false positives
18+
$api_url = preg_replace('#/[a-z]{2}(-[a-z]{2})?/wc-api/#i', '/wc-api/', $api_url);
1619
return add_query_arg('secret', $callback_secret, $api_url);
1720
}
1821

0 commit comments

Comments
 (0)