From b4a51fb1d73d57c833f32917252a98dd1447c273 Mon Sep 17 00:00:00 2001 From: futtta Date: Thu, 5 Dec 2024 20:30:53 +0100 Subject: [PATCH] fix for PHP Fatal error: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, array given in wp-content/plugins/autoptimize/classes/autoptimizeExtra.php:222 as reported in https://wordpress.org/support/topic/critical-error-after-changing-google-font-setting/ --- classes/autoptimizeExtra.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/classes/autoptimizeExtra.php b/classes/autoptimizeExtra.php index 75f8ea78..6ee3e0d0 100644 --- a/classes/autoptimizeExtra.php +++ b/classes/autoptimizeExtra.php @@ -219,7 +219,16 @@ public function filter_remove_dns_prefetch( $urls, $relation_type, $url_to_remov if ( ! empty( $url_to_remove ) && 'dns-prefetch' === $relation_type ) { $cnt = 0; foreach ( $urls as $url ) { - if ( false !== strpos( $url, $url_to_remove ) ) { + // $url can be an array, in which case we need to fetch the value of the href key. + if ( is_array( $url ) ) { + if ( isset( $url['href'] ) ) { + $url = $url['href']; + } else { + continue; + } + } + + if ( is_string( $url ) && false !== strpos( $url, $url_to_remove ) ) { unset( $urls[ $cnt ] ); } $cnt++;