Skip to content

Commit

Permalink
Fixing local path
Browse files Browse the repository at this point in the history
  • Loading branch information
karrirasinmaki committed Aug 27, 2018
1 parent 3abc866 commit 4b8b0a1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/api/utilities/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,24 @@ function beans_url_to_path( $url, $force_rebuild = false ) {
$blogdetails = '';
}

// It's not an internal URL. Bail out.
if ( false === stripos( parse_url( $url, PHP_URL_HOST ), parse_url( $site_url, PHP_URL_HOST ) ) ) {
if ( false === stripos( $url, parse_url( site_url(), PHP_URL_SCHEME ) ) ) {
// If no url scheme found, it's local path instead of url.
// Also path is actually relative path instead of absolute.
// Add ./ in front of the relative url to make it relative path.
// After sanitize it will be converted to absolute path.
$url = beans_sanitize_path( './' . $url );
}
return $url;
}

// Fix protocol. It isn't needed to set SSL as it is only used to parse the URL.
if ( ! parse_url( $url, PHP_URL_SCHEME ) ) {
$original_url = $url;
$url = 'http://' . ltrim( $url, '/' );
}

// It's not an internal URL. Bail out.
if ( false === stripos( parse_url( $url, PHP_URL_HOST ), parse_url( $site_url, PHP_URL_HOST ) ) ) {
return isset( $original_url ) ? $original_url : $url;
}

// Parse url and standardize backslashes.
$url = parse_url( $url, PHP_URL_PATH );
$path = wp_normalize_path( $url );
Expand Down

0 comments on commit 4b8b0a1

Please sign in to comment.