Skip to content

Commit

Permalink
Fixed a bug where the admin request checks failed when Wordpress is i…
Browse files Browse the repository at this point in the history
…nstalled in a subdirectory
  • Loading branch information
Paulsky committed Nov 4, 2024
1 parent 5b5744c commit 7717773
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
All notable changes to the Tax Switch for Woocommerce plugin will be documented in this file.

## [1.1.9] - 2024-11-04
### Added
- Extra check for filtering backend and frontend AJAX requests (which adds compatibility for [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)).
### Updated
- Fixed a bug where the admin request checks failed when Wordpress is installed in a subdirectory.

## [1.1.8] - 2024-10-25
### Added
- Compatibility for YITH WooCommerce Product Add-ons & Extra Options Premium
Expand Down
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: wijnbergdevelopments
Tags: woocommerce, tax, vat
Requires at least: 5.0
Tested up to: 6.6
Stable tag: 1.1.8
Stable tag: 1.1.9
Requires PHP: 7.2
License: GPL-2.0+
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
Expand Down Expand Up @@ -77,6 +77,9 @@ You can also use this shortcode in your theme files with the do_shortcode() func
Some WooCommerce Blocks are not fully compatible with this plugin as they do not use standard WooCommerce filters for price display. This is a known limitation of WooCommerce Blocks and not specific to this plugin. You can fix this by using WooCommerce shortcodes instead of the WooCommerce Blocks.

== Changelog ==
= 1.1.9 =
* Added extra check for filtering backend and frontend AJAX requests (which adds compatibility for [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/))
* Fixed a bug where the admin request checks failed when Wordpress is installed in a subdirectory

= 1.1.8 =
* Added compatibility for YITH WooCommerce Product Add-ons & Extra Options Premium
Expand Down
2 changes: 1 addition & 1 deletion block/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "wdevs/tax-switch",
"version": "1.1.8",
"version": "1.1.9",
"title": "Tax Switch for WooCommerce",
"category": "woocommerce",
"icon": "money-alt",
Expand Down
3 changes: 2 additions & 1 deletion block/src/compatibility/ProductAddOns.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class ProductAddOns {
}
}
}
vm.handlePriceUpdate();
}
vm.handlePriceUpdate();
}
}, 10 );
}
Expand Down Expand Up @@ -132,6 +132,7 @@ class ProductAddOns {

handlePriceUpdate() {
const elements = {
productPrice: jQuery( '#wapo-total-product-price' ),
options: jQuery( '#wapo-total-options-price' ),
order: jQuery( '#wapo-total-order-price' ),
};
Expand Down
37 changes: 34 additions & 3 deletions includes/class-wdevs-tax-switch.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,16 @@ private function is_admin_request() {
/**
* Get current URL.
*
* @link https://wordpress.stackexchange.com/a/126534
* @link https://wordpress.stackexchange.com/a/237498/178511
*/
$current_url = home_url( add_query_arg( null, null ) );
$parts = parse_url(home_url());
$current_url = $parts['scheme'] . '://' . $parts['host'];

if (array_key_exists('port', $parts)) {
$current_url .= ':' . $parts['port'];
}

$current_url .= add_query_arg([]);

/**
* Get admin URL and referrer.
Expand All @@ -389,7 +396,7 @@ private function is_admin_request() {
if ( 0 === strpos( $referrer, $admin_url ) ) {
return true;
} else {
return ! $this->is_doing_ajax();
return ! $this->is_frontend_ajax_request();
}
} else {
return false;
Expand All @@ -411,4 +418,28 @@ private function is_doing_ajax() {
}
}

/**
* @return bool
* @since 1.1.9
*/
private function is_frontend_ajax_request() {

$script_filename = isset( $_SERVER['SCRIPT_FILENAME'] ) ? $_SERVER['SCRIPT_FILENAME'] : '';

if ( $this->is_doing_ajax() ) {
$referrer_raw = wp_get_raw_referer();
if ( $referrer_raw === false ) {
return false;
}

//If referer does not contain admin URL and we are using the admin-ajax.php endpoint, this is likely a frontend AJAX request
if ( ( ( strpos( $referrer_raw, admin_url() ) === false ) && ( basename( $script_filename ) === 'admin-ajax.php' ) ) ) {
return true;
}
}

//If no checks triggered, we end up here - not an AJAX request.
return false;
}

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wdevs-tax-switch",
"version": "1.1.8",
"version": "1.1.9",
"description": "Let customers toggle between inclusive and exclusive VAT pricing in your WooCommerce store.",
"author": "Wijnberg Developments",
"license": "GPL-2.0-or-later",
Expand Down
4 changes: 2 additions & 2 deletions wdevs-tax-switch.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Plugin Name: Tax Switch for WooCommerce
* Plugin URI: https://wijnberg.dev
* Description: Let customers toggle between inclusive and exclusive VAT pricing in your WooCommerce store.
* Version: 1.1.8
* Version: 1.1.9
* Author: Wijnberg Developments
* Author URI: https://wijnberg.dev/
* License: GPL-2.0+
Expand All @@ -41,7 +41,7 @@
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'WDEVS_TAX_SWITCH_VERSION', '1.1.8' );
define( 'WDEVS_TAX_SWITCH_VERSION', '1.1.9' );

/**
* The code that runs during plugin activation.
Expand Down

0 comments on commit 7717773

Please sign in to comment.