| Server IP : 167.99.224.18 / Your IP : 216.73.216.136 Web Server : Apache/2.4.41 (Ubuntu) System : Linux wordpress-ubuntu-s-1vcpu-1gb-nyc1-01 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.0.25 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins-old/plausible-analytics/src/ |
Upload File : |
<?php
/**
* Plausible Analytics | Compatibility.
*
* @since 1.2.5
* @package WordPress
* @subpackage Plausible Analytics
*/
namespace Plausible\Analytics\WP;
use Exception;
/**
* @codeCoverageIgnore Because this is to be tested in a headless browser.
*/
class Compatibility {
/**
* A list of filters and actions to prevent our script from being manipulated by other plugins, known to cause issues.
* Our script is already <1KB, so there's no need to minify, combine or optimize it in any other way.
*
* @return void
*/
public function __construct() {
// Autoptimize
if ( defined( 'AUTOPTIMIZE_PLUGIN_VERSION' ) ) {
add_filter( 'autoptimize_filter_js_exclude', [ $this, 'exclude_plausible_js_as_string' ] );
}
// LiteSpeed Cache
if ( defined( 'LSCWP_V' ) ) {
add_filter( 'litespeed_optimize_js_excludes', [ $this, 'exclude_plausible_js' ] );
add_filter( 'litespeed_optm_js_defer_exc', [ $this, 'exclude_plausible_inline_js' ] );
add_filter( 'litespeed_optm_gm_js_exc', [ $this, 'exclude_plausible_inline_js' ] );
}
// SG Optimizer
if ( defined( '\SiteGround_Optimizer\VERSION' ) ) {
add_filter( 'sgo_javascript_combine_exclude', [ $this, 'exclude_js_by_handle' ] );
add_filter( 'sgo_js_minify_exclude', [ $this, 'exclude_js_by_handle' ] );
add_filter( 'sgo_js_async_exclude', [ $this, 'exclude_js_by_handle' ] );
add_filter( 'sgo_javascript_combine_excluded_inline_content', [ $this, 'exclude_plausible_inline_js' ] );
add_filter( 'sgo_javascript_combine_excluded_external_paths', [ $this, 'exclude_plausible_js' ] );
}
// WPML
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
add_filter( 'rest_url', [ $this, 'wpml_compatibility' ], 10, 1 );
}
// WP Optimize
if ( defined( 'WPO_VERSION' ) ) {
add_filter( 'wp-optimize-minify-default-exclusions', [ $this, 'exclude_plausible_js' ] );
}
// WP Rocket
if ( defined( 'WP_ROCKET_VERSION' ) ) {
add_filter( 'rocket_excluded_inline_js_content', [ $this, 'exclude_plausible_inline_js' ] );
add_filter( 'rocket_exclude_js', [ $this, 'exclude_plausible_js' ] );
add_filter( 'rocket_minify_excluded_external_js', [ $this, 'exclude_plausible_js' ] );
add_filter( 'rocket_delay_js_scripts', [ $this, 'exclude_plausible_js' ] );
}
}
/**
* Adds window.plausible
*
* @param mixed $exclude_js
*
* @return string
*/
public function exclude_plausible_js_as_string( $exclude_js ) {
$exclude_js .= ', window.plausible, ' . Helpers::get_js_url( true );
return $exclude_js;
}
/**
* Dear WP Rocket/SG Optimizer/Etc., don't minify/combine our inline JS, please.
*
* @filter rocket_excluded_inline_js_content
* @since 1.2.5
*
* @param array $inline_js
*
* @return array
*/
public function exclude_plausible_inline_js( $inline_js ) {
if ( ! isset( $inline_js[ 'plausible' ] ) ) {
$inline_js[ 'plausible' ] = 'window.plausible';
}
return $inline_js;
}
/**
* Dear WP Rocket/SG Optimizer/Etc., don't minify/combine/delay our external JS, please.
*
* @filter rocket_exclude_js
* @filter rocket_minify_excluded_external_js
* @since 1.2.5
*
* @param array $excluded_js
*
* @return array
*/
public function exclude_plausible_js( $excluded_js ) {
$excluded_js[] = Helpers::get_js_url( true );
return $excluded_js;
}
/**
* Dear WP Rocket/SG Optimizer/Etc., don't minify/combine/delay our external JS, please.
*
* @filter rocket_exclude_js
* @filter rocket_minify_excluded_external_js
* @since 1.2.5
*
* @param array $excluded_js
*
* @return array
*/
public function exclude_js_by_handle( $excluded_handles ) {
$excluded_handles[] = 'plausible-analytics';
return $excluded_handles;
}
/**
* WPML overrides the REST API URL to include the language 'subdirectory', which leads to 404s.
* This forces it back to default behavior.
*
* @param mixed $url
*
* @return string|void
* @throws Exception
*/
public function wpml_compatibility( $url ) {
$rest_endpoint = Helpers::get_rest_endpoint( false );
if ( strpos( $url, $rest_endpoint ) !== false ) {
return get_option( 'home' ) . $rest_endpoint;
}
return $url;
}
}