Yoast\WP\SEO\Helpers

Url_Helper::recreate_current_url()publicYoast 1.0

Recreate current URL.

{} Это метод класса: Url_Helper{}

Хуков нет.

Возвращает

Строку.

Использование

$Url_Helper = new Url_Helper();
$Url_Helper->recreate_current_url( $with_request_uri );
$with_request_uri(true|false)
Whether we want the REQUEST_URI appended.
По умолчанию: true

Код Url_Helper::recreate_current_url() Yoast 19.7.1

public function recreate_current_url( $with_request_uri = true ) {
	$current_url = 'http';
	if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) {
		$current_url .= 's';
	}
	$current_url .= '://';

	// phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary.
	$suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : '';

	if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) {
		// phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary.
		$server_name = $_SERVER['SERVER_NAME'];
	}
	else {
		// Early return with just the path.
		return $suffix;
	}

	$server_port = '';
	if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) {
		// phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary.
		$server_port = $_SERVER['SERVER_PORT'];
	}

	if ( ! empty( $server_port ) ) {
		$current_url .= $server_name . ':' . $server_port . $suffix;
	}
	else {
		// phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary.
		$current_url .= $server_name . $suffix;
	}

	return $current_url;
}