|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Contracts\CommandContract; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Helpers\Url; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Modules\Notice; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Request; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AbstractCommand implements CommandContract |
|
11
|
|
|
{ |
|
12
|
24 |
|
protected bool $result = true; |
|
13
|
|
|
|
|
14
|
24 |
|
public function fail(): void |
|
15
|
|
|
{ |
|
16
|
|
|
$this->result = false; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function hasRequest(): bool |
|
20
|
|
|
{ |
|
21
|
|
|
return isset($this->request) |
|
22
|
|
|
&& is_a($this->request, Request::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function pass(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$this->result = true; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function referer(): string |
|
31
|
|
|
{ |
|
32
|
|
|
return Url::home(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function request(): Request |
|
36
|
|
|
{ |
|
37
|
|
|
if (!$this->hasRequest()) { |
|
38
|
|
|
return new Request(); |
|
39
|
|
|
} |
|
40
|
|
|
return $this->request; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function response(): array |
|
44
|
|
|
{ |
|
45
|
|
|
return []; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function sendJsonResponse(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$data = $this->response(); |
|
51
|
|
|
if ($this->successful()) { |
|
52
|
|
|
wp_send_json_success($data); |
|
53
|
|
|
} |
|
54
|
|
|
if (empty($data['notices'])) { |
|
55
|
|
|
glsr(Notice::class)->addError( |
|
56
|
|
|
sprintf(_x('Something went wrong, check the <a href="%s">Site Reviews → Tools → Console</a> page for errors.', 'admin-text', 'site-reviews'), |
|
57
|
|
|
glsr_admin_url('tools', 'console') |
|
58
|
|
|
) |
|
59
|
|
|
); |
|
60
|
|
|
$data['notices'] = glsr(Notice::class)->get(); |
|
61
|
|
|
} |
|
62
|
|
|
wp_send_json_error($data); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function successful(): bool |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->result; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|