Skip to content

Commit

Permalink
Remove duplicate filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan0sz committed Jul 17, 2024
1 parent 4e4147c commit a1c6bac
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Filters {
*/
public function __construct() {
add_filter( 'script_loader_tag', [ $this, 'add_plausible_attributes' ], 10, 2 );
add_filter( 'rest_url', [ $this, 'wpml_compatibility' ], 10, 1 );
add_filter( 'plausible_analytics_script_params', [ $this, 'maybe_add_custom_params' ] );
}

Expand All @@ -43,7 +42,7 @@ public function __construct() {
* @return string
*/
public function add_plausible_attributes( $tag, $handle ) {
// Bailout, if not `Plausible Analytics` script.
// Bail if it's not our script.
if ( 'plausible-analytics' !== $handle ) {
return $tag; // @codeCoverageIgnore
}
Expand All @@ -61,34 +60,15 @@ public function add_plausible_attributes( $tag, $handle ) {

// Triggered when exclude pages is enabled.
if ( ! empty( $settings[ 'excluded_pages' ] ) && $settings[ 'excluded_pages' ] ) {
$excluded_pages = $settings[ 'excluded_pages' ];
$params .= " data-exclude='{$excluded_pages}'";
$excluded_pages = $settings[ 'excluded_pages' ]; // @codeCoverageIgnore
$params .= " data-exclude='{$excluded_pages}'"; // @codeCoverageIgnore
}

$params = apply_filters( 'plausible_analytics_script_params', $params );

return str_replace( ' src', " {$params} src", $tag );
}

/**
* 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; // @codeCoverageIgnore
}

return $url;
}

/**
* Adds custom parameters Author and Category if Custom Pageview Properties is enabled.
*
Expand Down

0 comments on commit a1c6bac

Please sign in to comment.