|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Helper; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Modules\Sanitizer; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Request; |
|
8
|
|
|
|
|
9
|
|
|
class NoticeController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @action current_screen |
|
13
|
|
|
*/ |
|
14
|
9 |
|
public function activatePlugin(): void |
|
15
|
|
|
{ |
|
16
|
9 |
|
$action = filter_input(INPUT_GET, 'action'); |
|
17
|
9 |
|
$plugin = filter_input(INPUT_GET, 'plugin'); |
|
18
|
9 |
|
$trigger = filter_input(INPUT_GET, 'trigger'); |
|
19
|
9 |
|
if ('activate' !== $action || 'notice' !== $trigger || empty($plugin)) { |
|
20
|
9 |
|
return; |
|
21
|
|
|
} |
|
22
|
|
|
check_admin_referer('activate-plugin_'.$plugin); |
|
23
|
|
|
$result = activate_plugin($plugin, '', is_network_admin(), true); |
|
24
|
|
|
if (is_wp_error($result)) { |
|
25
|
|
|
wp_die($result->get_error_message()); |
|
26
|
|
|
} |
|
27
|
|
|
wp_safe_redirect(wp_get_referer()); |
|
28
|
|
|
exit; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @admin admin_head |
|
33
|
|
|
*/ |
|
34
|
|
|
public function adminNotices(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$dir = glsr()->path('plugin/Notices'); |
|
37
|
|
|
if (!is_dir($dir)) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
$iterator = new \DirectoryIterator($dir); |
|
41
|
|
|
foreach ($iterator as $fileinfo) { |
|
42
|
|
|
if (!$fileinfo->isFile()) { |
|
43
|
|
|
continue; |
|
44
|
|
|
} |
|
45
|
|
|
try { |
|
46
|
|
|
$notice = '\GeminiLabs\SiteReviews\Notices\\'.$fileinfo->getBasename('.php'); |
|
47
|
|
|
$reflect = new \ReflectionClass($notice); |
|
48
|
|
|
if ($reflect->isInstantiable()) { |
|
49
|
|
|
glsr()->singleton($notice); // make singleton |
|
50
|
|
|
glsr($notice); |
|
51
|
|
|
} |
|
52
|
|
|
} catch (\ReflectionException $e) { |
|
53
|
|
|
glsr_log()->error($e->getMessage()); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @action site-reviews/route/admin/dismiss-notice |
|
60
|
|
|
*/ |
|
61
|
|
|
public function dismissNotice(Request $request): void |
|
62
|
|
|
{ |
|
63
|
|
|
$noticeKey = glsr(Sanitizer::class)->sanitizeText($request->notice); |
|
64
|
|
|
$notice = Helper::buildClassName($noticeKey.'-notice', 'Notices'); |
|
65
|
|
|
if (class_exists($notice)) { |
|
66
|
|
|
glsr($notice)->dismiss(); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @action site-reviews/route/ajax/dismiss-notice |
|
72
|
|
|
*/ |
|
73
|
|
|
public function dismissNoticeAjax(Request $request): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->dismissNotice($request); |
|
76
|
|
|
wp_send_json_success(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @action admin_notices |
|
81
|
|
|
*/ |
|
82
|
|
|
public function injectAfterNotices(): void |
|
83
|
|
|
{ |
|
84
|
|
|
if (str_contains(glsr_current_screen()->id, glsr()->post_type)) { |
|
85
|
|
|
// Close the hidden div used to prevent notices from flickering before |
|
86
|
|
|
// they are moved elsewhere in the page by WordPress Core. |
|
87
|
|
|
echo '</div>'; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @action admin_notices |
|
93
|
|
|
*/ |
|
94
|
|
|
public function injectBeforeNotices(): void |
|
95
|
|
|
{ |
|
96
|
|
|
if (str_contains(glsr_current_screen()->id, glsr()->post_type)) { |
|
97
|
|
|
// Wrap the notices in a hidden div to prevent flickering before |
|
98
|
|
|
// they are moved elsewhere in the page by WordPress Core. |
|
99
|
|
|
echo '<div id="glsr-notice-catcher">'; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|