Skip to content

Commit c85f7c1

Browse files
authored
fix wordpress blocked by waf [SPMVP-6920] (#1)
* feat: add custom user agent [SPMVP-6920]
1 parent c71ed37 commit c85f7c1

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/Facades/WordPress.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* @method static \Storipress\WordPress\WordPress setUsername(string $username)
2525
* @method static \Storipress\WordPress\WordPress password()
2626
* @method static \Storipress\WordPress\WordPress setPassword(string $password)
27+
* @method static \Storipress\WordPress\WordPress userAgent()
28+
* @method static \Storipress\WordPress\WordPress withUserAgent(string $userAgent)
2729
*/
2830
class WordPress extends Facade
2931
{

src/Requests/Request.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ protected function request(
3636
string $path,
3737
array $options = [],
3838
): stdClass|array|bool {
39-
$response = $this
40-
->app
41-
->http
39+
$http = $this->app->http
4240
->withoutVerifying()
4341
->withoutRedirecting()
44-
->withBasicAuth($this->app->username(), $this->app->password())
45-
->{$method}($this->getUrl($path), $options);
42+
->withBasicAuth($this->app->username(), $this->app->password());
43+
44+
if ($this->app->userAgent()) {
45+
$http->withUserAgent($this->app->userAgent());
46+
}
47+
48+
$response = $http->{$method}($this->getUrl($path), $options);
4649

4750
if (!($response instanceof Response)) {
4851
throw new UnexpectedValueException();

src/WordPress.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class WordPress
2929

3030
protected string $password;
3131

32+
protected ?string $userAgent = null;
33+
3234
public function __construct(
3335
public Factory $http,
3436
) {
@@ -84,6 +86,18 @@ public function setPassword(string $key): static
8486
return $this;
8587
}
8688

89+
public function userAgent(): ?string
90+
{
91+
return $this->userAgent;
92+
}
93+
94+
public function withUserAgent(string $userAgent): static
95+
{
96+
$this->userAgent = $userAgent;
97+
98+
return $this;
99+
}
100+
87101
public function request(): GeneralRequest
88102
{
89103
return $this->request;

0 commit comments

Comments
 (0)