diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/Requests/src/Auth/Basic.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wp/wp-includes/Requests/src/Auth/Basic.php Fri Sep 05 18:40:08 2025 +0200 @@ -0,0 +1,103 @@ +user, $this->pass) = $args; + return; + } + + if ($args !== null) { + throw InvalidArgument::create(1, '$args', 'array|null', gettype($args)); + } + } + + /** + * Register the necessary callbacks + * + * @see \WpOrg\Requests\Auth\Basic::curl_before_send() + * @see \WpOrg\Requests\Auth\Basic::fsockopen_header() + * @param \WpOrg\Requests\Hooks $hooks Hook system + */ + public function register(Hooks $hooks) { + $hooks->register('curl.before_send', [$this, 'curl_before_send']); + $hooks->register('fsockopen.after_headers', [$this, 'fsockopen_header']); + } + + /** + * Set cURL parameters before the data is sent + * + * @param resource|\CurlHandle $handle cURL handle + */ + public function curl_before_send(&$handle) { + curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($handle, CURLOPT_USERPWD, $this->getAuthString()); + } + + /** + * Add extra headers to the request before sending + * + * @param string $out HTTP header string + */ + public function fsockopen_header(&$out) { + $out .= sprintf("Authorization: Basic %s\r\n", base64_encode($this->getAuthString())); + } + + /** + * Get the authentication string (user:pass) + * + * @return string + */ + public function getAuthString() { + return $this->user . ':' . $this->pass; + } +}