Skip to content

Commit

Permalink
Small refactor of parameters with @whoami-pwd
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmurphy committed Jan 13, 2025
1 parent e37f7b0 commit 11f1db2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
14 changes: 6 additions & 8 deletions plugins/faustwp/includes/replacement/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ function content_replacement( string $content ): string {
return $content;
}

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

$upload_url = wp_upload_dir()['baseurl'];
$wp_media_urls = faustwp_get_wp_media_urls( $wp_site_urls, $upload_url );
$relative_upload_url = faustwp_get_relative_upload_url( $wp_site_urls, $upload_url );
$relative_upload_url = faustwp_get_relative_upload_url( $wp_site_urls, wp_upload_dir()['baseurl'] );
$wp_media_urls = faustwp_get_wp_media_urls( $wp_site_urls, $relative_upload_url );
$frontend_uri = (string) faustwp_get_setting( 'frontend_uri' ) ?? '/';

if ( $replace_content_urls && $replace_media_urls ) {
Expand Down Expand Up @@ -108,15 +107,14 @@ function image_source_srcset_replacement( $sources ) {
return $sources;
}

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

$replace_media_urls = ! use_wp_domain_for_media();
$upload_url = wp_upload_dir()['baseurl'];
$wp_media_urls = faustwp_get_wp_media_urls( $wp_site_urls, $upload_url );
$relative_upload_url = faustwp_get_relative_upload_url( $wp_site_urls, $upload_url );
$relative_upload_url = faustwp_get_relative_upload_url( $wp_site_urls, wp_upload_dir()['baseurl'] );
$wp_media_urls = faustwp_get_wp_media_urls( $wp_site_urls, $relative_upload_url );
$frontend_uri = (string) faustwp_get_setting( 'frontend_uri' );
$site_url = site_url() . '/';

Expand Down
15 changes: 6 additions & 9 deletions plugins/faustwp/includes/replacement/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ function is_wp_link_ajax_request(): bool {
&& 'wp-link-ajax' === $_POST['action'] );
}


/**
* Get all site URLs for each possible HTTP protocol
*
* @param string $site_url The site url.
*
* @return array<string> An array of site urls.
*/
function faustwp_get_wp_site_urls() {
function faustwp_get_wp_site_urls( string $site_url ): array {

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

$is_https = strpos( $site_url, 0, 6 ) === 'https:';
Expand All @@ -158,16 +160,11 @@ function faustwp_get_wp_site_urls() {
* Get all media urls based off the available site urls
*
* @param array<string> $wp_site_urls The array of potential site urls.
* @param string $upload_url An array of site URLs.
* @param string $relative_upload_url The relative upload url.
*
* @return array<string> The array of media Urls
*/
function faustwp_get_wp_media_urls( array $wp_site_urls, string $upload_url ) {
$relative_upload_url = faustwp_get_relative_upload_url( $wp_site_urls, $upload_url );

if ( ! is_string( $relative_upload_url ) ) {
return apply_filters( 'faustwp_get_wp_site_media_urls', array() );
}
function faustwp_get_wp_media_urls( array $wp_site_urls, string $relative_upload_url ) {

$media_urls = array();
foreach ( $wp_site_urls as $site_url ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public function test_content_replacement_for_content_and_media_urls_and_add_site
return array_merge( $site_urls, [ 'https://subdomain.example.org' ] );
});

$this->assertSame(faustwp_get_wp_site_urls(), [
$this->assertSame(faustwp_get_wp_site_urls($site_url), [
$site_url,
$site_url_secure,
'//example.org',
Expand Down

0 comments on commit 11f1db2

Please sign in to comment.