PluginProbe
Site Reviews / trunk
Site Reviews vtrunk
8.3.1 8.3.0 8.2.2 8.2.1 8.2.0 8.1.0 8.0.13 8.0.12 8.0.11 trunk 1.2.2 2.17.1 3.5.4 4.7.0 5.25.1 6.11.8 7.0.10 7.0.11 7.0.12 7.0.13 7.0.14 7.0.15 7.0.16 7.0.17 7.0.18 All 54 releases
site-reviews / plugin / Controllers / WelcomeController.php

WelcomeController.php in Site Reviews trunk, at plugin/Controllers/WelcomeController.php

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