@@ -10,134 +10,134 @@ |
||
10 | 10 | |
11 | 11 | class Migrate |
12 | 12 | { |
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - public $currentVersion; |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + public $currentVersion; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $transientKey; |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $transientKey; |
|
22 | 22 | |
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->currentVersion = $this->getCurrentVersion(); |
|
26 | - $this->transientKey = Application::PREFIX.'migrations'; |
|
27 | - } |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->currentVersion = $this->getCurrentVersion(); |
|
26 | + $this->transientKey = Application::PREFIX.'migrations'; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function isMigrationNeeded() |
|
33 | - { |
|
34 | - $transient = get_transient($this->transientKey); |
|
35 | - if (false === $transient || !isset($transient[glsr()->version])) { |
|
36 | - $transient = [ |
|
37 | - glsr()->version => !empty($this->getNewMigrationFiles()), |
|
38 | - ]; |
|
39 | - set_transient($this->transientKey, $transient); |
|
40 | - } |
|
41 | - return Helper::castToBool($transient[glsr()->version]); |
|
42 | - } |
|
29 | + /** |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function isMigrationNeeded() |
|
33 | + { |
|
34 | + $transient = get_transient($this->transientKey); |
|
35 | + if (false === $transient || !isset($transient[glsr()->version])) { |
|
36 | + $transient = [ |
|
37 | + glsr()->version => !empty($this->getNewMigrationFiles()), |
|
38 | + ]; |
|
39 | + set_transient($this->transientKey, $transient); |
|
40 | + } |
|
41 | + return Helper::castToBool($transient[glsr()->version]); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function run() |
|
48 | - { |
|
49 | - $this->runMigrations($this->getNewMigrationFiles()); |
|
50 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function run() |
|
48 | + { |
|
49 | + $this->runMigrations($this->getNewMigrationFiles()); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function runAll() |
|
56 | - { |
|
57 | - $this->runMigrations($this->getMigrationFiles()); |
|
58 | - } |
|
52 | + /** |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function runAll() |
|
56 | + { |
|
57 | + $this->runMigrations($this->getMigrationFiles()); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - protected function getCurrentVersion() |
|
64 | - { |
|
65 | - $fallback = '0.0.0'; |
|
66 | - $majorVersions = [4, 3, 2, 1]; |
|
67 | - foreach ($majorVersions as $majorVersion) { |
|
68 | - $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
69 | - $version = Arr::get($settings, 'version', $fallback); |
|
70 | - if (Helper::isGreaterThan($version, $fallback)) { |
|
71 | - return $version; |
|
72 | - } |
|
73 | - } |
|
74 | - return $fallback; |
|
75 | - } |
|
60 | + /** |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + protected function getCurrentVersion() |
|
64 | + { |
|
65 | + $fallback = '0.0.0'; |
|
66 | + $majorVersions = [4, 3, 2, 1]; |
|
67 | + foreach ($majorVersions as $majorVersion) { |
|
68 | + $settings = get_option(OptionManager::databaseKey($majorVersion)); |
|
69 | + $version = Arr::get($settings, 'version', $fallback); |
|
70 | + if (Helper::isGreaterThan($version, $fallback)) { |
|
71 | + return $version; |
|
72 | + } |
|
73 | + } |
|
74 | + return $fallback; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - protected function getMigrationFiles() |
|
81 | - { |
|
82 | - $files = []; |
|
83 | - $dir = glsr()->path('plugin/Modules/Migrations'); |
|
84 | - if (is_dir($dir)) { |
|
85 | - $iterator = new DirectoryIterator($dir); |
|
86 | - foreach ($iterator as $fileinfo) { |
|
87 | - if ($fileinfo->isFile()) { |
|
88 | - $files[] = $fileinfo->getFilename(); |
|
89 | - } |
|
90 | - } |
|
91 | - natsort($files); |
|
92 | - } |
|
93 | - return $files; |
|
94 | - } |
|
77 | + /** |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + protected function getMigrationFiles() |
|
81 | + { |
|
82 | + $files = []; |
|
83 | + $dir = glsr()->path('plugin/Modules/Migrations'); |
|
84 | + if (is_dir($dir)) { |
|
85 | + $iterator = new DirectoryIterator($dir); |
|
86 | + foreach ($iterator as $fileinfo) { |
|
87 | + if ($fileinfo->isFile()) { |
|
88 | + $files[] = $fileinfo->getFilename(); |
|
89 | + } |
|
90 | + } |
|
91 | + natsort($files); |
|
92 | + } |
|
93 | + return $files; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - protected function getNewMigrationFiles() |
|
100 | - { |
|
101 | - $files = $this->getMigrationFiles(); |
|
102 | - foreach ($files as $index => $file) { |
|
103 | - $className = str_replace('.php', '', $file); |
|
104 | - $migrationVersion = str_replace(['Migrate_', '_'], ['', '.'], $className); |
|
105 | - $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
106 | - if (Helper::isGreaterThanOrEqual($this->currentVersion, $migrationVersion.$suffix)) { |
|
107 | - unset($files[$index]); |
|
108 | - } |
|
109 | - } |
|
110 | - return $files; |
|
111 | - } |
|
96 | + /** |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + protected function getNewMigrationFiles() |
|
100 | + { |
|
101 | + $files = $this->getMigrationFiles(); |
|
102 | + foreach ($files as $index => $file) { |
|
103 | + $className = str_replace('.php', '', $file); |
|
104 | + $migrationVersion = str_replace(['Migrate_', '_'], ['', '.'], $className); |
|
105 | + $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions |
|
106 | + if (Helper::isGreaterThanOrEqual($this->currentVersion, $migrationVersion.$suffix)) { |
|
107 | + unset($files[$index]); |
|
108 | + } |
|
109 | + } |
|
110 | + return $files; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - protected function runMigrations(array $files) |
|
117 | - { |
|
118 | - if (empty($files)) { |
|
119 | - return; |
|
120 | - } |
|
121 | - array_walk($files, function ($file) { |
|
122 | - $className = str_replace('.php', '', $file); |
|
123 | - glsr('Modules\\Migrations\\'.$className)->run(); |
|
124 | - $versionMigrated = str_replace(['Migrate_', '_'], ['v','.'], $className); |
|
125 | - glsr_log()->debug('migration completed for '.$versionMigrated); |
|
126 | - }); |
|
127 | - if ($this->currentVersion !== glsr()->version) { |
|
128 | - $this->updateVersionFrom($this->currentVersion); |
|
129 | - } |
|
130 | - glsr(OptionManager::class)->set('last_migration_run', current_time('timestamp')); |
|
131 | - delete_transient($this->transientKey); |
|
132 | - } |
|
113 | + /** |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + protected function runMigrations(array $files) |
|
117 | + { |
|
118 | + if (empty($files)) { |
|
119 | + return; |
|
120 | + } |
|
121 | + array_walk($files, function ($file) { |
|
122 | + $className = str_replace('.php', '', $file); |
|
123 | + glsr('Modules\\Migrations\\'.$className)->run(); |
|
124 | + $versionMigrated = str_replace(['Migrate_', '_'], ['v','.'], $className); |
|
125 | + glsr_log()->debug('migration completed for '.$versionMigrated); |
|
126 | + }); |
|
127 | + if ($this->currentVersion !== glsr()->version) { |
|
128 | + $this->updateVersionFrom($this->currentVersion); |
|
129 | + } |
|
130 | + glsr(OptionManager::class)->set('last_migration_run', current_time('timestamp')); |
|
131 | + delete_transient($this->transientKey); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @param string $previousVersion |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - protected function updateVersionFrom($previousVersion) |
|
139 | - { |
|
140 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
141 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
142 | - } |
|
134 | + /** |
|
135 | + * @param string $previousVersion |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + protected function updateVersionFrom($previousVersion) |
|
139 | + { |
|
140 | + glsr(OptionManager::class)->set('version', glsr()->version); |
|
141 | + glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
142 | + } |
|
143 | 143 | } |
@@ -17,356 +17,356 @@ |
||
17 | 17 | */ |
18 | 18 | final class Application extends Container |
19 | 19 | { |
20 | - const CAPABILITY = 'edit_others_posts'; |
|
21 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
22 | - const ID = 'site-reviews'; |
|
23 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
24 | - const POST_TYPE = 'site-review'; |
|
25 | - const PREFIX = 'glsr_'; |
|
26 | - const TAXONOMY = 'site-review-category'; |
|
20 | + const CAPABILITY = 'edit_others_posts'; |
|
21 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
22 | + const ID = 'site-reviews'; |
|
23 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
24 | + const POST_TYPE = 'site-review'; |
|
25 | + const PREFIX = 'glsr_'; |
|
26 | + const TAXONOMY = 'site-review-category'; |
|
27 | 27 | |
28 | - public $addons = []; |
|
29 | - public $defaults; |
|
30 | - public $deprecated = []; |
|
31 | - public $file; |
|
32 | - public $languages; |
|
33 | - public $mceShortcodes = []; //defined elsewhere |
|
34 | - public $name; |
|
35 | - public $postTypeColumns = []; // defined elsewhere |
|
36 | - public $reviewTypes; |
|
37 | - public $schemas = []; //defined elsewhere |
|
38 | - public $version; |
|
28 | + public $addons = []; |
|
29 | + public $defaults; |
|
30 | + public $deprecated = []; |
|
31 | + public $file; |
|
32 | + public $languages; |
|
33 | + public $mceShortcodes = []; //defined elsewhere |
|
34 | + public $name; |
|
35 | + public $postTypeColumns = []; // defined elsewhere |
|
36 | + public $reviewTypes; |
|
37 | + public $schemas = []; //defined elsewhere |
|
38 | + public $version; |
|
39 | 39 | |
40 | - public function __construct() |
|
41 | - { |
|
42 | - static::$instance = $this; |
|
43 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
44 | - $plugin = get_file_data($this->file, [ |
|
45 | - 'languages' => 'Domain Path', |
|
46 | - 'name' => 'Plugin Name', |
|
47 | - 'version' => 'Version', |
|
48 | - ], 'plugin'); |
|
49 | - array_walk($plugin, function ($value, $key) { |
|
50 | - $this->$key = $value; |
|
51 | - }); |
|
52 | - } |
|
40 | + public function __construct() |
|
41 | + { |
|
42 | + static::$instance = $this; |
|
43 | + $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
44 | + $plugin = get_file_data($this->file, [ |
|
45 | + 'languages' => 'Domain Path', |
|
46 | + 'name' => 'Plugin Name', |
|
47 | + 'version' => 'Version', |
|
48 | + ], 'plugin'); |
|
49 | + array_walk($plugin, function ($value, $key) { |
|
50 | + $this->$key = $value; |
|
51 | + }); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function activate() |
|
58 | - { |
|
59 | - $this->scheduleCronJob(); |
|
60 | - add_option(static::PREFIX.'activated', true); |
|
61 | - } |
|
54 | + /** |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function activate() |
|
58 | + { |
|
59 | + $this->scheduleCronJob(); |
|
60 | + add_option(static::PREFIX.'activated', true); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param string $view |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function build($view, array $data = []) |
|
68 | - { |
|
69 | - ob_start(); |
|
70 | - $this->render($view, $data); |
|
71 | - return ob_get_clean(); |
|
72 | - } |
|
63 | + /** |
|
64 | + * @param string $view |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function build($view, array $data = []) |
|
68 | + { |
|
69 | + ob_start(); |
|
70 | + $this->render($view, $data); |
|
71 | + return ob_get_clean(); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $capability |
|
76 | - * @return bool |
|
77 | - */ |
|
78 | - public function can($capability) |
|
79 | - { |
|
80 | - return $this->make(Role::class)->can($capability); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @param string $capability |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | + public function can($capability) |
|
79 | + { |
|
80 | + return $this->make(Role::class)->can($capability); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function catchFatalError() |
|
87 | - { |
|
88 | - $error = error_get_last(); |
|
89 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
90 | - return; |
|
91 | - } |
|
92 | - glsr_log()->error($error['message']); |
|
93 | - } |
|
83 | + /** |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function catchFatalError() |
|
87 | + { |
|
88 | + $error = error_get_last(); |
|
89 | + if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
90 | + return; |
|
91 | + } |
|
92 | + glsr_log()->error($error['message']); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @param string $name |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function config($name) |
|
100 | - { |
|
101 | - $configFile = $this->path('config/'.$name.'.php'); |
|
102 | - $config = file_exists($configFile) |
|
103 | - ? include $configFile |
|
104 | - : []; |
|
105 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
106 | - } |
|
95 | + /** |
|
96 | + * @param string $name |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function config($name) |
|
100 | + { |
|
101 | + $configFile = $this->path('config/'.$name.'.php'); |
|
102 | + $config = file_exists($configFile) |
|
103 | + ? include $configFile |
|
104 | + : []; |
|
105 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * @param string $property |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function constant($property, $className = 'static') |
|
113 | - { |
|
114 | - $constant = $className.'::'.$property; |
|
115 | - return defined($constant) |
|
116 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
117 | - : ''; |
|
118 | - } |
|
108 | + /** |
|
109 | + * @param string $property |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function constant($property, $className = 'static') |
|
113 | + { |
|
114 | + $constant = $className.'::'.$property; |
|
115 | + return defined($constant) |
|
116 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
117 | + : ''; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - public function deactivate() |
|
124 | - { |
|
125 | - $this->unscheduleCronJob(); |
|
126 | - } |
|
120 | + /** |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + public function deactivate() |
|
124 | + { |
|
125 | + $this->unscheduleCronJob(); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @param string $view |
|
130 | - * @return void|string |
|
131 | - */ |
|
132 | - public function file($view) |
|
133 | - { |
|
134 | - $view.= '.php'; |
|
135 | - $filePaths = []; |
|
136 | - if (Str::startsWith('templates/', $view)) { |
|
137 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
138 | - } |
|
139 | - $filePaths[] = $this->path($view); |
|
140 | - $filePaths[] = $this->path('views/'.$view); |
|
141 | - foreach ($filePaths as $file) { |
|
142 | - if (!file_exists($file)) { |
|
143 | - continue; |
|
144 | - } |
|
145 | - return $file; |
|
146 | - } |
|
147 | - } |
|
128 | + /** |
|
129 | + * @param string $view |
|
130 | + * @return void|string |
|
131 | + */ |
|
132 | + public function file($view) |
|
133 | + { |
|
134 | + $view.= '.php'; |
|
135 | + $filePaths = []; |
|
136 | + if (Str::startsWith('templates/', $view)) { |
|
137 | + $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
138 | + } |
|
139 | + $filePaths[] = $this->path($view); |
|
140 | + $filePaths[] = $this->path('views/'.$view); |
|
141 | + foreach ($filePaths as $file) { |
|
142 | + if (!file_exists($file)) { |
|
143 | + continue; |
|
144 | + } |
|
145 | + return $file; |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - public function getDefaults() |
|
153 | - { |
|
154 | - if (empty($this->defaults)) { |
|
155 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
156 | - } |
|
157 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
158 | - } |
|
149 | + /** |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + public function getDefaults() |
|
153 | + { |
|
154 | + if (empty($this->defaults)) { |
|
155 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
156 | + } |
|
157 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @param string $page |
|
162 | - * @param string $tab |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public function getPermission($page = '', $tab = 'index') |
|
166 | - { |
|
167 | - $fallback = 'edit_posts'; |
|
168 | - $permissions = [ |
|
169 | - 'addons' => 'install_plugins', |
|
170 | - 'documentation' => [ |
|
171 | - 'faq' => 'edit_others_posts', |
|
172 | - 'functions' => 'manage_options', |
|
173 | - 'hooks' => 'edit_others_posts', |
|
174 | - 'index' => 'edit_posts', |
|
175 | - 'support' => 'edit_others_posts', |
|
176 | - ], |
|
177 | - 'settings' => 'manage_options', |
|
178 | - 'tools' => [ |
|
179 | - 'console' => 'edit_others_posts', |
|
180 | - 'general' => 'edit_others_posts', |
|
181 | - 'index' => 'edit_others_posts', |
|
182 | - 'sync' => 'manage_options', |
|
183 | - 'system-info' => 'edit_others_posts', |
|
184 | - ] |
|
185 | - ]; |
|
186 | - $permission = Arr::get($permissions, $page, $fallback); |
|
187 | - if (is_array($permission)) { |
|
188 | - $permission = Arr::get($permission, $tab, $fallback); |
|
189 | - } |
|
190 | - return empty($permission) || !is_string($permission) |
|
191 | - ? $fallback |
|
192 | - : $permission; |
|
193 | - } |
|
160 | + /** |
|
161 | + * @param string $page |
|
162 | + * @param string $tab |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public function getPermission($page = '', $tab = 'index') |
|
166 | + { |
|
167 | + $fallback = 'edit_posts'; |
|
168 | + $permissions = [ |
|
169 | + 'addons' => 'install_plugins', |
|
170 | + 'documentation' => [ |
|
171 | + 'faq' => 'edit_others_posts', |
|
172 | + 'functions' => 'manage_options', |
|
173 | + 'hooks' => 'edit_others_posts', |
|
174 | + 'index' => 'edit_posts', |
|
175 | + 'support' => 'edit_others_posts', |
|
176 | + ], |
|
177 | + 'settings' => 'manage_options', |
|
178 | + 'tools' => [ |
|
179 | + 'console' => 'edit_others_posts', |
|
180 | + 'general' => 'edit_others_posts', |
|
181 | + 'index' => 'edit_others_posts', |
|
182 | + 'sync' => 'manage_options', |
|
183 | + 'system-info' => 'edit_others_posts', |
|
184 | + ] |
|
185 | + ]; |
|
186 | + $permission = Arr::get($permissions, $page, $fallback); |
|
187 | + if (is_array($permission)) { |
|
188 | + $permission = Arr::get($permission, $tab, $fallback); |
|
189 | + } |
|
190 | + return empty($permission) || !is_string($permission) |
|
191 | + ? $fallback |
|
192 | + : $permission; |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @param string $page |
|
197 | - * @param string $tab |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function hasPermission($page = '', $tab = 'index') |
|
201 | - { |
|
202 | - $isAdmin = $this->isAdmin(); |
|
203 | - return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
204 | - } |
|
195 | + /** |
|
196 | + * @param string $page |
|
197 | + * @param string $tab |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function hasPermission($page = '', $tab = 'index') |
|
201 | + { |
|
202 | + $isAdmin = $this->isAdmin(); |
|
203 | + return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * @return void |
|
208 | - */ |
|
209 | - public function init() |
|
210 | - { |
|
211 | - $this->make(Actions::class)->run(); |
|
212 | - $this->make(Filters::class)->run(); |
|
213 | - } |
|
206 | + /** |
|
207 | + * @return void |
|
208 | + */ |
|
209 | + public function init() |
|
210 | + { |
|
211 | + $this->make(Actions::class)->run(); |
|
212 | + $this->make(Filters::class)->run(); |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * @return bool |
|
217 | - */ |
|
218 | - public function isAdmin() |
|
219 | - { |
|
220 | - return is_admin() && !wp_doing_ajax(); |
|
221 | - } |
|
215 | + /** |
|
216 | + * @return bool |
|
217 | + */ |
|
218 | + public function isAdmin() |
|
219 | + { |
|
220 | + return is_admin() && !wp_doing_ajax(); |
|
221 | + } |
|
222 | 222 | |
223 | - /** |
|
224 | - * @param string $file |
|
225 | - * @return string |
|
226 | - */ |
|
227 | - public function path($file = '', $realpath = true) |
|
228 | - { |
|
229 | - $path = plugin_dir_path($this->file); |
|
230 | - if (!$realpath) { |
|
231 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
232 | - } |
|
233 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
234 | - return apply_filters('site-reviews/path', $path, $file); |
|
235 | - } |
|
223 | + /** |
|
224 | + * @param string $file |
|
225 | + * @return string |
|
226 | + */ |
|
227 | + public function path($file = '', $realpath = true) |
|
228 | + { |
|
229 | + $path = plugin_dir_path($this->file); |
|
230 | + if (!$realpath) { |
|
231 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
232 | + } |
|
233 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
234 | + return apply_filters('site-reviews/path', $path, $file); |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * @param object $addon |
|
239 | - * @return void |
|
240 | - */ |
|
241 | - public function register($addon) |
|
242 | - { |
|
243 | - try { |
|
244 | - $reflection = new \ReflectionClass($addon); |
|
245 | - if ($id = $reflection->getConstant('ID')) { |
|
246 | - $this->addons[] = $id; |
|
247 | - $this->bind($id, $addon); |
|
248 | - $addon->init(); |
|
249 | - } |
|
250 | - } catch(\ReflectionException $e) { |
|
251 | - glsr_log()->error('Attempted to register an invalid addon.'); |
|
252 | - } |
|
253 | - } |
|
237 | + /** |
|
238 | + * @param object $addon |
|
239 | + * @return void |
|
240 | + */ |
|
241 | + public function register($addon) |
|
242 | + { |
|
243 | + try { |
|
244 | + $reflection = new \ReflectionClass($addon); |
|
245 | + if ($id = $reflection->getConstant('ID')) { |
|
246 | + $this->addons[] = $id; |
|
247 | + $this->bind($id, $addon); |
|
248 | + $addon->init(); |
|
249 | + } |
|
250 | + } catch(\ReflectionException $e) { |
|
251 | + glsr_log()->error('Attempted to register an invalid addon.'); |
|
252 | + } |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * @return void |
|
257 | - */ |
|
258 | - public function registerAddons() |
|
259 | - { |
|
260 | - do_action('site-reviews/addon/register', $this); |
|
261 | - } |
|
255 | + /** |
|
256 | + * @return void |
|
257 | + */ |
|
258 | + public function registerAddons() |
|
259 | + { |
|
260 | + do_action('site-reviews/addon/register', $this); |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * @return void |
|
265 | - */ |
|
266 | - public function registerLanguages() |
|
267 | - { |
|
268 | - load_plugin_textdomain(static::ID, false, |
|
269 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
270 | - ); |
|
271 | - } |
|
263 | + /** |
|
264 | + * @return void |
|
265 | + */ |
|
266 | + public function registerLanguages() |
|
267 | + { |
|
268 | + load_plugin_textdomain(static::ID, false, |
|
269 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
270 | + ); |
|
271 | + } |
|
272 | 272 | |
273 | - /** |
|
274 | - * @return void |
|
275 | - */ |
|
276 | - public function registerReviewTypes() |
|
277 | - { |
|
278 | - $types = apply_filters('site-reviews/addon/types', []); |
|
279 | - $this->reviewTypes = wp_parse_args($types, [ |
|
280 | - 'local' => __('Local', 'site-reviews'), |
|
281 | - ]); |
|
282 | - } |
|
273 | + /** |
|
274 | + * @return void |
|
275 | + */ |
|
276 | + public function registerReviewTypes() |
|
277 | + { |
|
278 | + $types = apply_filters('site-reviews/addon/types', []); |
|
279 | + $this->reviewTypes = wp_parse_args($types, [ |
|
280 | + 'local' => __('Local', 'site-reviews'), |
|
281 | + ]); |
|
282 | + } |
|
283 | 283 | |
284 | - /** |
|
285 | - * @param string $view |
|
286 | - * @return void |
|
287 | - */ |
|
288 | - public function render($view, array $data = []) |
|
289 | - { |
|
290 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
291 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
292 | - if (!file_exists($file)) { |
|
293 | - glsr_log()->error('File not found: '.$file); |
|
294 | - return; |
|
295 | - } |
|
296 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
297 | - extract($data); |
|
298 | - include $file; |
|
299 | - } |
|
284 | + /** |
|
285 | + * @param string $view |
|
286 | + * @return void |
|
287 | + */ |
|
288 | + public function render($view, array $data = []) |
|
289 | + { |
|
290 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
291 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
292 | + if (!file_exists($file)) { |
|
293 | + glsr_log()->error('File not found: '.$file); |
|
294 | + return; |
|
295 | + } |
|
296 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
297 | + extract($data); |
|
298 | + include $file; |
|
299 | + } |
|
300 | 300 | |
301 | - /** |
|
302 | - * @return void |
|
303 | - */ |
|
304 | - public function scheduleCronJob() |
|
305 | - { |
|
306 | - if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
307 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
308 | - } |
|
309 | - } |
|
301 | + /** |
|
302 | + * @return void |
|
303 | + */ |
|
304 | + public function scheduleCronJob() |
|
305 | + { |
|
306 | + if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
307 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
308 | + } |
|
309 | + } |
|
310 | 310 | |
311 | - /** |
|
312 | - * @return void |
|
313 | - */ |
|
314 | - public function setDefaults() |
|
315 | - { |
|
316 | - if (get_option(static::PREFIX.'activated')) { |
|
317 | - $this->make(DefaultsManager::class)->set(); |
|
318 | - delete_option(static::PREFIX.'activated'); |
|
319 | - } |
|
320 | - } |
|
311 | + /** |
|
312 | + * @return void |
|
313 | + */ |
|
314 | + public function setDefaults() |
|
315 | + { |
|
316 | + if (get_option(static::PREFIX.'activated')) { |
|
317 | + $this->make(DefaultsManager::class)->set(); |
|
318 | + delete_option(static::PREFIX.'activated'); |
|
319 | + } |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * @param string $file |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function themePath($file = '') |
|
327 | - { |
|
328 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
329 | - } |
|
322 | + /** |
|
323 | + * @param string $file |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function themePath($file = '') |
|
327 | + { |
|
328 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * @return void |
|
333 | - */ |
|
334 | - public function unscheduleCronJob() |
|
335 | - { |
|
336 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
337 | - } |
|
331 | + /** |
|
332 | + * @return void |
|
333 | + */ |
|
334 | + public function unscheduleCronJob() |
|
335 | + { |
|
336 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
337 | + } |
|
338 | 338 | |
339 | - /** |
|
340 | - * @param string $path |
|
341 | - * @return string |
|
342 | - */ |
|
343 | - public function url($path = '') |
|
344 | - { |
|
345 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
346 | - return apply_filters('site-reviews/url', $url, $path); |
|
347 | - } |
|
339 | + /** |
|
340 | + * @param string $path |
|
341 | + * @return string |
|
342 | + */ |
|
343 | + public function url($path = '') |
|
344 | + { |
|
345 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
346 | + return apply_filters('site-reviews/url', $url, $path); |
|
347 | + } |
|
348 | 348 | |
349 | - /** |
|
350 | - * @param string $versionLevel |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - public function version($versionLevel = '') |
|
354 | - { |
|
355 | - $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
356 | - preg_match($pattern, $this->version, $matches); |
|
357 | - switch ($versionLevel) { |
|
358 | - case 'major': |
|
359 | - $version = Arr::get($matches, 1); |
|
360 | - break; |
|
361 | - case 'minor': |
|
362 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
363 | - break; |
|
364 | - case 'patch': |
|
365 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
366 | - break; |
|
367 | - } |
|
368 | - return empty($version) |
|
369 | - ? $this->version |
|
370 | - : $version; |
|
371 | - } |
|
349 | + /** |
|
350 | + * @param string $versionLevel |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + public function version($versionLevel = '') |
|
354 | + { |
|
355 | + $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
356 | + preg_match($pattern, $this->version, $matches); |
|
357 | + switch ($versionLevel) { |
|
358 | + case 'major': |
|
359 | + $version = Arr::get($matches, 1); |
|
360 | + break; |
|
361 | + case 'minor': |
|
362 | + $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
363 | + break; |
|
364 | + case 'patch': |
|
365 | + $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
366 | + break; |
|
367 | + } |
|
368 | + return empty($version) |
|
369 | + ? $this->version |
|
370 | + : $version; |
|
371 | + } |
|
372 | 372 | } |
@@ -8,28 +8,28 @@ |
||
8 | 8 | |
9 | 9 | class TogglePinned |
10 | 10 | { |
11 | - /** |
|
12 | - * @return bool |
|
13 | - */ |
|
14 | - public function handle(Command $command) |
|
15 | - { |
|
16 | - if (!get_post($command->id)) { |
|
17 | - return false; |
|
18 | - } |
|
19 | - if (!glsr()->can('edit_others_posts')) { |
|
20 | - $meta = (Database::class)->get($command->id, 'pinned'); |
|
21 | - return wp_validate_boolean($meta); |
|
22 | - } |
|
23 | - if (is_null($command->pinned)) { |
|
24 | - $meta = glsr(Database::class)->get($command->id, 'pinned'); |
|
25 | - $command->pinned = !wp_validate_boolean($meta); |
|
26 | - } else { |
|
27 | - $notice = $command->pinned |
|
28 | - ? __('Review pinned.', 'site-reviews') |
|
29 | - : __('Review unpinned.', 'site-reviews'); |
|
30 | - glsr(Notice::class)->addSuccess($notice); |
|
31 | - } |
|
32 | - glsr(Database::class)->update($command->id, 'pinned', $command->pinned); |
|
33 | - return $command->pinned; |
|
34 | - } |
|
11 | + /** |
|
12 | + * @return bool |
|
13 | + */ |
|
14 | + public function handle(Command $command) |
|
15 | + { |
|
16 | + if (!get_post($command->id)) { |
|
17 | + return false; |
|
18 | + } |
|
19 | + if (!glsr()->can('edit_others_posts')) { |
|
20 | + $meta = (Database::class)->get($command->id, 'pinned'); |
|
21 | + return wp_validate_boolean($meta); |
|
22 | + } |
|
23 | + if (is_null($command->pinned)) { |
|
24 | + $meta = glsr(Database::class)->get($command->id, 'pinned'); |
|
25 | + $command->pinned = !wp_validate_boolean($meta); |
|
26 | + } else { |
|
27 | + $notice = $command->pinned |
|
28 | + ? __('Review pinned.', 'site-reviews') |
|
29 | + : __('Review unpinned.', 'site-reviews'); |
|
30 | + glsr(Notice::class)->addSuccess($notice); |
|
31 | + } |
|
32 | + glsr(Database::class)->update($command->id, 'pinned', $command->pinned); |
|
33 | + return $command->pinned; |
|
34 | + } |
|
35 | 35 | } |
@@ -6,133 +6,133 @@ |
||
6 | 6 | |
7 | 7 | class Role |
8 | 8 | { |
9 | - /** |
|
10 | - * @param string $role |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function addCapabilities($role) |
|
14 | - { |
|
15 | - $roleCapabilities = $this->roleCapabilities(); |
|
16 | - $wpRole = get_role($role); |
|
17 | - if (empty($wpRole) || !array_key_exists($role, $roleCapabilities)) { |
|
18 | - return; |
|
19 | - } |
|
20 | - foreach ($roleCapabilities[$role] as $capability) { |
|
21 | - $wpRole->add_cap($this->normalizeCapability($capability)); |
|
22 | - } |
|
23 | - } |
|
9 | + /** |
|
10 | + * @param string $role |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function addCapabilities($role) |
|
14 | + { |
|
15 | + $roleCapabilities = $this->roleCapabilities(); |
|
16 | + $wpRole = get_role($role); |
|
17 | + if (empty($wpRole) || !array_key_exists($role, $roleCapabilities)) { |
|
18 | + return; |
|
19 | + } |
|
20 | + foreach ($roleCapabilities[$role] as $capability) { |
|
21 | + $wpRole->add_cap($this->normalizeCapability($capability)); |
|
22 | + } |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param string $capability |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public function can($capability) |
|
30 | - { |
|
31 | - return in_array($capability, $this->capabilities()) |
|
32 | - ? current_user_can($this->normalizeCapability($capability)) |
|
33 | - : current_user_can($capability); |
|
34 | - } |
|
25 | + /** |
|
26 | + * @param string $capability |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public function can($capability) |
|
30 | + { |
|
31 | + return in_array($capability, $this->capabilities()) |
|
32 | + ? current_user_can($this->normalizeCapability($capability)) |
|
33 | + : current_user_can($capability); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $role |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function removeCapabilities($role) |
|
41 | - { |
|
42 | - $wpRole = get_role($role); |
|
43 | - if (empty($wpRole) || 'administrator' === $role) { // do not remove from administrator role |
|
44 | - return; |
|
45 | - } |
|
46 | - foreach ($this->capabilities() as $capability) { |
|
47 | - $wpRole->remove_cap($this->normalizeCapability($capability)); |
|
48 | - } |
|
49 | - } |
|
36 | + /** |
|
37 | + * @param string $role |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function removeCapabilities($role) |
|
41 | + { |
|
42 | + $wpRole = get_role($role); |
|
43 | + if (empty($wpRole) || 'administrator' === $role) { // do not remove from administrator role |
|
44 | + return; |
|
45 | + } |
|
46 | + foreach ($this->capabilities() as $capability) { |
|
47 | + $wpRole->remove_cap($this->normalizeCapability($capability)); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function resetAll() |
|
55 | - { |
|
56 | - $roles = array_keys(wp_roles()->roles); |
|
57 | - array_walk($roles, [$this, 'removeCapabilities']); |
|
58 | - $roles = array_keys($this->roleCapabilities()); |
|
59 | - array_walk($roles, [$this, 'addCapabilities']); |
|
60 | - } |
|
51 | + /** |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function resetAll() |
|
55 | + { |
|
56 | + $roles = array_keys(wp_roles()->roles); |
|
57 | + array_walk($roles, [$this, 'removeCapabilities']); |
|
58 | + $roles = array_keys($this->roleCapabilities()); |
|
59 | + array_walk($roles, [$this, 'addCapabilities']); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - protected function capabilities() |
|
66 | - { |
|
67 | - $capabilities = [ |
|
68 | - 'delete_others_posts', |
|
69 | - 'delete_post', |
|
70 | - 'delete_posts', |
|
71 | - 'delete_private_posts', |
|
72 | - 'delete_published_posts', |
|
73 | - 'edit_others_posts', |
|
74 | - 'edit_post', |
|
75 | - 'edit_posts', |
|
76 | - 'edit_private_posts', |
|
77 | - 'edit_published_posts', |
|
78 | - 'publish_posts', |
|
79 | - 'read_post', |
|
80 | - 'read_private_posts', |
|
81 | - ]; |
|
82 | - return apply_filters('site-reviews/capabilities', $capabilities); |
|
83 | - } |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + protected function capabilities() |
|
66 | + { |
|
67 | + $capabilities = [ |
|
68 | + 'delete_others_posts', |
|
69 | + 'delete_post', |
|
70 | + 'delete_posts', |
|
71 | + 'delete_private_posts', |
|
72 | + 'delete_published_posts', |
|
73 | + 'edit_others_posts', |
|
74 | + 'edit_post', |
|
75 | + 'edit_posts', |
|
76 | + 'edit_private_posts', |
|
77 | + 'edit_published_posts', |
|
78 | + 'publish_posts', |
|
79 | + 'read_post', |
|
80 | + 'read_private_posts', |
|
81 | + ]; |
|
82 | + return apply_filters('site-reviews/capabilities', $capabilities); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param string $capability |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - protected function normalizeCapability($capability) |
|
90 | - { |
|
91 | - return str_replace('post', Application::POST_TYPE, $capability); |
|
92 | - } |
|
85 | + /** |
|
86 | + * @param string $capability |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + protected function normalizeCapability($capability) |
|
90 | + { |
|
91 | + return str_replace('post', Application::POST_TYPE, $capability); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - protected function roleCapabilities() |
|
98 | - { |
|
99 | - $capabilities = [ |
|
100 | - 'administrator' => [ |
|
101 | - 'delete_others_posts', |
|
102 | - 'delete_posts', |
|
103 | - 'delete_private_posts', |
|
104 | - 'delete_published_posts', |
|
105 | - 'edit_others_posts', |
|
106 | - 'edit_posts', |
|
107 | - 'edit_private_posts', |
|
108 | - 'edit_published_posts', |
|
109 | - 'publish_posts', |
|
110 | - 'read_private_posts', |
|
111 | - ], |
|
112 | - 'editor' => [ |
|
113 | - 'delete_others_posts', |
|
114 | - 'delete_posts', |
|
115 | - 'delete_private_posts', |
|
116 | - 'delete_published_posts', |
|
117 | - 'edit_others_posts', |
|
118 | - 'edit_posts', |
|
119 | - 'edit_private_posts', |
|
120 | - 'edit_published_posts', |
|
121 | - 'publish_posts', |
|
122 | - 'read_private_posts', |
|
123 | - ], |
|
124 | - 'author' => [ |
|
125 | - 'delete_posts', |
|
126 | - 'delete_published_posts', |
|
127 | - 'edit_posts', |
|
128 | - 'edit_published_posts', |
|
129 | - 'publish_posts', |
|
130 | - ], |
|
131 | - 'contributor' => [ |
|
132 | - 'delete_posts', |
|
133 | - 'edit_posts', |
|
134 | - ], |
|
135 | - ]; |
|
136 | - return apply_filters('site-reviews/capabilities/for-roles', $capabilities); |
|
137 | - } |
|
94 | + /** |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + protected function roleCapabilities() |
|
98 | + { |
|
99 | + $capabilities = [ |
|
100 | + 'administrator' => [ |
|
101 | + 'delete_others_posts', |
|
102 | + 'delete_posts', |
|
103 | + 'delete_private_posts', |
|
104 | + 'delete_published_posts', |
|
105 | + 'edit_others_posts', |
|
106 | + 'edit_posts', |
|
107 | + 'edit_private_posts', |
|
108 | + 'edit_published_posts', |
|
109 | + 'publish_posts', |
|
110 | + 'read_private_posts', |
|
111 | + ], |
|
112 | + 'editor' => [ |
|
113 | + 'delete_others_posts', |
|
114 | + 'delete_posts', |
|
115 | + 'delete_private_posts', |
|
116 | + 'delete_published_posts', |
|
117 | + 'edit_others_posts', |
|
118 | + 'edit_posts', |
|
119 | + 'edit_private_posts', |
|
120 | + 'edit_published_posts', |
|
121 | + 'publish_posts', |
|
122 | + 'read_private_posts', |
|
123 | + ], |
|
124 | + 'author' => [ |
|
125 | + 'delete_posts', |
|
126 | + 'delete_published_posts', |
|
127 | + 'edit_posts', |
|
128 | + 'edit_published_posts', |
|
129 | + 'publish_posts', |
|
130 | + ], |
|
131 | + 'contributor' => [ |
|
132 | + 'delete_posts', |
|
133 | + 'edit_posts', |
|
134 | + ], |
|
135 | + ]; |
|
136 | + return apply_filters('site-reviews/capabilities/for-roles', $capabilities); |
|
137 | + } |
|
138 | 138 | } |
@@ -15,197 +15,197 @@ |
||
15 | 15 | |
16 | 16 | class MenuController extends Controller |
17 | 17 | { |
18 | - /** |
|
19 | - * @return void |
|
20 | - * @action admin_menu |
|
21 | - */ |
|
22 | - public function registerMenuCount() |
|
23 | - { |
|
24 | - global $menu, $typenow; |
|
25 | - foreach ($menu as $key => $value) { |
|
26 | - if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
27 | - continue; |
|
28 | - } |
|
29 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
30 | - $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
31 | - 'class' => 'unapproved-count', |
|
32 | - ]); |
|
33 | - $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
34 | - 'class' => 'awaiting-mod count-'.$postCount->pending, |
|
35 | - ]); |
|
36 | - $menu[$key][0].= ' '.$awaitingModeration; |
|
37 | - if (Application::POST_TYPE === $typenow) { |
|
38 | - $menu[$key][4].= ' current'; |
|
39 | - } |
|
40 | - break; |
|
41 | - } |
|
42 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + * @action admin_menu |
|
21 | + */ |
|
22 | + public function registerMenuCount() |
|
23 | + { |
|
24 | + global $menu, $typenow; |
|
25 | + foreach ($menu as $key => $value) { |
|
26 | + if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE) { |
|
27 | + continue; |
|
28 | + } |
|
29 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
30 | + $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
31 | + 'class' => 'unapproved-count', |
|
32 | + ]); |
|
33 | + $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
34 | + 'class' => 'awaiting-mod count-'.$postCount->pending, |
|
35 | + ]); |
|
36 | + $menu[$key][0].= ' '.$awaitingModeration; |
|
37 | + if (Application::POST_TYPE === $typenow) { |
|
38 | + $menu[$key][4].= ' current'; |
|
39 | + } |
|
40 | + break; |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - * @action admin_menu |
|
47 | - */ |
|
48 | - public function registerSubMenus() |
|
49 | - { |
|
50 | - $pages = $this->parseWithFilter('submenu/pages', [ |
|
51 | - 'settings' => __('Settings', 'site-reviews'), |
|
52 | - 'tools' => __('Tools', 'site-reviews'), |
|
53 | - 'addons' => __('Add-ons', 'site-reviews'), |
|
54 | - 'documentation' => __('Help', 'site-reviews'), |
|
55 | - ]); |
|
56 | - foreach ($pages as $slug => $title) { |
|
57 | - $method = Helper::buildMethodName('render-'.$slug.'-menu'); |
|
58 | - $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
59 | - if (!is_callable($callback)) { |
|
60 | - continue; |
|
61 | - } |
|
62 | - add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
63 | - } |
|
64 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + * @action admin_menu |
|
47 | + */ |
|
48 | + public function registerSubMenus() |
|
49 | + { |
|
50 | + $pages = $this->parseWithFilter('submenu/pages', [ |
|
51 | + 'settings' => __('Settings', 'site-reviews'), |
|
52 | + 'tools' => __('Tools', 'site-reviews'), |
|
53 | + 'addons' => __('Add-ons', 'site-reviews'), |
|
54 | + 'documentation' => __('Help', 'site-reviews'), |
|
55 | + ]); |
|
56 | + foreach ($pages as $slug => $title) { |
|
57 | + $method = Helper::buildMethodName('render-'.$slug.'-menu'); |
|
58 | + $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
59 | + if (!is_callable($callback)) { |
|
60 | + continue; |
|
61 | + } |
|
62 | + add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, glsr()->getPermission($slug), $slug, $callback); |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return void |
|
68 | - * @see $this->registerSubMenus() |
|
69 | - * @callback add_submenu_page |
|
70 | - */ |
|
71 | - public function renderAddonsMenu() |
|
72 | - { |
|
73 | - $this->renderPage('addons', [ |
|
74 | - 'template' => glsr(Template::class), |
|
75 | - ]); |
|
76 | - } |
|
66 | + /** |
|
67 | + * @return void |
|
68 | + * @see $this->registerSubMenus() |
|
69 | + * @callback add_submenu_page |
|
70 | + */ |
|
71 | + public function renderAddonsMenu() |
|
72 | + { |
|
73 | + $this->renderPage('addons', [ |
|
74 | + 'template' => glsr(Template::class), |
|
75 | + ]); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - * @see $this->registerSubMenus() |
|
81 | - * @callback add_submenu_page |
|
82 | - */ |
|
83 | - public function renderDocumentationMenu() |
|
84 | - { |
|
85 | - $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
86 | - 'support' => __('Support', 'site-reviews'), |
|
87 | - 'faq' => __('FAQ', 'site-reviews'), |
|
88 | - 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
89 | - 'hooks' => __('Hooks', 'site-reviews'), |
|
90 | - 'functions' => __('Functions', 'site-reviews'), |
|
91 | - 'addons' => __('Addons', 'site-reviews'), |
|
92 | - ]); |
|
93 | - $addons = apply_filters('site-reviews/addon/documentation', []); |
|
94 | - ksort($addons); |
|
95 | - if (empty($addons)) { |
|
96 | - unset($tabs['addons']); |
|
97 | - } |
|
98 | - $this->renderPage('documentation', [ |
|
99 | - 'addons' => $addons, |
|
100 | - 'tabs' => $tabs, |
|
101 | - ]); |
|
102 | - } |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + * @see $this->registerSubMenus() |
|
81 | + * @callback add_submenu_page |
|
82 | + */ |
|
83 | + public function renderDocumentationMenu() |
|
84 | + { |
|
85 | + $tabs = $this->parseWithFilter('documentation/tabs', [ |
|
86 | + 'support' => __('Support', 'site-reviews'), |
|
87 | + 'faq' => __('FAQ', 'site-reviews'), |
|
88 | + 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
89 | + 'hooks' => __('Hooks', 'site-reviews'), |
|
90 | + 'functions' => __('Functions', 'site-reviews'), |
|
91 | + 'addons' => __('Addons', 'site-reviews'), |
|
92 | + ]); |
|
93 | + $addons = apply_filters('site-reviews/addon/documentation', []); |
|
94 | + ksort($addons); |
|
95 | + if (empty($addons)) { |
|
96 | + unset($tabs['addons']); |
|
97 | + } |
|
98 | + $this->renderPage('documentation', [ |
|
99 | + 'addons' => $addons, |
|
100 | + 'tabs' => $tabs, |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void |
|
106 | - * @see $this->registerSubMenus() |
|
107 | - * @callback add_submenu_page |
|
108 | - */ |
|
109 | - public function renderSettingsMenu() |
|
110 | - { |
|
111 | - $tabs = $this->parseWithFilter('settings/tabs', [ |
|
112 | - 'general' => __('General', 'site-reviews'), |
|
113 | - 'reviews' => __('Reviews', 'site-reviews'), |
|
114 | - 'submissions' => __('Submissions', 'site-reviews'), |
|
115 | - 'schema' => __('Schema', 'site-reviews'), |
|
116 | - 'translations' => __('Translations', 'site-reviews'), |
|
117 | - 'addons' => __('Addons', 'site-reviews'), |
|
118 | - 'licenses' => __('Licenses', 'site-reviews'), |
|
119 | - ]); |
|
120 | - if (empty(Arr::get(glsr()->defaults, 'settings.addons'))) { |
|
121 | - unset($tabs['addons']); |
|
122 | - } |
|
123 | - if (empty(Arr::get(glsr()->defaults, 'settings.licenses'))) { |
|
124 | - unset($tabs['licenses']); |
|
125 | - } |
|
126 | - $this->renderPage('settings', [ |
|
127 | - 'settings' => glsr(Settings::class), |
|
128 | - 'tabs' => $tabs, |
|
129 | - ]); |
|
130 | - } |
|
104 | + /** |
|
105 | + * @return void |
|
106 | + * @see $this->registerSubMenus() |
|
107 | + * @callback add_submenu_page |
|
108 | + */ |
|
109 | + public function renderSettingsMenu() |
|
110 | + { |
|
111 | + $tabs = $this->parseWithFilter('settings/tabs', [ |
|
112 | + 'general' => __('General', 'site-reviews'), |
|
113 | + 'reviews' => __('Reviews', 'site-reviews'), |
|
114 | + 'submissions' => __('Submissions', 'site-reviews'), |
|
115 | + 'schema' => __('Schema', 'site-reviews'), |
|
116 | + 'translations' => __('Translations', 'site-reviews'), |
|
117 | + 'addons' => __('Addons', 'site-reviews'), |
|
118 | + 'licenses' => __('Licenses', 'site-reviews'), |
|
119 | + ]); |
|
120 | + if (empty(Arr::get(glsr()->defaults, 'settings.addons'))) { |
|
121 | + unset($tabs['addons']); |
|
122 | + } |
|
123 | + if (empty(Arr::get(glsr()->defaults, 'settings.licenses'))) { |
|
124 | + unset($tabs['licenses']); |
|
125 | + } |
|
126 | + $this->renderPage('settings', [ |
|
127 | + 'settings' => glsr(Settings::class), |
|
128 | + 'tabs' => $tabs, |
|
129 | + ]); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return void |
|
134 | - * @see $this->registerSubMenus() |
|
135 | - * @callback add_submenu_page |
|
136 | - */ |
|
137 | - public function renderToolsMenu() |
|
138 | - { |
|
139 | - $tabs = $this->parseWithFilter('tools/tabs', [ |
|
140 | - 'general' => __('General', 'site-reviews'), |
|
141 | - 'sync' => __('Sync Reviews', 'site-reviews'), |
|
142 | - 'console' => __('Console', 'site-reviews'), |
|
143 | - 'system-info' => __('System Info', 'site-reviews'), |
|
144 | - ]); |
|
145 | - if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
146 | - unset($tabs['sync']); |
|
147 | - } |
|
148 | - $this->renderPage('tools', [ |
|
149 | - 'data' => [ |
|
150 | - 'context' => [ |
|
151 | - 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
152 | - 'console' => strval(glsr(Console::class)), |
|
153 | - 'id' => Application::ID, |
|
154 | - 'system' => strval(glsr(System::class)), |
|
155 | - ], |
|
156 | - 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
157 | - ], |
|
158 | - 'tabs' => $tabs, |
|
159 | - 'template' => glsr(Template::class), |
|
160 | - ]); |
|
161 | - } |
|
132 | + /** |
|
133 | + * @return void |
|
134 | + * @see $this->registerSubMenus() |
|
135 | + * @callback add_submenu_page |
|
136 | + */ |
|
137 | + public function renderToolsMenu() |
|
138 | + { |
|
139 | + $tabs = $this->parseWithFilter('tools/tabs', [ |
|
140 | + 'general' => __('General', 'site-reviews'), |
|
141 | + 'sync' => __('Sync Reviews', 'site-reviews'), |
|
142 | + 'console' => __('Console', 'site-reviews'), |
|
143 | + 'system-info' => __('System Info', 'site-reviews'), |
|
144 | + ]); |
|
145 | + if (!apply_filters('site-reviews/addon/sync/enable', false)) { |
|
146 | + unset($tabs['sync']); |
|
147 | + } |
|
148 | + $this->renderPage('tools', [ |
|
149 | + 'data' => [ |
|
150 | + 'context' => [ |
|
151 | + 'base_url' => admin_url('edit.php?post_type='.Application::POST_TYPE), |
|
152 | + 'console' => strval(glsr(Console::class)), |
|
153 | + 'id' => Application::ID, |
|
154 | + 'system' => strval(glsr(System::class)), |
|
155 | + ], |
|
156 | + 'services' => apply_filters('site-reviews/addon/sync/services', []), |
|
157 | + ], |
|
158 | + 'tabs' => $tabs, |
|
159 | + 'template' => glsr(Template::class), |
|
160 | + ]); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @return void |
|
165 | - * @action admin_init |
|
166 | - */ |
|
167 | - public function setCustomPermissions() |
|
168 | - { |
|
169 | - foreach (wp_roles()->roles as $role => $value) { |
|
170 | - wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
171 | - } |
|
172 | - } |
|
163 | + /** |
|
164 | + * @return void |
|
165 | + * @action admin_init |
|
166 | + */ |
|
167 | + public function setCustomPermissions() |
|
168 | + { |
|
169 | + foreach (wp_roles()->roles as $role => $value) { |
|
170 | + wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - protected function getNotices() |
|
178 | - { |
|
179 | - return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
180 | - 'id' => 'glsr-notices', |
|
181 | - ]); |
|
182 | - } |
|
174 | + /** |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + protected function getNotices() |
|
178 | + { |
|
179 | + return glsr(Builder::class)->div(glsr(Notice::class)->get(), [ |
|
180 | + 'id' => 'glsr-notices', |
|
181 | + ]); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * @param string $hookSuffix |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - protected function parseWithFilter($hookSuffix, array $args = []) |
|
189 | - { |
|
190 | - if (Str::endsWith('/tabs', $hookSuffix)) { |
|
191 | - $page = str_replace('/tabs', '', $hookSuffix); |
|
192 | - foreach ($args as $tab => $title) { |
|
193 | - if (!glsr()->hasPermission($page, $tab)) { |
|
194 | - unset($args[$tab]); |
|
195 | - } |
|
196 | - } |
|
197 | - } |
|
198 | - return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
199 | - } |
|
184 | + /** |
|
185 | + * @param string $hookSuffix |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + protected function parseWithFilter($hookSuffix, array $args = []) |
|
189 | + { |
|
190 | + if (Str::endsWith('/tabs', $hookSuffix)) { |
|
191 | + $page = str_replace('/tabs', '', $hookSuffix); |
|
192 | + foreach ($args as $tab => $title) { |
|
193 | + if (!glsr()->hasPermission($page, $tab)) { |
|
194 | + unset($args[$tab]); |
|
195 | + } |
|
196 | + } |
|
197 | + } |
|
198 | + return apply_filters('site-reviews/addon/'.$hookSuffix, $args); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * @param string $page |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - protected function renderPage($page, array $data = []) |
|
206 | - { |
|
207 | - $data['http_referer'] = (string) wp_get_referer(); |
|
208 | - $data['notices'] = $this->getNotices(); |
|
209 | - glsr()->render('pages/'.$page.'/index', $data); |
|
210 | - } |
|
201 | + /** |
|
202 | + * @param string $page |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + protected function renderPage($page, array $data = []) |
|
206 | + { |
|
207 | + $data['http_referer'] = (string) wp_get_referer(); |
|
208 | + $data['notices'] = $this->getNotices(); |
|
209 | + glsr()->render('pages/'.$page.'/index', $data); |
|
210 | + } |
|
211 | 211 | } |
@@ -10,180 +10,180 @@ |
||
10 | 10 | |
11 | 11 | class Columns |
12 | 12 | { |
13 | - /** |
|
14 | - * @param int $postId |
|
15 | - * @return void|string |
|
16 | - */ |
|
17 | - public function buildColumnAssignedTo($postId) |
|
18 | - { |
|
19 | - $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | - if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | - return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | - 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | - ]); |
|
24 | - } |
|
25 | - } |
|
13 | + /** |
|
14 | + * @param int $postId |
|
15 | + * @return void|string |
|
16 | + */ |
|
17 | + public function buildColumnAssignedTo($postId) |
|
18 | + { |
|
19 | + $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | + if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | + return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | + 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | + ]); |
|
24 | + } |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param int $postId |
|
29 | - * @return void|string |
|
30 | - */ |
|
31 | - public function buildColumnEmail($postId) |
|
32 | - { |
|
33 | - if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
34 | - return $email; |
|
35 | - } |
|
36 | - } |
|
27 | + /** |
|
28 | + * @param int $postId |
|
29 | + * @return void|string |
|
30 | + */ |
|
31 | + public function buildColumnEmail($postId) |
|
32 | + { |
|
33 | + if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
34 | + return $email; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param int $postId |
|
40 | - * @return void|string |
|
41 | - */ |
|
42 | - public function buildColumnIpAddress($postId) |
|
43 | - { |
|
44 | - if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
45 | - return $ipAddress; |
|
46 | - } |
|
47 | - } |
|
38 | + /** |
|
39 | + * @param int $postId |
|
40 | + * @return void|string |
|
41 | + */ |
|
42 | + public function buildColumnIpAddress($postId) |
|
43 | + { |
|
44 | + if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
45 | + return $ipAddress; |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param int $postId |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function buildColumnPinned($postId) |
|
54 | - { |
|
55 | - $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
56 | - ? 'pinned ' |
|
57 | - : ''; |
|
58 | - if (glsr()->can('edit_others_posts')) { |
|
59 | - $pinned.= 'pin-review '; |
|
60 | - } |
|
61 | - return glsr(Builder::class)->i([ |
|
62 | - 'class' => $pinned.'dashicons dashicons-sticky', |
|
63 | - 'data-id' => $postId, |
|
64 | - ]); |
|
65 | - } |
|
49 | + /** |
|
50 | + * @param int $postId |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function buildColumnPinned($postId) |
|
54 | + { |
|
55 | + $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
56 | + ? 'pinned ' |
|
57 | + : ''; |
|
58 | + if (glsr()->can('edit_others_posts')) { |
|
59 | + $pinned.= 'pin-review '; |
|
60 | + } |
|
61 | + return glsr(Builder::class)->i([ |
|
62 | + 'class' => $pinned.'dashicons dashicons-sticky', |
|
63 | + 'data-id' => $postId, |
|
64 | + ]); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param int $postId |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function buildColumnResponse($postId) |
|
72 | - { |
|
73 | - return glsr(Database::class)->get($postId, 'response') |
|
74 | - ? __('Yes', 'site-reviews') |
|
75 | - : __('No', 'site-reviews'); |
|
76 | - } |
|
67 | + /** |
|
68 | + * @param int $postId |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function buildColumnResponse($postId) |
|
72 | + { |
|
73 | + return glsr(Database::class)->get($postId, 'response') |
|
74 | + ? __('Yes', 'site-reviews') |
|
75 | + : __('No', 'site-reviews'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param int $postId |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function buildColumnReviewer($postId) |
|
83 | - { |
|
84 | - return strval(glsr(Database::class)->get($postId, 'author')); |
|
85 | - } |
|
78 | + /** |
|
79 | + * @param int $postId |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function buildColumnReviewer($postId) |
|
83 | + { |
|
84 | + return strval(glsr(Database::class)->get($postId, 'author')); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param int $postId |
|
89 | - * @param int|null $rating |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function buildColumnRating($postId) |
|
93 | - { |
|
94 | - return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
95 | - } |
|
87 | + /** |
|
88 | + * @param int $postId |
|
89 | + * @param int|null $rating |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function buildColumnRating($postId) |
|
93 | + { |
|
94 | + return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @param int $postId |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - public function buildColumnReviewType($postId) |
|
102 | - { |
|
103 | - $type = glsr(Database::class)->get($postId, 'review_type'); |
|
104 | - return array_key_exists($type, glsr()->reviewTypes) |
|
105 | - ? glsr()->reviewTypes[$type] |
|
106 | - : __('Unsupported Type', 'site-reviews'); |
|
107 | - } |
|
97 | + /** |
|
98 | + * @param int $postId |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + public function buildColumnReviewType($postId) |
|
102 | + { |
|
103 | + $type = glsr(Database::class)->get($postId, 'review_type'); |
|
104 | + return array_key_exists($type, glsr()->reviewTypes) |
|
105 | + ? glsr()->reviewTypes[$type] |
|
106 | + : __('Unsupported Type', 'site-reviews'); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param string $postType |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - public function renderFilters($postType) |
|
114 | - { |
|
115 | - if (Application::POST_TYPE !== $postType) { |
|
116 | - return; |
|
117 | - } |
|
118 | - if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
119 | - $status = 'publish'; |
|
120 | - } |
|
121 | - $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
122 | - $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
123 | - $this->renderFilterRatings($ratings); |
|
124 | - $this->renderFilterTypes($types); |
|
125 | - } |
|
109 | + /** |
|
110 | + * @param string $postType |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + public function renderFilters($postType) |
|
114 | + { |
|
115 | + if (Application::POST_TYPE !== $postType) { |
|
116 | + return; |
|
117 | + } |
|
118 | + if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
119 | + $status = 'publish'; |
|
120 | + } |
|
121 | + $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
122 | + $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
123 | + $this->renderFilterRatings($ratings); |
|
124 | + $this->renderFilterTypes($types); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @param string $column |
|
129 | - * @param int $postId |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - public function renderValues($column, $postId) |
|
133 | - { |
|
134 | - $method = Helper::buildMethodName($column, 'buildColumn'); |
|
135 | - $value = method_exists($this, $method) |
|
136 | - ? call_user_func([$this, $method], $postId) |
|
137 | - : ''; |
|
138 | - $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
139 | - if (0 !== $value && empty($value)) { |
|
140 | - $value = '—'; |
|
141 | - } |
|
142 | - echo $value; |
|
143 | - } |
|
127 | + /** |
|
128 | + * @param string $column |
|
129 | + * @param int $postId |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + public function renderValues($column, $postId) |
|
133 | + { |
|
134 | + $method = Helper::buildMethodName($column, 'buildColumn'); |
|
135 | + $value = method_exists($this, $method) |
|
136 | + ? call_user_func([$this, $method], $postId) |
|
137 | + : ''; |
|
138 | + $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
139 | + if (0 !== $value && empty($value)) { |
|
140 | + $value = '—'; |
|
141 | + } |
|
142 | + echo $value; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @param array $ratings |
|
147 | - * @return void |
|
148 | - */ |
|
149 | - protected function renderFilterRatings($ratings) |
|
150 | - { |
|
151 | - if (empty($ratings)) { |
|
152 | - return; |
|
153 | - } |
|
154 | - $ratings = array_flip(array_reverse($ratings)); |
|
155 | - array_walk($ratings, function (&$value, $key) { |
|
156 | - $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
157 | - $value = sprintf($label, $key); |
|
158 | - }); |
|
159 | - echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
160 | - 'class' => 'screen-reader-text', |
|
161 | - 'for' => 'rating', |
|
162 | - ]); |
|
163 | - echo glsr(Builder::class)->select([ |
|
164 | - 'name' => 'rating', |
|
165 | - 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
166 | - 'value' => filter_input(INPUT_GET, 'rating'), |
|
167 | - ]); |
|
168 | - } |
|
145 | + /** |
|
146 | + * @param array $ratings |
|
147 | + * @return void |
|
148 | + */ |
|
149 | + protected function renderFilterRatings($ratings) |
|
150 | + { |
|
151 | + if (empty($ratings)) { |
|
152 | + return; |
|
153 | + } |
|
154 | + $ratings = array_flip(array_reverse($ratings)); |
|
155 | + array_walk($ratings, function (&$value, $key) { |
|
156 | + $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
157 | + $value = sprintf($label, $key); |
|
158 | + }); |
|
159 | + echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
160 | + 'class' => 'screen-reader-text', |
|
161 | + 'for' => 'rating', |
|
162 | + ]); |
|
163 | + echo glsr(Builder::class)->select([ |
|
164 | + 'name' => 'rating', |
|
165 | + 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
166 | + 'value' => filter_input(INPUT_GET, 'rating'), |
|
167 | + ]); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * @param array $types |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - protected function renderFilterTypes($types) |
|
175 | - { |
|
176 | - if (count(glsr()->reviewTypes) < 2) { |
|
177 | - return; |
|
178 | - } |
|
179 | - echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
180 | - 'class' => 'screen-reader-text', |
|
181 | - 'for' => 'review_type', |
|
182 | - ]); |
|
183 | - echo glsr(Builder::class)->select([ |
|
184 | - 'name' => 'review_type', |
|
185 | - 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
186 | - 'value' => filter_input(INPUT_GET, 'review_type'), |
|
187 | - ]); |
|
188 | - } |
|
170 | + /** |
|
171 | + * @param array $types |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + protected function renderFilterTypes($types) |
|
175 | + { |
|
176 | + if (count(glsr()->reviewTypes) < 2) { |
|
177 | + return; |
|
178 | + } |
|
179 | + echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
180 | + 'class' => 'screen-reader-text', |
|
181 | + 'for' => 'review_type', |
|
182 | + ]); |
|
183 | + echo glsr(Builder::class)->select([ |
|
184 | + 'name' => 'review_type', |
|
185 | + 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
186 | + 'value' => filter_input(INPUT_GET, 'review_type'), |
|
187 | + ]); |
|
188 | + } |
|
189 | 189 | } |
@@ -20,402 +20,402 @@ |
||
20 | 20 | |
21 | 21 | class EditorController extends Controller |
22 | 22 | { |
23 | - /** |
|
24 | - * @param array $settings |
|
25 | - * @return array |
|
26 | - * @filter wp_editor_settings |
|
27 | - */ |
|
28 | - public function filterEditorSettings($settings) |
|
29 | - { |
|
30 | - return glsr(Customization::class)->filterEditorSettings( |
|
31 | - Arr::consolidateArray($settings) |
|
32 | - ); |
|
33 | - } |
|
23 | + /** |
|
24 | + * @param array $settings |
|
25 | + * @return array |
|
26 | + * @filter wp_editor_settings |
|
27 | + */ |
|
28 | + public function filterEditorSettings($settings) |
|
29 | + { |
|
30 | + return glsr(Customization::class)->filterEditorSettings( |
|
31 | + Arr::consolidateArray($settings) |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script. |
|
37 | - * @param string $html |
|
38 | - * @return string |
|
39 | - * @filter the_editor |
|
40 | - */ |
|
41 | - public function filterEditorTextarea($html) |
|
42 | - { |
|
43 | - return glsr(Customization::class)->filterEditorTextarea($html); |
|
44 | - } |
|
35 | + /** |
|
36 | + * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script. |
|
37 | + * @param string $html |
|
38 | + * @return string |
|
39 | + * @filter the_editor |
|
40 | + */ |
|
41 | + public function filterEditorTextarea($html) |
|
42 | + { |
|
43 | + return glsr(Customization::class)->filterEditorTextarea($html); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param bool $protected |
|
48 | - * @param string $metaKey |
|
49 | - * @param string $metaType |
|
50 | - * @return bool |
|
51 | - * @filter is_protected_meta |
|
52 | - */ |
|
53 | - public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
54 | - { |
|
55 | - if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
56 | - $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
57 | - $values = Arr::prefixArrayKeys($values); |
|
58 | - if (array_key_exists($metaKey, $values)) { |
|
59 | - $protected = false; |
|
60 | - } |
|
61 | - } |
|
62 | - return $protected; |
|
63 | - } |
|
46 | + /** |
|
47 | + * @param bool $protected |
|
48 | + * @param string $metaKey |
|
49 | + * @param string $metaType |
|
50 | + * @return bool |
|
51 | + * @filter is_protected_meta |
|
52 | + */ |
|
53 | + public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
54 | + { |
|
55 | + if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
56 | + $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
57 | + $values = Arr::prefixArrayKeys($values); |
|
58 | + if (array_key_exists($metaKey, $values)) { |
|
59 | + $protected = false; |
|
60 | + } |
|
61 | + } |
|
62 | + return $protected; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param array $messages |
|
67 | - * @return array |
|
68 | - * @filter post_updated_messages |
|
69 | - */ |
|
70 | - public function filterUpdateMessages($messages) |
|
71 | - { |
|
72 | - return glsr(Labels::class)->filterUpdateMessages( |
|
73 | - Arr::consolidateArray($messages) |
|
74 | - ); |
|
75 | - } |
|
65 | + /** |
|
66 | + * @param array $messages |
|
67 | + * @return array |
|
68 | + * @filter post_updated_messages |
|
69 | + */ |
|
70 | + public function filterUpdateMessages($messages) |
|
71 | + { |
|
72 | + return glsr(Labels::class)->filterUpdateMessages( |
|
73 | + Arr::consolidateArray($messages) |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return void |
|
79 | - * @action add_meta_boxes_{Application::POST_TYPE} |
|
80 | - */ |
|
81 | - public function registerMetaBoxes($post) |
|
82 | - { |
|
83 | - add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
84 | - add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
85 | - if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
86 | - return; |
|
87 | - } |
|
88 | - add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
89 | - } |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + * @action add_meta_boxes_{Application::POST_TYPE} |
|
80 | + */ |
|
81 | + public function registerMetaBoxes($post) |
|
82 | + { |
|
83 | + add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
84 | + add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
85 | + if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
86 | + return; |
|
87 | + } |
|
88 | + add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - * @action admin_print_scripts |
|
94 | - */ |
|
95 | - public function removeAutosave() |
|
96 | - { |
|
97 | - glsr(Customization::class)->removeAutosave(); |
|
98 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + * @action admin_print_scripts |
|
94 | + */ |
|
95 | + public function removeAutosave() |
|
96 | + { |
|
97 | + glsr(Customization::class)->removeAutosave(); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return void |
|
102 | - * @action admin_menu |
|
103 | - */ |
|
104 | - public function removeMetaBoxes() |
|
105 | - { |
|
106 | - glsr(Customization::class)->removeMetaBoxes(); |
|
107 | - } |
|
100 | + /** |
|
101 | + * @return void |
|
102 | + * @action admin_menu |
|
103 | + */ |
|
104 | + public function removeMetaBoxes() |
|
105 | + { |
|
106 | + glsr(Customization::class)->removeMetaBoxes(); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - public function removePostTypeSupport() |
|
113 | - { |
|
114 | - glsr(Customization::class)->removePostTypeSupport(); |
|
115 | - } |
|
109 | + /** |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + public function removePostTypeSupport() |
|
113 | + { |
|
114 | + glsr(Customization::class)->removePostTypeSupport(); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @param WP_Post $post |
|
119 | - * @return void |
|
120 | - * @callback add_meta_box |
|
121 | - */ |
|
122 | - public function renderAssignedToMetabox($post) |
|
123 | - { |
|
124 | - if (!$this->isReviewPostType($post)) { |
|
125 | - return; |
|
126 | - } |
|
127 | - $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
128 | - wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
129 | - glsr()->render('partials/editor/metabox-assigned-to', [ |
|
130 | - 'id' => $assignedTo, |
|
131 | - 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
132 | - ]); |
|
133 | - } |
|
117 | + /** |
|
118 | + * @param WP_Post $post |
|
119 | + * @return void |
|
120 | + * @callback add_meta_box |
|
121 | + */ |
|
122 | + public function renderAssignedToMetabox($post) |
|
123 | + { |
|
124 | + if (!$this->isReviewPostType($post)) { |
|
125 | + return; |
|
126 | + } |
|
127 | + $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
128 | + wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
129 | + glsr()->render('partials/editor/metabox-assigned-to', [ |
|
130 | + 'id' => $assignedTo, |
|
131 | + 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
132 | + ]); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param WP_Post $post |
|
137 | - * @return void |
|
138 | - * @callback add_meta_box |
|
139 | - */ |
|
140 | - public function renderDetailsMetaBox($post) |
|
141 | - { |
|
142 | - if (!$this->isReviewPostType($post)) { |
|
143 | - return; |
|
144 | - } |
|
145 | - $review = glsr_get_review($post); |
|
146 | - glsr()->render('partials/editor/metabox-details', [ |
|
147 | - 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
148 | - 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
149 | - ]); |
|
150 | - } |
|
135 | + /** |
|
136 | + * @param WP_Post $post |
|
137 | + * @return void |
|
138 | + * @callback add_meta_box |
|
139 | + */ |
|
140 | + public function renderDetailsMetaBox($post) |
|
141 | + { |
|
142 | + if (!$this->isReviewPostType($post)) { |
|
143 | + return; |
|
144 | + } |
|
145 | + $review = glsr_get_review($post); |
|
146 | + glsr()->render('partials/editor/metabox-details', [ |
|
147 | + 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
148 | + 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
149 | + ]); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @return void |
|
154 | - * @action post_submitbox_misc_actions |
|
155 | - */ |
|
156 | - public function renderPinnedInPublishMetaBox() |
|
157 | - { |
|
158 | - if (!$this->isReviewPostType(get_post()) |
|
159 | - || !glsr()->can('edit_others_posts')) { |
|
160 | - return; |
|
161 | - } |
|
162 | - glsr(Template::class)->render('partials/editor/pinned', [ |
|
163 | - 'context' => [ |
|
164 | - 'no' => __('No', 'site-reviews'), |
|
165 | - 'yes' => __('Yes', 'site-reviews'), |
|
166 | - ], |
|
167 | - 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
168 | - ]); |
|
169 | - } |
|
152 | + /** |
|
153 | + * @return void |
|
154 | + * @action post_submitbox_misc_actions |
|
155 | + */ |
|
156 | + public function renderPinnedInPublishMetaBox() |
|
157 | + { |
|
158 | + if (!$this->isReviewPostType(get_post()) |
|
159 | + || !glsr()->can('edit_others_posts')) { |
|
160 | + return; |
|
161 | + } |
|
162 | + glsr(Template::class)->render('partials/editor/pinned', [ |
|
163 | + 'context' => [ |
|
164 | + 'no' => __('No', 'site-reviews'), |
|
165 | + 'yes' => __('Yes', 'site-reviews'), |
|
166 | + ], |
|
167 | + 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
168 | + ]); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @param WP_Post $post |
|
173 | - * @return void |
|
174 | - * @callback add_meta_box |
|
175 | - */ |
|
176 | - public function renderResponseMetaBox($post) |
|
177 | - { |
|
178 | - if (!$this->isReviewPostType($post)) { |
|
179 | - return; |
|
180 | - } |
|
181 | - wp_nonce_field('response', '_nonce-response', false); |
|
182 | - glsr()->render('partials/editor/metabox-response', [ |
|
183 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
184 | - ]); |
|
185 | - } |
|
171 | + /** |
|
172 | + * @param WP_Post $post |
|
173 | + * @return void |
|
174 | + * @callback add_meta_box |
|
175 | + */ |
|
176 | + public function renderResponseMetaBox($post) |
|
177 | + { |
|
178 | + if (!$this->isReviewPostType($post)) { |
|
179 | + return; |
|
180 | + } |
|
181 | + wp_nonce_field('response', '_nonce-response', false); |
|
182 | + glsr()->render('partials/editor/metabox-response', [ |
|
183 | + 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
184 | + ]); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * @param WP_Post $post |
|
189 | - * @return void |
|
190 | - * @action edit_form_after_title |
|
191 | - */ |
|
192 | - public function renderReviewEditor($post) |
|
193 | - { |
|
194 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
195 | - return; |
|
196 | - } |
|
197 | - glsr()->render('partials/editor/review', [ |
|
198 | - 'post' => $post, |
|
199 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
200 | - ]); |
|
201 | - } |
|
187 | + /** |
|
188 | + * @param WP_Post $post |
|
189 | + * @return void |
|
190 | + * @action edit_form_after_title |
|
191 | + */ |
|
192 | + public function renderReviewEditor($post) |
|
193 | + { |
|
194 | + if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
195 | + return; |
|
196 | + } |
|
197 | + glsr()->render('partials/editor/review', [ |
|
198 | + 'post' => $post, |
|
199 | + 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
200 | + ]); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @return void |
|
205 | - * @action admin_head |
|
206 | - */ |
|
207 | - public function renderReviewFields() |
|
208 | - { |
|
209 | - $screen = glsr_current_screen(); |
|
210 | - if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
211 | - return; |
|
212 | - } |
|
213 | - add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
214 | - add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
215 | - } |
|
203 | + /** |
|
204 | + * @return void |
|
205 | + * @action admin_head |
|
206 | + */ |
|
207 | + public function renderReviewFields() |
|
208 | + { |
|
209 | + $screen = glsr_current_screen(); |
|
210 | + if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
211 | + return; |
|
212 | + } |
|
213 | + add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
214 | + add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @param WP_Post $post |
|
219 | - * @return void |
|
220 | - * @action edit_form_top |
|
221 | - */ |
|
222 | - public function renderReviewNotice($post) |
|
223 | - { |
|
224 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
225 | - return; |
|
226 | - } |
|
227 | - glsr(Notice::class)->addWarning(sprintf( |
|
228 | - __('%s reviews are read-only.', 'site-reviews'), |
|
229 | - glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
230 | - )); |
|
231 | - glsr(Template::class)->render('partials/editor/notice', [ |
|
232 | - 'context' => [ |
|
233 | - 'notices' => glsr(Notice::class)->get(), |
|
234 | - ], |
|
235 | - ]); |
|
236 | - } |
|
217 | + /** |
|
218 | + * @param WP_Post $post |
|
219 | + * @return void |
|
220 | + * @action edit_form_top |
|
221 | + */ |
|
222 | + public function renderReviewNotice($post) |
|
223 | + { |
|
224 | + if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
225 | + return; |
|
226 | + } |
|
227 | + glsr(Notice::class)->addWarning(sprintf( |
|
228 | + __('%s reviews are read-only.', 'site-reviews'), |
|
229 | + glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
230 | + )); |
|
231 | + glsr(Template::class)->render('partials/editor/notice', [ |
|
232 | + 'context' => [ |
|
233 | + 'notices' => glsr(Notice::class)->get(), |
|
234 | + ], |
|
235 | + ]); |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * @param WP_Post $post |
|
240 | - * @return void |
|
241 | - * @see glsr_categories_meta_box() |
|
242 | - * @callback register_taxonomy |
|
243 | - */ |
|
244 | - public function renderTaxonomyMetabox($post) |
|
245 | - { |
|
246 | - if (!$this->isReviewPostType($post)) { |
|
247 | - return; |
|
248 | - } |
|
249 | - glsr()->render('partials/editor/metabox-categories', [ |
|
250 | - 'post' => $post, |
|
251 | - 'tax_name' => Application::TAXONOMY, |
|
252 | - 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
253 | - ]); |
|
254 | - } |
|
238 | + /** |
|
239 | + * @param WP_Post $post |
|
240 | + * @return void |
|
241 | + * @see glsr_categories_meta_box() |
|
242 | + * @callback register_taxonomy |
|
243 | + */ |
|
244 | + public function renderTaxonomyMetabox($post) |
|
245 | + { |
|
246 | + if (!$this->isReviewPostType($post)) { |
|
247 | + return; |
|
248 | + } |
|
249 | + glsr()->render('partials/editor/metabox-categories', [ |
|
250 | + 'post' => $post, |
|
251 | + 'tax_name' => Application::TAXONOMY, |
|
252 | + 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
253 | + ]); |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * @return void |
|
258 | - * @see $this->filterUpdateMessages() |
|
259 | - * @action admin_action_revert |
|
260 | - */ |
|
261 | - public function revertReview() |
|
262 | - { |
|
263 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
264 | - return; |
|
265 | - } |
|
266 | - check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
267 | - glsr(ReviewManager::class)->revert($postId); |
|
268 | - $this->redirect($postId, 52); |
|
269 | - } |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + * @see $this->filterUpdateMessages() |
|
259 | + * @action admin_action_revert |
|
260 | + */ |
|
261 | + public function revertReview() |
|
262 | + { |
|
263 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
264 | + return; |
|
265 | + } |
|
266 | + check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
267 | + glsr(ReviewManager::class)->revert($postId); |
|
268 | + $this->redirect($postId, 52); |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * @param int $postId |
|
273 | - * @param \WP_Post $post |
|
274 | - * @param bool $isUpdate |
|
275 | - * @return void |
|
276 | - * @action save_post_.Application::POST_TYPE |
|
277 | - */ |
|
278 | - public function saveMetaboxes($postId, $post, $isUpdating) |
|
279 | - { |
|
280 | - glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
281 | - glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
282 | - if ($isUpdating) { |
|
283 | - do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
284 | - } |
|
285 | - } |
|
271 | + /** |
|
272 | + * @param int $postId |
|
273 | + * @param \WP_Post $post |
|
274 | + * @param bool $isUpdate |
|
275 | + * @return void |
|
276 | + * @action save_post_.Application::POST_TYPE |
|
277 | + */ |
|
278 | + public function saveMetaboxes($postId, $post, $isUpdating) |
|
279 | + { |
|
280 | + glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
281 | + glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
282 | + if ($isUpdating) { |
|
283 | + do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
284 | + } |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * @param string $assignedTo |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
292 | - { |
|
293 | - $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
294 | - if (!($assignedPost instanceof WP_Post)) { |
|
295 | - return; |
|
296 | - } |
|
297 | - return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
298 | - 'context' => [ |
|
299 | - 'data.url' => (string) get_permalink($assignedPost), |
|
300 | - 'data.title' => get_the_title($assignedPost), |
|
301 | - ], |
|
302 | - ]); |
|
303 | - } |
|
287 | + /** |
|
288 | + * @param string $assignedTo |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
292 | + { |
|
293 | + $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
294 | + if (!($assignedPost instanceof WP_Post)) { |
|
295 | + return; |
|
296 | + } |
|
297 | + return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
298 | + 'context' => [ |
|
299 | + 'data.url' => (string) get_permalink($assignedPost), |
|
300 | + 'data.title' => get_the_title($assignedPost), |
|
301 | + ], |
|
302 | + ]); |
|
303 | + } |
|
304 | 304 | |
305 | - /** |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
309 | - { |
|
310 | - $isModified = !Arr::compareArrays( |
|
311 | - [$review->title, $review->content, $review->date], |
|
312 | - [ |
|
313 | - glsr(Database::class)->get($post->ID, 'title'), |
|
314 | - glsr(Database::class)->get($post->ID, 'content'), |
|
315 | - glsr(Database::class)->get($post->ID, 'date'), |
|
316 | - ] |
|
317 | - ); |
|
318 | - if ($isModified) { |
|
319 | - $revertUrl = wp_nonce_url( |
|
320 | - admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
321 | - 'revert-review_'.$post->ID |
|
322 | - ); |
|
323 | - return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
324 | - 'class' => 'button button-large', |
|
325 | - 'href' => $revertUrl, |
|
326 | - 'id' => 'revert', |
|
327 | - ]); |
|
328 | - } |
|
329 | - return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
330 | - 'class' => 'button-large', |
|
331 | - 'disabled' => true, |
|
332 | - 'id' => 'revert', |
|
333 | - ]); |
|
334 | - } |
|
305 | + /** |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
309 | + { |
|
310 | + $isModified = !Arr::compareArrays( |
|
311 | + [$review->title, $review->content, $review->date], |
|
312 | + [ |
|
313 | + glsr(Database::class)->get($post->ID, 'title'), |
|
314 | + glsr(Database::class)->get($post->ID, 'content'), |
|
315 | + glsr(Database::class)->get($post->ID, 'date'), |
|
316 | + ] |
|
317 | + ); |
|
318 | + if ($isModified) { |
|
319 | + $revertUrl = wp_nonce_url( |
|
320 | + admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
321 | + 'revert-review_'.$post->ID |
|
322 | + ); |
|
323 | + return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
324 | + 'class' => 'button button-large', |
|
325 | + 'href' => $revertUrl, |
|
326 | + 'id' => 'revert', |
|
327 | + ]); |
|
328 | + } |
|
329 | + return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
330 | + 'class' => 'button-large', |
|
331 | + 'disabled' => true, |
|
332 | + 'id' => 'revert', |
|
333 | + ]); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * @param object $review |
|
338 | - * @return string|void |
|
339 | - */ |
|
340 | - protected function getReviewType($review) |
|
341 | - { |
|
342 | - if (count(glsr()->reviewTypes) < 2) { |
|
343 | - return; |
|
344 | - } |
|
345 | - $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
346 | - ? glsr()->reviewTypes[$review->review_type] |
|
347 | - : __('Unknown', 'site-reviews'); |
|
348 | - if (!empty($review->url)) { |
|
349 | - $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
350 | - 'href' => $review->url, |
|
351 | - 'target' => '_blank', |
|
352 | - ]); |
|
353 | - } |
|
354 | - return $reviewType; |
|
355 | - } |
|
336 | + /** |
|
337 | + * @param object $review |
|
338 | + * @return string|void |
|
339 | + */ |
|
340 | + protected function getReviewType($review) |
|
341 | + { |
|
342 | + if (count(glsr()->reviewTypes) < 2) { |
|
343 | + return; |
|
344 | + } |
|
345 | + $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
346 | + ? glsr()->reviewTypes[$review->review_type] |
|
347 | + : __('Unknown', 'site-reviews'); |
|
348 | + if (!empty($review->url)) { |
|
349 | + $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
350 | + 'href' => $review->url, |
|
351 | + 'target' => '_blank', |
|
352 | + ]); |
|
353 | + } |
|
354 | + return $reviewType; |
|
355 | + } |
|
356 | 356 | |
357 | - /** |
|
358 | - * @return bool |
|
359 | - */ |
|
360 | - protected function isReviewEditable($post) |
|
361 | - { |
|
362 | - return $this->isReviewPostType($post) |
|
363 | - && post_type_supports(Application::POST_TYPE, 'title') |
|
364 | - && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
365 | - } |
|
357 | + /** |
|
358 | + * @return bool |
|
359 | + */ |
|
360 | + protected function isReviewEditable($post) |
|
361 | + { |
|
362 | + return $this->isReviewPostType($post) |
|
363 | + && post_type_supports(Application::POST_TYPE, 'title') |
|
364 | + && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
365 | + } |
|
366 | 366 | |
367 | - /** |
|
368 | - * @param mixed $post |
|
369 | - * @return bool |
|
370 | - */ |
|
371 | - protected function isReviewPostType($post) |
|
372 | - { |
|
373 | - return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
|
374 | - } |
|
367 | + /** |
|
368 | + * @param mixed $post |
|
369 | + * @return bool |
|
370 | + */ |
|
371 | + protected function isReviewPostType($post) |
|
372 | + { |
|
373 | + return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
|
374 | + } |
|
375 | 375 | |
376 | - /** |
|
377 | - * @return array |
|
378 | - */ |
|
379 | - protected function normalizeDetailsMetaBox(Review $review) |
|
380 | - { |
|
381 | - $user = empty($review->user_id) |
|
382 | - ? __('Unregistered user', 'site-reviews') |
|
383 | - : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
384 | - 'href' => get_author_posts_url($review->user_id), |
|
385 | - ]); |
|
386 | - $email = empty($review->email) |
|
387 | - ? '—' |
|
388 | - : glsr(Builder::class)->a($review->email, [ |
|
389 | - 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
390 | - ]); |
|
391 | - $metabox = [ |
|
392 | - __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
393 | - __('Type', 'site-reviews') => $this->getReviewType($review), |
|
394 | - __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
395 | - __('Name', 'site-reviews') => $review->author, |
|
396 | - __('Email', 'site-reviews') => $email, |
|
397 | - __('User', 'site-reviews') => $user, |
|
398 | - __('IP Address', 'site-reviews') => $review->ip_address, |
|
399 | - __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
400 | - ]; |
|
401 | - return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
402 | - } |
|
376 | + /** |
|
377 | + * @return array |
|
378 | + */ |
|
379 | + protected function normalizeDetailsMetaBox(Review $review) |
|
380 | + { |
|
381 | + $user = empty($review->user_id) |
|
382 | + ? __('Unregistered user', 'site-reviews') |
|
383 | + : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
384 | + 'href' => get_author_posts_url($review->user_id), |
|
385 | + ]); |
|
386 | + $email = empty($review->email) |
|
387 | + ? '—' |
|
388 | + : glsr(Builder::class)->a($review->email, [ |
|
389 | + 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
390 | + ]); |
|
391 | + $metabox = [ |
|
392 | + __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
393 | + __('Type', 'site-reviews') => $this->getReviewType($review), |
|
394 | + __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
395 | + __('Name', 'site-reviews') => $review->author, |
|
396 | + __('Email', 'site-reviews') => $email, |
|
397 | + __('User', 'site-reviews') => $user, |
|
398 | + __('IP Address', 'site-reviews') => $review->ip_address, |
|
399 | + __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
400 | + ]; |
|
401 | + return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
402 | + } |
|
403 | 403 | |
404 | - /** |
|
405 | - * @param int $postId |
|
406 | - * @param int $messageIndex |
|
407 | - * @return void |
|
408 | - */ |
|
409 | - protected function redirect($postId, $messageIndex) |
|
410 | - { |
|
411 | - $referer = wp_get_referer(); |
|
412 | - $hasReferer = !$referer |
|
413 | - || Str::contains($referer, 'post.php') |
|
414 | - || Str::contains($referer, 'post-new.php'); |
|
415 | - $redirectUri = $hasReferer |
|
416 | - ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
417 | - : get_edit_post_link($postId); |
|
418 | - wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
419 | - exit; |
|
420 | - } |
|
404 | + /** |
|
405 | + * @param int $postId |
|
406 | + * @param int $messageIndex |
|
407 | + * @return void |
|
408 | + */ |
|
409 | + protected function redirect($postId, $messageIndex) |
|
410 | + { |
|
411 | + $referer = wp_get_referer(); |
|
412 | + $hasReferer = !$referer |
|
413 | + || Str::contains($referer, 'post.php') |
|
414 | + || Str::contains($referer, 'post-new.php'); |
|
415 | + $redirectUri = $hasReferer |
|
416 | + ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
417 | + : get_edit_post_link($postId); |
|
418 | + wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
419 | + exit; |
|
420 | + } |
|
421 | 421 | } |
@@ -14,268 +14,268 @@ |
||
14 | 14 | |
15 | 15 | class ListTableController extends Controller |
16 | 16 | { |
17 | - /** |
|
18 | - * @return void |
|
19 | - * @action admin_action_approve |
|
20 | - */ |
|
21 | - public function approve() |
|
22 | - { |
|
23 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
24 | - return; |
|
25 | - } |
|
26 | - check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
27 | - wp_update_post([ |
|
28 | - 'ID' => $postId, |
|
29 | - 'post_status' => 'publish', |
|
30 | - ]); |
|
31 | - wp_safe_redirect(wp_get_referer()); |
|
32 | - exit; |
|
33 | - } |
|
17 | + /** |
|
18 | + * @return void |
|
19 | + * @action admin_action_approve |
|
20 | + */ |
|
21 | + public function approve() |
|
22 | + { |
|
23 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
24 | + return; |
|
25 | + } |
|
26 | + check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
27 | + wp_update_post([ |
|
28 | + 'ID' => $postId, |
|
29 | + 'post_status' => 'publish', |
|
30 | + ]); |
|
31 | + wp_safe_redirect(wp_get_referer()); |
|
32 | + exit; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param array $columns |
|
37 | - * @return array |
|
38 | - * @filter manage_.Application::POST_TYPE._posts_columns |
|
39 | - */ |
|
40 | - public function filterColumnsForPostType($columns) |
|
41 | - { |
|
42 | - $columns = Arr::consolidateArray($columns); |
|
43 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
44 | - foreach ($postTypeColumns as $key => &$value) { |
|
45 | - if (!array_key_exists($key, $columns) || !empty($value)) { |
|
46 | - continue; |
|
47 | - } |
|
48 | - $value = $columns[$key]; |
|
49 | - } |
|
50 | - if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
51 | - unset($postTypeColumns['review_type']); |
|
52 | - } |
|
53 | - return array_filter($postTypeColumns, 'strlen'); |
|
54 | - } |
|
35 | + /** |
|
36 | + * @param array $columns |
|
37 | + * @return array |
|
38 | + * @filter manage_.Application::POST_TYPE._posts_columns |
|
39 | + */ |
|
40 | + public function filterColumnsForPostType($columns) |
|
41 | + { |
|
42 | + $columns = Arr::consolidateArray($columns); |
|
43 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
44 | + foreach ($postTypeColumns as $key => &$value) { |
|
45 | + if (!array_key_exists($key, $columns) || !empty($value)) { |
|
46 | + continue; |
|
47 | + } |
|
48 | + $value = $columns[$key]; |
|
49 | + } |
|
50 | + if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
51 | + unset($postTypeColumns['review_type']); |
|
52 | + } |
|
53 | + return array_filter($postTypeColumns, 'strlen'); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param string $status |
|
58 | - * @param WP_Post $post |
|
59 | - * @return string |
|
60 | - * @filter post_date_column_status |
|
61 | - */ |
|
62 | - public function filterDateColumnStatus($status, $post) |
|
63 | - { |
|
64 | - if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
65 | - $status = __('Submitted', 'site-reviews'); |
|
66 | - } |
|
67 | - return $status; |
|
68 | - } |
|
56 | + /** |
|
57 | + * @param string $status |
|
58 | + * @param WP_Post $post |
|
59 | + * @return string |
|
60 | + * @filter post_date_column_status |
|
61 | + */ |
|
62 | + public function filterDateColumnStatus($status, $post) |
|
63 | + { |
|
64 | + if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
65 | + $status = __('Submitted', 'site-reviews'); |
|
66 | + } |
|
67 | + return $status; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @param array $hidden |
|
72 | - * @param WP_Screen $post |
|
73 | - * @return array |
|
74 | - * @filter default_hidden_columns |
|
75 | - */ |
|
76 | - public function filterDefaultHiddenColumns($hidden, $screen) |
|
77 | - { |
|
78 | - if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
79 | - $hidden = Arr::consolidateArray($hidden); |
|
80 | - $hidden = array_unique(array_merge($hidden, [ |
|
81 | - 'email', 'ip_address', 'response', 'reviewer', |
|
82 | - ])); |
|
83 | - } |
|
84 | - return $hidden; |
|
85 | - } |
|
70 | + /** |
|
71 | + * @param array $hidden |
|
72 | + * @param WP_Screen $post |
|
73 | + * @return array |
|
74 | + * @filter default_hidden_columns |
|
75 | + */ |
|
76 | + public function filterDefaultHiddenColumns($hidden, $screen) |
|
77 | + { |
|
78 | + if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
79 | + $hidden = Arr::consolidateArray($hidden); |
|
80 | + $hidden = array_unique(array_merge($hidden, [ |
|
81 | + 'email', 'ip_address', 'response', 'reviewer', |
|
82 | + ])); |
|
83 | + } |
|
84 | + return $hidden; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param array $actions |
|
89 | - * @param WP_Post $post |
|
90 | - * @return array |
|
91 | - * @filter post_row_actions |
|
92 | - */ |
|
93 | - public function filterRowActions($actions, $post) |
|
94 | - { |
|
95 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
96 | - || 'trash' == $post->post_status |
|
97 | - || !user_can(get_current_user_id(), 'edit_post', $post->ID)) { |
|
98 | - return $actions; |
|
99 | - } |
|
100 | - unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
101 | - $rowActions = [ |
|
102 | - 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
103 | - 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
104 | - ]; |
|
105 | - $newActions = []; |
|
106 | - foreach ($rowActions as $key => $text) { |
|
107 | - $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
108 | - 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
109 | - 'class' => 'glsr-change-status', |
|
110 | - 'href' => wp_nonce_url( |
|
111 | - admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
112 | - $key.'-review_'.$post->ID |
|
113 | - ), |
|
114 | - ]); |
|
115 | - } |
|
116 | - return $newActions + Arr::consolidateArray($actions); |
|
117 | - } |
|
87 | + /** |
|
88 | + * @param array $actions |
|
89 | + * @param WP_Post $post |
|
90 | + * @return array |
|
91 | + * @filter post_row_actions |
|
92 | + */ |
|
93 | + public function filterRowActions($actions, $post) |
|
94 | + { |
|
95 | + if (Application::POST_TYPE != Arr::get($post, 'post_type') |
|
96 | + || 'trash' == $post->post_status |
|
97 | + || !user_can(get_current_user_id(), 'edit_post', $post->ID)) { |
|
98 | + return $actions; |
|
99 | + } |
|
100 | + unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
101 | + $rowActions = [ |
|
102 | + 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
103 | + 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
104 | + ]; |
|
105 | + $newActions = []; |
|
106 | + foreach ($rowActions as $key => $text) { |
|
107 | + $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
108 | + 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
109 | + 'class' => 'glsr-change-status', |
|
110 | + 'href' => wp_nonce_url( |
|
111 | + admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
112 | + $key.'-review_'.$post->ID |
|
113 | + ), |
|
114 | + ]); |
|
115 | + } |
|
116 | + return $newActions + Arr::consolidateArray($actions); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * @param array $columns |
|
121 | - * @return array |
|
122 | - * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
123 | - */ |
|
124 | - public function filterSortableColumns($columns) |
|
125 | - { |
|
126 | - $columns = Arr::consolidateArray($columns); |
|
127 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
128 | - unset($postTypeColumns['cb']); |
|
129 | - foreach ($postTypeColumns as $key => $value) { |
|
130 | - if (Str::startsWith('taxonomy', $key)) { |
|
131 | - continue; |
|
132 | - } |
|
133 | - $columns[$key] = $key; |
|
134 | - } |
|
135 | - return $columns; |
|
136 | - } |
|
119 | + /** |
|
120 | + * @param array $columns |
|
121 | + * @return array |
|
122 | + * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
123 | + */ |
|
124 | + public function filterSortableColumns($columns) |
|
125 | + { |
|
126 | + $columns = Arr::consolidateArray($columns); |
|
127 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
128 | + unset($postTypeColumns['cb']); |
|
129 | + foreach ($postTypeColumns as $key => $value) { |
|
130 | + if (Str::startsWith('taxonomy', $key)) { |
|
131 | + continue; |
|
132 | + } |
|
133 | + $columns[$key] = $key; |
|
134 | + } |
|
135 | + return $columns; |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * @param string $columnName |
|
140 | - * @param string $postType |
|
141 | - * @return void |
|
142 | - * @action bulk_edit_custom_box |
|
143 | - */ |
|
144 | - public function renderBulkEditFields($columnName, $postType) |
|
145 | - { |
|
146 | - if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
147 | - glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
148 | - } |
|
149 | - } |
|
138 | + /** |
|
139 | + * @param string $columnName |
|
140 | + * @param string $postType |
|
141 | + * @return void |
|
142 | + * @action bulk_edit_custom_box |
|
143 | + */ |
|
144 | + public function renderBulkEditFields($columnName, $postType) |
|
145 | + { |
|
146 | + if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
147 | + glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @param string $postType |
|
153 | - * @return void |
|
154 | - * @action restrict_manage_posts |
|
155 | - */ |
|
156 | - public function renderColumnFilters($postType) |
|
157 | - { |
|
158 | - glsr(Columns::class)->renderFilters($postType); |
|
159 | - } |
|
151 | + /** |
|
152 | + * @param string $postType |
|
153 | + * @return void |
|
154 | + * @action restrict_manage_posts |
|
155 | + */ |
|
156 | + public function renderColumnFilters($postType) |
|
157 | + { |
|
158 | + glsr(Columns::class)->renderFilters($postType); |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * @param string $column |
|
163 | - * @param string $postId |
|
164 | - * @return void |
|
165 | - * @action manage_posts_custom_column |
|
166 | - */ |
|
167 | - public function renderColumnValues($column, $postId) |
|
168 | - { |
|
169 | - glsr(Columns::class)->renderValues($column, $postId); |
|
170 | - } |
|
161 | + /** |
|
162 | + * @param string $column |
|
163 | + * @param string $postId |
|
164 | + * @return void |
|
165 | + * @action manage_posts_custom_column |
|
166 | + */ |
|
167 | + public function renderColumnValues($column, $postId) |
|
168 | + { |
|
169 | + glsr(Columns::class)->renderValues($column, $postId); |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * @param int $postId |
|
174 | - * @return void |
|
175 | - * @action save_post_.Application::POST_TYPE |
|
176 | - */ |
|
177 | - public function saveBulkEditFields($postId) |
|
178 | - { |
|
179 | - if (!glsr()->can('edit_posts')) { |
|
180 | - return; |
|
181 | - } |
|
182 | - $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
183 | - if ($assignedTo && get_post($assignedTo)) { |
|
184 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
185 | - } |
|
186 | - } |
|
172 | + /** |
|
173 | + * @param int $postId |
|
174 | + * @return void |
|
175 | + * @action save_post_.Application::POST_TYPE |
|
176 | + */ |
|
177 | + public function saveBulkEditFields($postId) |
|
178 | + { |
|
179 | + if (!glsr()->can('edit_posts')) { |
|
180 | + return; |
|
181 | + } |
|
182 | + $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
183 | + if ($assignedTo && get_post($assignedTo)) { |
|
184 | + glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
185 | + } |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @return void |
|
190 | - * @action pre_get_posts |
|
191 | - */ |
|
192 | - public function setQueryForColumn(WP_Query $query) |
|
193 | - { |
|
194 | - if (!$this->hasPermission($query)) { |
|
195 | - return; |
|
196 | - } |
|
197 | - $this->setMetaQuery($query, [ |
|
198 | - 'rating', 'review_type', |
|
199 | - ]); |
|
200 | - $this->setOrderby($query); |
|
201 | - } |
|
188 | + /** |
|
189 | + * @return void |
|
190 | + * @action pre_get_posts |
|
191 | + */ |
|
192 | + public function setQueryForColumn(WP_Query $query) |
|
193 | + { |
|
194 | + if (!$this->hasPermission($query)) { |
|
195 | + return; |
|
196 | + } |
|
197 | + $this->setMetaQuery($query, [ |
|
198 | + 'rating', 'review_type', |
|
199 | + ]); |
|
200 | + $this->setOrderby($query); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @return void |
|
205 | - * @action admin_action_unapprove |
|
206 | - */ |
|
207 | - public function unapprove() |
|
208 | - { |
|
209 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
210 | - return; |
|
211 | - } |
|
212 | - check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
213 | - wp_update_post([ |
|
214 | - 'ID' => $postId, |
|
215 | - 'post_status' => 'pending', |
|
216 | - ]); |
|
217 | - wp_safe_redirect(wp_get_referer()); |
|
218 | - exit; |
|
219 | - } |
|
203 | + /** |
|
204 | + * @return void |
|
205 | + * @action admin_action_unapprove |
|
206 | + */ |
|
207 | + public function unapprove() |
|
208 | + { |
|
209 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
210 | + return; |
|
211 | + } |
|
212 | + check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
213 | + wp_update_post([ |
|
214 | + 'ID' => $postId, |
|
215 | + 'post_status' => 'pending', |
|
216 | + ]); |
|
217 | + wp_safe_redirect(wp_get_referer()); |
|
218 | + exit; |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * Check if the translation string can be modified. |
|
223 | - * @param string $domain |
|
224 | - * @return bool |
|
225 | - */ |
|
226 | - protected function canModifyTranslation($domain = 'default') |
|
227 | - { |
|
228 | - $screen = glsr_current_screen(); |
|
229 | - return 'default' == $domain |
|
230 | - && 'edit' == $screen->base |
|
231 | - && Application::POST_TYPE == $screen->post_type; |
|
232 | - } |
|
221 | + /** |
|
222 | + * Check if the translation string can be modified. |
|
223 | + * @param string $domain |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | + protected function canModifyTranslation($domain = 'default') |
|
227 | + { |
|
228 | + $screen = glsr_current_screen(); |
|
229 | + return 'default' == $domain |
|
230 | + && 'edit' == $screen->base |
|
231 | + && Application::POST_TYPE == $screen->post_type; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @return bool |
|
236 | - */ |
|
237 | - protected function hasPermission(WP_Query $query) |
|
238 | - { |
|
239 | - global $pagenow; |
|
240 | - return is_admin() |
|
241 | - && $query->is_main_query() |
|
242 | - && Application::POST_TYPE == $query->get('post_type') |
|
243 | - && 'edit.php' == $pagenow; |
|
244 | - } |
|
234 | + /** |
|
235 | + * @return bool |
|
236 | + */ |
|
237 | + protected function hasPermission(WP_Query $query) |
|
238 | + { |
|
239 | + global $pagenow; |
|
240 | + return is_admin() |
|
241 | + && $query->is_main_query() |
|
242 | + && Application::POST_TYPE == $query->get('post_type') |
|
243 | + && 'edit.php' == $pagenow; |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * @return void |
|
248 | - */ |
|
249 | - protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
250 | - { |
|
251 | - foreach ($metaKeys as $key) { |
|
252 | - $value = (string) filter_input(INPUT_GET, $key); |
|
253 | - if ('' === $value) { |
|
254 | - continue; |
|
255 | - } |
|
256 | - $metaQuery = (array) $query->get('meta_query'); |
|
257 | - $metaQuery[] = [ |
|
258 | - 'key' => Str::prefix('_', $key, '_'), |
|
259 | - 'value' => $value, |
|
260 | - ]; |
|
261 | - $query->set('meta_query', array_filter($metaQuery)); |
|
262 | - } |
|
263 | - } |
|
246 | + /** |
|
247 | + * @return void |
|
248 | + */ |
|
249 | + protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
250 | + { |
|
251 | + foreach ($metaKeys as $key) { |
|
252 | + $value = (string) filter_input(INPUT_GET, $key); |
|
253 | + if ('' === $value) { |
|
254 | + continue; |
|
255 | + } |
|
256 | + $metaQuery = (array) $query->get('meta_query'); |
|
257 | + $metaQuery[] = [ |
|
258 | + 'key' => Str::prefix('_', $key, '_'), |
|
259 | + 'value' => $value, |
|
260 | + ]; |
|
261 | + $query->set('meta_query', array_filter($metaQuery)); |
|
262 | + } |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - protected function setOrderby(WP_Query $query) |
|
269 | - { |
|
270 | - $orderby = $query->get('orderby'); |
|
271 | - $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
272 | - unset($columns['cb'], $columns['title'], $columns['date']); |
|
273 | - if (in_array($orderby, array_keys($columns))) { |
|
274 | - if ('reviewer' == $orderby) { |
|
275 | - $orderby = 'author'; |
|
276 | - } |
|
277 | - $query->set('meta_key', Str::prefix('_', $orderby, '_')); |
|
278 | - $query->set('orderby', 'meta_value'); |
|
279 | - } |
|
280 | - } |
|
265 | + /** |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + protected function setOrderby(WP_Query $query) |
|
269 | + { |
|
270 | + $orderby = $query->get('orderby'); |
|
271 | + $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
272 | + unset($columns['cb'], $columns['title'], $columns['date']); |
|
273 | + if (in_array($orderby, array_keys($columns))) { |
|
274 | + if ('reviewer' == $orderby) { |
|
275 | + $orderby = 'author'; |
|
276 | + } |
|
277 | + $query->set('meta_key', Str::prefix('_', $orderby, '_')); |
|
278 | + $query->set('orderby', 'meta_value'); |
|
279 | + } |
|
280 | + } |
|
281 | 281 | } |
@@ -10,55 +10,55 @@ |
||
10 | 10 | |
11 | 11 | abstract class Controller |
12 | 12 | { |
13 | - /** |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function download($filename, $content) |
|
17 | - { |
|
18 | - if (!glsr()->can('edit_others_posts')) { |
|
19 | - return; |
|
20 | - } |
|
21 | - nocache_headers(); |
|
22 | - header('Content-Type: text/plain'); |
|
23 | - header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
24 | - echo html_entity_decode($content); |
|
25 | - exit; |
|
26 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function download($filename, $content) |
|
17 | + { |
|
18 | + if (!glsr()->can('edit_others_posts')) { |
|
19 | + return; |
|
20 | + } |
|
21 | + nocache_headers(); |
|
22 | + header('Content-Type: text/plain'); |
|
23 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
24 | + echo html_entity_decode($content); |
|
25 | + exit; |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param object $command |
|
30 | - * @return mixed |
|
31 | - * @throws InvalidArgumentException |
|
32 | - */ |
|
33 | - public function execute($command) |
|
34 | - { |
|
35 | - $handlerClass = str_replace('Commands', 'Handlers', get_class($command)); |
|
36 | - if (!class_exists($handlerClass)) { |
|
37 | - throw new InvalidArgumentException('Handler '.$handlerClass.' not found.'); |
|
38 | - } |
|
39 | - try { |
|
40 | - return glsr($handlerClass)->handle($command); |
|
41 | - } catch (Exception $e) { |
|
42 | - status_header(400); |
|
43 | - glsr(Notice::class)->addError(new WP_Error('site_reviews_error', $e->getMessage())); |
|
44 | - glsr_log()->error($e->getMessage()); |
|
45 | - } |
|
46 | - } |
|
28 | + /** |
|
29 | + * @param object $command |
|
30 | + * @return mixed |
|
31 | + * @throws InvalidArgumentException |
|
32 | + */ |
|
33 | + public function execute($command) |
|
34 | + { |
|
35 | + $handlerClass = str_replace('Commands', 'Handlers', get_class($command)); |
|
36 | + if (!class_exists($handlerClass)) { |
|
37 | + throw new InvalidArgumentException('Handler '.$handlerClass.' not found.'); |
|
38 | + } |
|
39 | + try { |
|
40 | + return glsr($handlerClass)->handle($command); |
|
41 | + } catch (Exception $e) { |
|
42 | + status_header(400); |
|
43 | + glsr(Notice::class)->addError(new WP_Error('site_reviews_error', $e->getMessage())); |
|
44 | + glsr_log()->error($e->getMessage()); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return int |
|
50 | - */ |
|
51 | - protected function getPostId() |
|
52 | - { |
|
53 | - return intval(filter_input(INPUT_GET, 'post')); |
|
54 | - } |
|
48 | + /** |
|
49 | + * @return int |
|
50 | + */ |
|
51 | + protected function getPostId() |
|
52 | + { |
|
53 | + return intval(filter_input(INPUT_GET, 'post')); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param int $postId |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - protected function isReviewPostId($postId) |
|
61 | - { |
|
62 | - return Application::POST_TYPE == get_post_field('post_type', $postId); |
|
63 | - } |
|
56 | + /** |
|
57 | + * @param int $postId |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + protected function isReviewPostId($postId) |
|
61 | + { |
|
62 | + return Application::POST_TYPE == get_post_field('post_type', $postId); |
|
63 | + } |
|
64 | 64 | } |