same_host( $url, 'product' === $post->post_type ? 'product' : 'content' ); } public function same_host( string $url, string $role ): ?RunUrl { $validated = wp_http_validate_url( $url ); if ( ! is_string( $validated ) || ! $this->matches_home_host( $validated ) ) { return null; } $without_fragment = preg_replace( '/#.*$/', '', $validated ); return is_string( $without_fragment ) ? new RunUrl( $without_fragment, $role ) : null; } private function matches_home_host( string $url ): bool { $home_host = wp_parse_url( home_url( '/' ), PHP_URL_HOST ); $url_host = wp_parse_url( $url, PHP_URL_HOST ); return is_string( $home_host ) && is_string( $url_host ) && strtolower( rtrim( $home_host, '.' ) ) === strtolower( rtrim( $url_host, '.' ) ); } }