Skip to content

Commit

Permalink
fix for PHP Fatal error: Uncaught TypeError: strpos(): Argument #1 ($…
Browse files Browse the repository at this point in the history
…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/
  • Loading branch information
futtta committed Dec 5, 2024
1 parent 04b8a14 commit b4a51fb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion classes/autoptimizeExtra.php
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down

0 comments on commit b4a51fb

Please sign in to comment.