Skip to content

Commit 2fa01fc

Browse files
committed
minor improvements
1 parent 1c720bc commit 2fa01fc

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

plugins/faustwp/includes/replacement/callbacks.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,29 @@ function content_replacement( ?string $content ) {
6262

6363
// Look for href links.
6464
preg_match_all( '#href="([^"]+)"#i', $content, $href_links );
65-
66-
foreach ( $href_links[1] as $i => $url ) {
67-
// skip media links.
68-
$is_media = array_filter( $wp_media_urls, fn( $media ) => strpos( $url, $media ) === 0 );
69-
if ( $is_media ) {
70-
continue;
71-
}
72-
73-
$is_wp_url = array_filter( $wp_site_urls, fn( $base ) => strpos( $url, $base ) === 0 );
74-
if ( ! $is_wp_url ) {
75-
continue;
65+
if ( is_array($href_links) && !empty($href_links[1]) ) {
66+
foreach ( $href_links[1] as $i => $url ) {
67+
// skip media links.
68+
$is_media = array_filter( $wp_media_urls, fn( $media ) => strpos( $url, $media ) === 0 );
69+
if ( $is_media ) {
70+
continue;
71+
}
72+
73+
$is_wp_url = array_filter( $wp_site_urls, fn( $base ) => strpos( $url, $base ) === 0 );
74+
if ( ! $is_wp_url ) {
75+
continue;
76+
}
77+
78+
// get relative link.
79+
$relative = str_replace( reset( $is_wp_url ), '', $url );
80+
$updated = 'href="' . $frontend_uri . $relative . '"';
81+
82+
$original = $href_links[0][ $i ];
83+
84+
if ( $original ) {
85+
$content = str_replace( $original, $updated, $content );
86+
}
7687
}
77-
78-
// get relative link.
79-
$relative = str_replace( reset( $is_wp_url ), '', $url );
80-
$updated = 'href="' . $frontend_uri . $relative . '"';
81-
82-
$original = $href_links[0][ $i ];
83-
$content = str_replace( $original, $updated, $content );
8488
}
8589
}
8690

0 commit comments

Comments
 (0)