|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Application; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Controllers\Controller; |
|
7
|
|
|
use GeminiLabs\SiteReviews\Database\OptionManager; |
|
8
|
|
|
use GeminiLabs\SiteReviews\Helper; |
|
9
|
|
|
use GeminiLabs\SiteReviews\Modules\Html; |
|
10
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Builder; |
|
11
|
|
|
use GeminiLabs\SiteReviews\Modules\Html\Template; |
|
12
|
|
|
use GeminiLabs\SiteReviews\Modules\Logger; |
|
13
|
|
|
use GeminiLabs\SiteReviews\Modules\System; |
|
14
|
|
|
|
|
15
|
|
|
class MenuController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @return void |
|
19
|
|
|
* @action admin_menu |
|
20
|
|
|
*/ |
|
21
|
|
|
public function registerMenuCount() |
|
22
|
|
|
{ |
|
23
|
|
|
global $menu, $typenow; |
|
24
|
|
|
foreach( $menu as $key => $value ) { |
|
25
|
|
|
if( !isset( $value[2] ) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE )continue; |
|
26
|
|
|
$postCount = wp_count_posts( Application::POST_TYPE ); |
|
27
|
|
|
$pendingCount = glsr( Builder::class )->span( number_format_i18n( $postCount->pending ), [ |
|
28
|
|
|
'class' => 'pending-count', |
|
29
|
|
|
]); |
|
30
|
|
|
$awaitingModeration = glsr( Builder::class )->span( $pendingCount, [ |
|
31
|
|
|
'class' => 'awaiting-mod count-'.$postCount->pending, |
|
32
|
|
|
]); |
|
33
|
|
|
$menu[$key][0] .= $awaitingModeration; |
|
34
|
|
|
if( $typenow === Application::POST_TYPE ) { |
|
35
|
|
|
$menu[$key][4] .= ' current'; |
|
36
|
|
|
} |
|
37
|
|
|
break; |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return void |
|
43
|
|
|
* @action admin_menu |
|
44
|
|
|
*/ |
|
45
|
|
|
public function registerSubMenus() |
|
46
|
|
|
{ |
|
47
|
|
|
$pages = $this->parseWithFilter( 'submenu/pages', [ |
|
48
|
|
|
'settings' => __( 'Settings', 'site-reviews' ), |
|
49
|
|
|
'tools' => __( 'Tools', 'site-reviews' ), |
|
50
|
|
|
'documentation' => __( 'Documentation', 'site-reviews' ), |
|
51
|
|
|
'addons' => __( 'Add-Ons', 'site-reviews' ), |
|
52
|
|
|
]); |
|
53
|
|
|
foreach( $pages as $slug => $title ) { |
|
54
|
|
|
$method = glsr( Helper::class )->buildMethodName( 'render-'.$slug.'-menu' ); |
|
55
|
|
|
$callback = apply_filters( 'site-reviews/addon/submenu/callback', [$this, $method], $slug ); |
|
56
|
|
|
if( !is_callable( $callback ))continue; |
|
57
|
|
|
add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, $title, $title, Application::CAPABILITY, $slug, $callback ); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return void |
|
63
|
|
|
* @see $this->registerSubMenus() |
|
64
|
|
|
* @callback add_submenu_page |
|
65
|
|
|
*/ |
|
66
|
|
|
public function renderAddonsMenu() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->renderPage( 'addons', [ |
|
69
|
|
|
'template' => glsr( Template::class ), |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return void |
|
75
|
|
|
* @see $this->registerSubMenus() |
|
76
|
|
|
* @callback add_submenu_page |
|
77
|
|
|
*/ |
|
78
|
|
|
public function renderDocumentationMenu() |
|
79
|
|
|
{ |
|
80
|
|
|
$tabs = $this->parseWithFilter( 'documentation/tabs', [ |
|
81
|
|
|
'support' => __( 'Support', 'site-reviews' ), |
|
82
|
|
|
'faq' => __( 'FAQ', 'site-reviews' ), |
|
83
|
|
|
'shortcodes' => __( 'Shortcodes', 'site-reviews' ), |
|
84
|
|
|
'hooks' => __( 'Hooks', 'site-reviews' ), |
|
85
|
|
|
'functions' => __( 'Functions', 'site-reviews' ), |
|
86
|
|
|
]); |
|
87
|
|
|
$this->renderPage( 'documentation', [ |
|
88
|
|
|
'tabs' => $tabs, |
|
89
|
|
|
]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return void |
|
94
|
|
|
* @see $this->registerSubMenus() |
|
95
|
|
|
* @callback add_submenu_page |
|
96
|
|
|
*/ |
|
97
|
|
|
public function renderSettingsMenu() |
|
98
|
|
|
{ |
|
99
|
|
|
$tabs = $this->parseWithFilter( 'settings/tabs', [ |
|
100
|
|
|
'general' => __( 'General', 'site-reviews' ), |
|
101
|
|
|
'reviews' => __( 'Reviews', 'site-reviews' ), |
|
102
|
|
|
'submissions' => __( 'Submissions', 'site-reviews' ), |
|
103
|
|
|
'schema' => __( 'Schema', 'site-reviews' ), |
|
104
|
|
|
'translations' => __( 'Translations', 'site-reviews' ), |
|
105
|
|
|
'licenses' => __( 'Licenses', 'site-reviews' ), |
|
106
|
|
|
]); |
|
107
|
|
|
if( !apply_filters( 'site-reviews/addon/licenses', false )) { |
|
108
|
|
|
unset( $tabs['licenses'] ); |
|
109
|
|
|
} |
|
110
|
|
|
$this->renderPage( 'settings', [ |
|
111
|
|
|
// 'database_key' => OptionManager::databaseKey(), |
|
|
|
|
|
|
112
|
|
|
// 'settings' => glsr()->getDefaults(), |
|
|
|
|
|
|
113
|
|
|
'tabs' => $tabs, |
|
114
|
|
|
'template' => glsr( Template::class ), |
|
115
|
|
|
]); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return void |
|
120
|
|
|
* @see $this->registerSubMenus() |
|
121
|
|
|
* @callback add_submenu_page |
|
122
|
|
|
*/ |
|
123
|
|
|
public function renderToolsMenu() |
|
124
|
|
|
{ |
|
125
|
|
|
$tabs = $this->parseWithFilter( 'tools/tabs', [ |
|
126
|
|
|
'import-export' => __( 'Import/Export', 'site-reviews' ), |
|
127
|
|
|
'logging' => __( 'Logging', 'site-reviews' ), |
|
128
|
|
|
'system-info' => __( 'System Info', 'site-reviews' ), |
|
129
|
|
|
]); |
|
130
|
|
|
$this->renderPage( 'tools', [ |
|
131
|
|
|
'data' => [ |
|
132
|
|
|
'id' => Application::ID, |
|
133
|
|
|
'logger' => glsr( Logger::class ), |
|
134
|
|
|
'prefix' => Application::PREFIX, |
|
135
|
|
|
'system' => glsr( System::class ), |
|
136
|
|
|
], |
|
137
|
|
|
'html' => glsr( Html::class ), |
|
138
|
|
|
'tabs' => $tabs, |
|
139
|
|
|
]); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return void |
|
144
|
|
|
* @action admin_init |
|
145
|
|
|
*/ |
|
146
|
|
|
public function setCustomPermissions() |
|
147
|
|
|
{ |
|
148
|
|
|
foreach( wp_roles()->roles as $role => $value ) { |
|
149
|
|
|
wp_roles()->remove_cap( $role, 'create_'.Application::POST_TYPE ); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param string $hookSuffix |
|
155
|
|
|
* @return array |
|
156
|
|
|
*/ |
|
157
|
|
|
protected function parseWithFilter( $hookSuffix, array $args = [] ) |
|
158
|
|
|
{ |
|
159
|
|
|
$filteredArgs = apply_filters( 'site-reviews/addon/'.$hookSuffix, [] ); |
|
160
|
|
|
return wp_parse_args( $filteredArgs, $args ); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param string $page |
|
165
|
|
|
* @return void |
|
166
|
|
|
*/ |
|
167
|
|
|
protected function renderPage( $page, array $data = [] ) |
|
168
|
|
|
{ |
|
169
|
|
|
glsr()->render( 'pages/'.$page.'/index', $data ); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.