Skip to content

Commit

Permalink
Fixed issues with PHPCS
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmurphy committed Dec 24, 2024
1 parent 2be8bfe commit 70a67ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
11 changes: 4 additions & 7 deletions plugins/faustwp/includes/replacement/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function content_replacement( string $content ): string {
return $content;
}

$wp_site_urls = faustwp_get_wp_site_urls();
if (empty($wp_site_urls)) {
$wp_site_urls = faustwp_get_wp_site_urls();
if ( empty( $wp_site_urls ) ) {
return $content;
}

Expand All @@ -53,15 +53,13 @@ function content_replacement( string $content ): string {
}

if ( $replace_content_urls && $replace_media_urls ) {

foreach ( $wp_site_urls as $site_url ) {
$content = str_replace( $site_url, $frontend_uri, $content );
}

return $content;
}


if ( $replace_media_urls ) {
$wp_media_site_url = $frontend_uri . $relative_upload_url;

Expand All @@ -73,8 +71,8 @@ function content_replacement( string $content ): string {
}

foreach ( $wp_site_urls as $site_url ) {
$pattern_exclude_media_urls = "#" . preg_quote( $site_url, '#' ) . "(?!{$relative_upload_url}(\/|$))#";
$content = preg_replace( $pattern_exclude_media_urls, $frontend_uri, $content );
$pattern_exclude_media_urls = '#' . preg_quote( $site_url, '#' ) . "(?!{$relative_upload_url}(\/|$))#";
$content = preg_replace( $pattern_exclude_media_urls, $frontend_uri, $content );
}

return $content;
Expand Down Expand Up @@ -116,7 +114,6 @@ function image_source_srcset_replacement( $sources ) {
$frontend_uri = faustwp_get_setting( 'frontend_uri' );
$site_url = site_url();


/**
* For urls with no domain or the frontend domain, replace with the WP site_url.
* This was the default replacement pattern until Faust 1.2, at which point this
Expand Down
24 changes: 11 additions & 13 deletions plugins/faustwp/includes/replacement/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,23 @@ function is_wp_link_ajax_request(): bool {
}

/**
* Get all site URLs for each HTTP schema
*
* @return array
* Get all site URLs for each HTTP protocol
*/
function faustwp_get_wp_site_urls() {

$site_url = site_url();
$host_url = parse_url( $site_url, PHP_URL_HOST );
$host_url = wp_parse_url( $site_url, PHP_URL_HOST );

if ( is_string( $host_url ) ) {
$urls = [
$urls = array(
'https://' . $host_url,
'http://' . $host_url,
'//' . $host_url,
];
);
} else {
$urls = [ $site_url ];
$urls = array( $site_url );
}


return apply_filters( 'faustwp_get_wp_site_urls', $urls );
}

Expand All @@ -166,10 +163,10 @@ function faustwp_get_wp_media_urls() {
$upload_url = faustwp_get_relative_upload_url( $site_urls );

if ( ! is_string( $upload_url ) ) {
return apply_filters( 'faustwp_get_wp_site_media_urls', [] );
return apply_filters( 'faustwp_get_wp_site_media_urls', array() );
}

$media_urls = [];
$media_urls = array();
foreach ( $site_urls as $site_url ) {
$media_urls[] = $site_url . $upload_url;
}
Expand All @@ -179,11 +176,12 @@ function faustwp_get_wp_media_urls() {


/**
* @param array $site_urls
* Gets the relative wp-content upload URL.
*
* @return false|string
* @param array<string> $site_urls An array of site URLs.
* @return string The relative upload URL.
*/
function faustwp_get_relative_upload_url( array $site_urls ) {
function faustwp_get_relative_upload_url( $site_urls ) {
$upload_dir = wp_upload_dir()['baseurl'];
foreach ( $site_urls as $site_url ) {
if ( strpos( $upload_dir, $site_url ) !== false ) {
Expand Down

0 comments on commit 70a67ef

Please sign in to comment.