1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Api; |
6
|
|
|
use GeminiLabs\SiteReviews\Defaults\TutorialDefaults; |
7
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Builder; |
8
|
|
|
|
9
|
|
|
class WelcomeController extends AbstractController |
10
|
|
|
{ |
11
|
|
|
protected $welcomePage; |
12
|
|
|
|
13
|
|
|
public function __construct() |
14
|
|
|
{ |
15
|
|
|
$this->welcomePage = glsr()->id.'-welcome'; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @filter plugin_action_links_site-reviews/site-reviews.php |
20
|
|
|
*/ |
21
|
|
|
public function filterActionLinks(array $links): array |
22
|
|
|
{ |
23
|
|
|
$links['welcome'] = glsr(Builder::class)->a([ |
24
|
|
|
'href' => esc_url(glsr_admin_url('welcome')), |
25
|
|
|
'text' => _x('About', 'admin-text', 'site-reviews'), |
26
|
|
|
]); |
27
|
|
|
return $links; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @action admin_menu |
32
|
|
|
*/ |
33
|
|
|
public function registerPage(): void |
34
|
|
|
{ |
35
|
|
|
add_dashboard_page( |
36
|
|
|
sprintf(_x('Welcome to %s', 'admin-text', 'site-reviews'), glsr()->name), |
37
|
|
|
glsr()->name, |
38
|
|
|
glsr()->getPermission('welcome'), |
39
|
|
|
$this->welcomePage, |
40
|
|
|
[$this, 'renderPageCallback'] |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* We don't use admin_menu because it breaks the privilege check which runs |
46
|
|
|
* after the admin_menu hook is triggered in wp-admin/includes/menu.php. |
47
|
|
|
* |
48
|
|
|
* @action admin_init |
49
|
|
|
*/ |
50
|
|
|
public function removeSubMenu(): void |
51
|
|
|
{ |
52
|
|
|
if (!function_exists('remove_submenu_page')) { |
53
|
|
|
require_once ABSPATH.'wp-admin/includes/plugin.php'; |
54
|
|
|
} |
55
|
|
|
remove_submenu_page('index.php', $this->welcomePage); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @see registerPage |
60
|
8 |
|
*/ |
61
|
|
|
public function renderPageCallback(): void |
62
|
8 |
|
{ |
63
|
|
|
$data = glsr(Api::class)->get('tutorials')->data(); |
64
|
|
|
$data = glsr(TutorialDefaults::class)->restrict($data); |
65
|
8 |
|
$tabs = glsr()->filterArray('addon/welcome/tabs', [ |
66
|
|
|
'getting-started' => _x('Getting Started', 'admin-text', 'site-reviews'), |
67
|
|
|
'whatsnew' => _x('What\'s New', 'admin-text', 'site-reviews'), |
68
|
|
|
'upgrade-guide' => _x('Upgrade Guide', 'admin-text', 'site-reviews'), |
69
|
|
|
'support' => _x('Support', 'admin-text', 'site-reviews'), |
70
|
|
|
]); |
71
|
|
|
glsr()->render('pages/welcome/index', [ |
72
|
|
|
'data' => $data, |
73
|
|
|
'http_referer' => (string) wp_get_referer(), |
74
|
|
|
'tabs' => $tabs, |
75
|
|
|
]); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Removing the submenu page prevents the get_admin_page_title() function |
80
|
|
|
* from accessing the page title so this hook restores it. |
81
|
|
|
* |
82
|
|
|
* @action load-dashboard_page_site-reviews-welcome |
83
|
|
|
*/ |
84
|
|
|
public function restorePageTitle(): void |
85
|
|
|
{ |
86
|
|
|
global $title; |
87
|
|
|
$title = sprintf(_x('Welcome to %s', 'admin-text', 'site-reviews'), glsr()->name); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|