|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Builder; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Template; |
|
8
|
|
|
|
|
9
|
|
|
class WelcomeController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @return array |
|
13
|
|
|
* @filter plugin_action_links_site-reviews/site-reviews.php |
|
14
|
|
|
*/ |
|
15
|
|
|
public function filterActionLinks(array $links) |
|
16
|
|
|
{ |
|
17
|
|
|
$links['welcome'] = glsr(Builder::class)->a(__('About', 'site-reviews'), [ |
|
18
|
|
|
'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome'), |
|
19
|
|
|
]); |
|
20
|
|
|
return $links; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return string |
|
25
|
|
|
* @filter admin_title |
|
26
|
|
|
*/ |
|
27
|
|
|
public function filterAdminTitle($title) |
|
28
|
|
|
{ |
|
29
|
|
|
return Application::POST_TYPE.'_page_welcome' == glsr_current_screen()->id |
|
30
|
|
|
? sprintf(__('Welcome to %s — WordPress', 'site-reviews'), glsr()->name) |
|
31
|
|
|
: $title; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param string $text |
|
36
|
|
|
* @return string |
|
37
|
|
|
* @filter admin_footer_text |
|
38
|
|
|
*/ |
|
39
|
|
|
public function filterFooterText($text) |
|
40
|
|
|
{ |
|
41
|
|
|
if (Application::POST_TYPE.'_page_welcome' != glsr_current_screen()->id) { |
|
42
|
|
|
return $text; |
|
43
|
|
|
} |
|
44
|
|
|
$url = 'https://wordpress.org/support/view/plugin-reviews/site-reviews?filter=5#new-post'; |
|
45
|
|
|
return wp_kses_post(sprintf( |
|
46
|
|
|
__('Please rate %s on %s and help us spread the word. Thank you so much!', 'site-reviews'), |
|
47
|
|
|
'<strong>'.glsr()->name.'</strong> <a href="'.$url.'" target="_blank">★★★★★</a>', |
|
48
|
|
|
'<a href="'.$url.'" target="_blank">wordpress.org</a>' |
|
49
|
|
|
)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $plugin |
|
54
|
|
|
* @param bool $isNetworkActivation |
|
55
|
|
|
* @return void |
|
56
|
|
|
* @action activated_plugin |
|
57
|
|
|
*/ |
|
58
|
|
|
public function redirectOnActivation($plugin, $isNetworkActivation) |
|
59
|
|
|
{ |
|
60
|
|
|
if (!$isNetworkActivation |
|
61
|
|
|
&& 'cli' !== php_sapi_name() |
|
62
|
|
|
&& $plugin === plugin_basename(glsr()->file)) { |
|
63
|
|
|
wp_safe_redirect(admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=welcome')); |
|
64
|
|
|
exit; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return void |
|
70
|
|
|
* @action admin_menu |
|
71
|
|
|
*/ |
|
72
|
|
|
public function registerPage() |
|
73
|
|
|
{ |
|
74
|
|
|
add_submenu_page('edit.php?post_type='.Application::POST_TYPE, |
|
75
|
|
|
sprintf(__('Welcome to %s', 'site-reviews'), glsr()->name), |
|
76
|
|
|
glsr()->name, |
|
77
|
|
|
glsr()->getPermission('welcome'), |
|
78
|
|
|
'welcome', |
|
79
|
|
|
[$this, 'renderPage'] |
|
80
|
|
|
); |
|
81
|
|
|
remove_submenu_page('edit.php?post_type='.Application::POST_TYPE, 'welcome'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return void |
|
86
|
|
|
* @see $this->registerPage() |
|
87
|
|
|
* @callback add_submenu_page |
|
88
|
|
|
*/ |
|
89
|
|
|
public function renderPage() |
|
90
|
|
|
{ |
|
91
|
|
|
$tabs = apply_filters('site-reviews/addon/welcome/tabs', [ |
|
92
|
|
|
'getting-started' => __('Getting Started', 'site-reviews'), |
|
93
|
|
|
'whatsnew' => __('What\'s New', 'site-reviews'), |
|
94
|
|
|
'upgrade-guide' => __('Upgrade Guide', 'site-reviews'), |
|
95
|
|
|
'support' => __('Support', 'site-reviews'), |
|
96
|
|
|
]); |
|
97
|
|
|
glsr()->render('pages/welcome/index', [ |
|
98
|
|
|
'data' => [ |
|
99
|
|
|
'context' => [], |
|
100
|
|
|
], |
|
101
|
|
|
'http_referer' => (string) wp_get_referer(), |
|
102
|
|
|
'tabs' => $tabs, |
|
103
|
|
|
'template' => glsr(Template::class), |
|
104
|
|
|
]); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|