Automattic\WooCommerce\Gateways\PayPal
Request::normalize_url_for_paypal
Normalize a URL for PayPal. PayPal requires absolute URLs with protocol.
Метод класса: Request{}
Хуков нет.
Возвращает
string. Normalized URL.
Использование
// private - только в коде основоного (родительского) класса $result = $this->normalize_url_for_paypal( $url ): string;
- $url(строка) (обязательный)
- The URL to check.
Код Request::normalize_url_for_paypal() Request::normalize url for paypal WC 11.2.2
private function normalize_url_for_paypal( string $url ): string {
// Replace encoded ampersand with actual ampersand.
// In some cases, the URL may contain encoded ampersand but PayPal expects the actual ampersand.
// PayPal request fails if the URL contains encoded ampersand.
$url = str_replace( '&', '&', $url );
// If the URL is already the home URL, return it.
if ( strpos( $url, home_url() ) === 0 ) {
return esc_url_raw( $url );
}
// Return the URL if it is already absolute (contains ://).
if ( strpos( $url, '://' ) !== false ) {
return esc_url_raw( $url );
}
$home_url = untrailingslashit( home_url() );
// If the URL is relative (starts with /), prepend the home URL.
if ( strpos( $url, '/' ) === 0 ) {
return esc_url_raw( $home_url . $url );
}
// Prepend home URL with a slash.
return esc_url_raw( $home_url . '/' . $url );
}