| 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 |
|