@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | public function __construct() |
41 | 41 | { |
42 | 42 | static::$instance = $this; |
43 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
44 | - $plugin = get_file_data($this->file, [ |
|
43 | + $this->file = realpath( trailingslashit( dirname( __DIR__ ) ).static::ID.'.php' ); |
|
44 | + $plugin = get_file_data( $this->file, [ |
|
45 | 45 | 'languages' => 'Domain Path', |
46 | 46 | 'name' => 'Plugin Name', |
47 | 47 | 'version' => 'Version', |
48 | - ], 'plugin'); |
|
49 | - array_walk($plugin, function ($value, $key) { |
|
48 | + ], 'plugin' ); |
|
49 | + array_walk( $plugin, function( $value, $key ) { |
|
50 | 50 | $this->$key = $value; |
51 | 51 | }); |
52 | 52 | } |
@@ -57,17 +57,17 @@ discard block |
||
57 | 57 | public function activate() |
58 | 58 | { |
59 | 59 | $this->scheduleCronJob(); |
60 | - add_option(static::PREFIX.'activated', true); |
|
60 | + add_option( static::PREFIX.'activated', true ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @param string $view |
65 | 65 | * @return string |
66 | 66 | */ |
67 | - public function build($view, array $data = []) |
|
67 | + public function build( $view, array $data = [] ) |
|
68 | 68 | { |
69 | 69 | ob_start(); |
70 | - $this->render($view, $data); |
|
70 | + $this->render( $view, $data ); |
|
71 | 71 | return ob_get_clean(); |
72 | 72 | } |
73 | 73 | |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * @param string $capability |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | - public function can($capability) |
|
78 | + public function can( $capability ) |
|
79 | 79 | { |
80 | - return $this->make(Role::class)->can($capability); |
|
80 | + return $this->make( Role::class )->can( $capability ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,34 +86,34 @@ discard block |
||
86 | 86 | public function catchFatalError() |
87 | 87 | { |
88 | 88 | $error = error_get_last(); |
89 | - if (E_ERROR !== Arr::get($error, 'type') || !Str::contains(Arr::get($error, 'message'), $this->path())) { |
|
89 | + if( E_ERROR !== Arr::get( $error, 'type' ) || !Str::contains( Arr::get( $error, 'message' ), $this->path() ) ) { |
|
90 | 90 | return; |
91 | 91 | } |
92 | - glsr_log()->error($error['message']); |
|
92 | + glsr_log()->error( $error['message'] ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | 96 | * @param string $name |
97 | 97 | * @return array |
98 | 98 | */ |
99 | - public function config($name) |
|
99 | + public function config( $name ) |
|
100 | 100 | { |
101 | - $configFile = $this->path('config/'.$name.'.php'); |
|
102 | - $config = file_exists($configFile) |
|
101 | + $configFile = $this->path( 'config/'.$name.'.php' ); |
|
102 | + $config = file_exists( $configFile ) |
|
103 | 103 | ? include $configFile |
104 | 104 | : []; |
105 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
105 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | 109 | * @param string $property |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - public function constant($property, $className = 'static') |
|
112 | + public function constant( $property, $className = 'static' ) |
|
113 | 113 | { |
114 | 114 | $constant = $className.'::'.$property; |
115 | - return defined($constant) |
|
116 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
115 | + return defined( $constant ) |
|
116 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
117 | 117 | : ''; |
118 | 118 | } |
119 | 119 | |
@@ -129,17 +129,17 @@ discard block |
||
129 | 129 | * @param string $view |
130 | 130 | * @return void|string |
131 | 131 | */ |
132 | - public function file($view) |
|
132 | + public function file( $view ) |
|
133 | 133 | { |
134 | - $view.= '.php'; |
|
134 | + $view .= '.php'; |
|
135 | 135 | $filePaths = []; |
136 | - if (Str::startsWith('templates/', $view)) { |
|
137 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
136 | + if( Str::startsWith( 'templates/', $view ) ) { |
|
137 | + $filePaths[] = $this->themePath( Str::removePrefix( 'templates/', $view ) ); |
|
138 | 138 | } |
139 | - $filePaths[] = $this->path($view); |
|
140 | - $filePaths[] = $this->path('views/'.$view); |
|
141 | - foreach ($filePaths as $file) { |
|
142 | - if (!file_exists($file)) { |
|
139 | + $filePaths[] = $this->path( $view ); |
|
140 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
141 | + foreach( $filePaths as $file ) { |
|
142 | + if( !file_exists( $file ) ) { |
|
143 | 143 | continue; |
144 | 144 | } |
145 | 145 | return $file; |
@@ -151,10 +151,10 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function getDefaults() |
153 | 153 | { |
154 | - if (empty($this->defaults)) { |
|
155 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
154 | + if( empty($this->defaults) ) { |
|
155 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
156 | 156 | } |
157 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
157 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param string $tab |
163 | 163 | * @return string |
164 | 164 | */ |
165 | - public function getPermission($page = '', $tab = 'index') |
|
165 | + public function getPermission( $page = '', $tab = 'index' ) |
|
166 | 166 | { |
167 | 167 | $fallback = 'edit_posts'; |
168 | 168 | $permissions = [ |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | 'system-info' => 'edit_others_posts', |
184 | 184 | ] |
185 | 185 | ]; |
186 | - $permission = Arr::get($permissions, $page, $fallback); |
|
187 | - if (is_array($permission)) { |
|
188 | - $permission = Arr::get($permission, $tab, $fallback); |
|
186 | + $permission = Arr::get( $permissions, $page, $fallback ); |
|
187 | + if( is_array( $permission ) ) { |
|
188 | + $permission = Arr::get( $permission, $tab, $fallback ); |
|
189 | 189 | } |
190 | - return empty($permission) || !is_string($permission) |
|
190 | + return empty($permission) || !is_string( $permission ) |
|
191 | 191 | ? $fallback |
192 | 192 | : $permission; |
193 | 193 | } |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | * @param string $tab |
198 | 198 | * @return bool |
199 | 199 | */ |
200 | - public function hasPermission($page = '', $tab = 'index') |
|
200 | + public function hasPermission( $page = '', $tab = 'index' ) |
|
201 | 201 | { |
202 | 202 | $isAdmin = $this->isAdmin(); |
203 | - return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
203 | + return !$isAdmin || ($isAdmin && $this->can( $this->getPermission( $page, $tab ) )); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function init() |
210 | 210 | { |
211 | - $this->make(Actions::class)->run(); |
|
212 | - $this->make(Filters::class)->run(); |
|
211 | + $this->make( Actions::class )->run(); |
|
212 | + $this->make( Filters::class )->run(); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -224,31 +224,31 @@ discard block |
||
224 | 224 | * @param string $file |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - public function path($file = '', $realpath = true) |
|
227 | + public function path( $file = '', $realpath = true ) |
|
228 | 228 | { |
229 | - $path = plugin_dir_path($this->file); |
|
230 | - if (!$realpath) { |
|
231 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
229 | + $path = plugin_dir_path( $this->file ); |
|
230 | + if( !$realpath ) { |
|
231 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
232 | 232 | } |
233 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
234 | - return apply_filters('site-reviews/path', $path, $file); |
|
233 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
234 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | 238 | * @param object $addon |
239 | 239 | * @return void |
240 | 240 | */ |
241 | - public function register($addon) |
|
241 | + public function register( $addon ) |
|
242 | 242 | { |
243 | 243 | try { |
244 | - $reflection = new \ReflectionClass($addon); |
|
245 | - if ($id = $reflection->getConstant('ID')) { |
|
244 | + $reflection = new \ReflectionClass( $addon ); |
|
245 | + if( $id = $reflection->getConstant( 'ID' ) ) { |
|
246 | 246 | $this->addons[] = $id; |
247 | - $this->bind($id, $addon); |
|
247 | + $this->bind( $id, $addon ); |
|
248 | 248 | $addon->init(); |
249 | 249 | } |
250 | - } catch(\ReflectionException $e) { |
|
251 | - glsr_log()->error('Attempted to register an invalid addon.'); |
|
250 | + } catch( \ReflectionException $e ) { |
|
251 | + glsr_log()->error( 'Attempted to register an invalid addon.' ); |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function registerAddons() |
259 | 259 | { |
260 | - do_action('site-reviews/addon/register', $this); |
|
260 | + do_action( 'site-reviews/addon/register', $this ); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -265,8 +265,8 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function registerLanguages() |
267 | 267 | { |
268 | - load_plugin_textdomain(static::ID, false, |
|
269 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
268 | + load_plugin_textdomain( static::ID, false, |
|
269 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
270 | 270 | ); |
271 | 271 | } |
272 | 272 | |
@@ -275,26 +275,26 @@ discard block |
||
275 | 275 | */ |
276 | 276 | public function registerReviewTypes() |
277 | 277 | { |
278 | - $types = apply_filters('site-reviews/addon/types', []); |
|
279 | - $this->reviewTypes = wp_parse_args($types, [ |
|
280 | - 'local' => __('Local', 'site-reviews'), |
|
281 | - ]); |
|
278 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
279 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
280 | + 'local' => __( 'Local', 'site-reviews' ), |
|
281 | + ] ); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | 285 | * @param string $view |
286 | 286 | * @return void |
287 | 287 | */ |
288 | - public function render($view, array $data = []) |
|
288 | + public function render( $view, array $data = [] ) |
|
289 | 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); |
|
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 | 294 | return; |
295 | 295 | } |
296 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
297 | - extract($data); |
|
296 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
297 | + extract( $data ); |
|
298 | 298 | include $file; |
299 | 299 | } |
300 | 300 | |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public function scheduleCronJob() |
305 | 305 | { |
306 | - if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
307 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
306 | + if( false === wp_next_scheduled( static::CRON_EVENT ) ) { |
|
307 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | |
@@ -313,9 +313,9 @@ discard block |
||
313 | 313 | */ |
314 | 314 | public function setDefaults() |
315 | 315 | { |
316 | - if (get_option(static::PREFIX.'activated')) { |
|
317 | - $this->make(DefaultsManager::class)->set(); |
|
318 | - delete_option(static::PREFIX.'activated'); |
|
316 | + if( get_option( static::PREFIX.'activated' ) ) { |
|
317 | + $this->make( DefaultsManager::class )->set(); |
|
318 | + delete_option( static::PREFIX.'activated' ); |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -323,9 +323,9 @@ discard block |
||
323 | 323 | * @param string $file |
324 | 324 | * @return string |
325 | 325 | */ |
326 | - public function themePath($file = '') |
|
326 | + public function themePath( $file = '' ) |
|
327 | 327 | { |
328 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
328 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -333,36 +333,36 @@ discard block |
||
333 | 333 | */ |
334 | 334 | public function unscheduleCronJob() |
335 | 335 | { |
336 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
336 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /** |
340 | 340 | * @param string $path |
341 | 341 | * @return string |
342 | 342 | */ |
343 | - public function url($path = '') |
|
343 | + public function url( $path = '' ) |
|
344 | 344 | { |
345 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
346 | - return apply_filters('site-reviews/url', $url, $path); |
|
345 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
346 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
350 | 350 | * @param string $versionLevel |
351 | 351 | * @return string |
352 | 352 | */ |
353 | - public function version($versionLevel = '') |
|
353 | + public function version( $versionLevel = '' ) |
|
354 | 354 | { |
355 | 355 | $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
356 | - preg_match($pattern, $this->version, $matches); |
|
357 | - switch ($versionLevel) { |
|
356 | + preg_match( $pattern, $this->version, $matches ); |
|
357 | + switch( $versionLevel ) { |
|
358 | 358 | case 'major': |
359 | - $version = Arr::get($matches, 1); |
|
359 | + $version = Arr::get( $matches, 1 ); |
|
360 | 360 | break; |
361 | 361 | case 'minor': |
362 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
362 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ); |
|
363 | 363 | break; |
364 | 364 | case 'patch': |
365 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
365 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ).Arr::get( $matches, 3 ); |
|
366 | 366 | break; |
367 | 367 | } |
368 | 368 | return empty($version) |