-
Notifications
You must be signed in to change notification settings - Fork 834
WooCommerce Analytics: Add proxy speed module to enhance proxy API performance #45243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+161
−0
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2b00936
Add proxy speed module to WooCommerce Analytics
chihsuan a1d4052
Enhance WooCommerce Analytics proxy speed module integration
chihsuan 2868677
changelog
chihsuan ef18385
Improve WooCommerceAnalyticsProxySpeed
chihsuan 3e2273b
Add changelog
chihsuan cc717e6
Update projects/packages/woocommerce-analytics/src/class-woocommerce-…
chihsuan b0ad9c0
Update projects/packages/woocommerce-analytics/src/class-woocommerce-…
chihsuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/woocommerce-analytics/changelog/add-wca-proxy-speed-module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add proxy speed module to enhance proxy API performance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...packages/woocommerce-analytics/src/mu-plugin/woocommerce-analytics-proxy-speed-module.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName | ||
/** | ||
* Plugin Name: WooCommerce Analytics - Proxy Speed Module | ||
* Description: Speeds up WooCommerce Analytics' proxy for avoiding ad blockers. | ||
* Plugin URI: https://woocommerce.com | ||
* Author: WooCommerce | ||
* Version: 1.0.0 | ||
* Author URI: https://woocommerce.com | ||
* | ||
* Text Domain: woocommerce-analytics | ||
* | ||
* Inspired by: https://github.com/plausible/wordpress/blob/092b97b247f45bf347ae32f9614f20a81d9e10c0/mu-plugin/plausible-proxy-speed-module.php | ||
*/ | ||
class WooCommerceAnalyticsProxySpeed { | ||
/** | ||
* Path of the proxy request. | ||
* | ||
* @var string | ||
*/ | ||
const PROXY_REQUEST_PATH = 'woocommerce-analytics/v1/track'; | ||
|
||
/** | ||
* Allowed plugin files for proxy request. | ||
* | ||
* @var array | ||
*/ | ||
private $allowed_plugin_files = array( 'woocommerce.php', 'woocommerce-analytics.php', 'jetpack.php' ); | ||
|
||
/** | ||
* Add filters and actions. | ||
* | ||
* @return void | ||
*/ | ||
public function init() { | ||
add_filter( 'option_active_plugins', array( $this, 'filter_active_plugins' ) ); | ||
} | ||
|
||
/** | ||
* Filter the list of active plugins for custom endpoint requests. | ||
* | ||
* @param array $active_plugins The list of active plugins. | ||
* | ||
* @return array The filtered list of active plugins. | ||
*/ | ||
public function filter_active_plugins( $active_plugins ) { | ||
if ( ! $this->is_proxy_request() || ! is_array( $active_plugins ) ) { | ||
return $active_plugins; | ||
} | ||
|
||
$filtered_plugins = array(); | ||
|
||
foreach ( $active_plugins as $plugin ) { | ||
foreach ( $this->allowed_plugin_files as $allowed_plugin_file ) { | ||
if ( strpos( $plugin, $allowed_plugin_file ) !== false ) { | ||
$filtered_plugins[] = $plugin; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return $filtered_plugins; | ||
} | ||
|
||
/** | ||
* Helper method to retrieve Request URI. Checks several globals. | ||
* | ||
* @return mixed | ||
*/ | ||
private function get_request_uri() { | ||
return isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | ||
} | ||
|
||
/** | ||
* Check if current request is a proxy request. | ||
* | ||
* @return bool | ||
*/ | ||
private function is_proxy_request() { | ||
return strpos( $this->get_request_uri(), self::PROXY_REQUEST_PATH ) !== false; | ||
} | ||
} | ||
|
||
( new WooCommerceAnalyticsProxySpeed() )->init(); |
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-wca-proxy-speed-module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: other | ||
|
||
Integrate calls to add and remove the proxy speed module in Jetpack plugin initialization and deactivation processes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.