YahnisElsts/wp-update-server

Update Request to handle WordPress.com

Closed this issue · 2 comments

Hey,

Thanks for the great server script. I wanted to let you know that the server script does not handle wordpress.com requests. I changed the construct in Wpup_Request to handle it, however I couldn't manage to get the WordPress version. Anyways, just if someone wanted to handle, it would be a great merge.

/If the request was made via the WordPress HTTP API we can usually
//get WordPress version and site URL from the user agent.
$header = $this->headers->get('User-Agent', '');
$regex = '@WordPress/(?P<version>\d[^;]*?);\s+(?P<url>https?://.+?)(?:\s|;|$)@i';
if ( preg_match($regex, $header, $matches) ) {
	$this->wpVersion = $matches['version'];
	$this->wpSiteUrl = $matches['url'];
} else {
	$regex = '@WordPress\.com;\s+(?P<url>https?://.+?)(?:\s|;|$)@i';
	if ( preg_match($regex, $header, $matches) ) {
		$this->wpVersion = '0.0.0';
		$this->wpSiteUrl = $matches['url'];
	}
}

Cheers,

Thank you for the suggestion and the code! Could you also post a couple examples of the User-Agent sent by wordpress.com (for testing/validation purposes)?

Hi there,

Sorry for the late response.

The $header (User-Agent) in the **Wpup_Request construct comes as

WordPress.com; https://domain.com

$this->headers (return of Wpup_Headers) is

Wpup_Headers Object
(
    [headers:protected] => Array
        (
            [Host] => www.mydomain.com
            [User-Agent] => WordPress.com; https://domain.com
            [Accept] => application/json
            [Cdn-Loop] => cloudflare
            [Cf-Connecting-Ip] => 2XXX:6XXX:X:1XX::6XX:aXX
            [Cf-Ipcountry] => US
            [Cf-Origin-Https] => on
            [Cf-Ray] => 5...............-IAD
            [Cf-Request-Id] => 0606..............
            [Cf-Visitor] => {"scheme":"https"}
            [Referer] => https://www.mydomain.com/server/?action=get_metadata&slug=............
            [X-Forwarded-For] => 2XXX:6XXX:X:1XX::6XXX:aXX
            [X-Forwarded-Proto] => https
            [Accept-Encoding] => gzip
            [Connection] => close
        )
)

Please note that, some places are changed for the anonymity. mydomain.com is my site, domain.com is the site on WordPress.com.