@@ -8,84 +8,84 @@ |
||
8 | 8 | |
9 | 9 | class Migrate_4_6_0 |
10 | 10 | { |
11 | - /** |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function migrateSidebarWidgets() |
|
15 | - { |
|
16 | - $sidebars = get_option('sidebars_widgets'); |
|
17 | - if ($this->widgetsExist($sidebars)) { |
|
18 | - $sidebars = $this->updateWidgetNames($sidebars); |
|
19 | - update_option('sidebars_widgets', $sidebars); |
|
20 | - } |
|
21 | - } |
|
11 | + /** |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function migrateSidebarWidgets() |
|
15 | + { |
|
16 | + $sidebars = get_option('sidebars_widgets'); |
|
17 | + if ($this->widgetsExist($sidebars)) { |
|
18 | + $sidebars = $this->updateWidgetNames($sidebars); |
|
19 | + update_option('sidebars_widgets', $sidebars); |
|
20 | + } |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function migrateThemeModWidgets() |
|
27 | - { |
|
28 | - $themes = $this->queryThemeMods(); |
|
29 | - foreach ($themes as $theme) { |
|
30 | - $themeMod = get_option($theme); |
|
31 | - $sidebars = Arr::get($themeMod, 'sidebars_widgets.data'); |
|
32 | - if ($this->widgetsExist($sidebars)) { |
|
33 | - $themeMod['sidebars_widgets']['data'] = $this->updateWidgetNames($sidebars); |
|
34 | - update_option($theme, $themeMod); |
|
35 | - } |
|
36 | - } |
|
37 | - } |
|
23 | + /** |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function migrateThemeModWidgets() |
|
27 | + { |
|
28 | + $themes = $this->queryThemeMods(); |
|
29 | + foreach ($themes as $theme) { |
|
30 | + $themeMod = get_option($theme); |
|
31 | + $sidebars = Arr::get($themeMod, 'sidebars_widgets.data'); |
|
32 | + if ($this->widgetsExist($sidebars)) { |
|
33 | + $themeMod['sidebars_widgets']['data'] = $this->updateWidgetNames($sidebars); |
|
34 | + update_option($theme, $themeMod); |
|
35 | + } |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function run() |
|
43 | - { |
|
44 | - $this->migrateSidebarWidgets(); |
|
45 | - $this->migrateThemeModWidgets(); |
|
46 | - } |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function run() |
|
43 | + { |
|
44 | + $this->migrateSidebarWidgets(); |
|
45 | + $this->migrateThemeModWidgets(); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - protected function queryThemeMods() |
|
52 | - { |
|
53 | - global $wpdb; |
|
54 | - return $wpdb->get_col(" |
|
48 | + /** |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + protected function queryThemeMods() |
|
52 | + { |
|
53 | + global $wpdb; |
|
54 | + return $wpdb->get_col(" |
|
55 | 55 | SELECT option_name |
56 | 56 | FROM {$wpdb->options} |
57 | 57 | WHERE option_name LIKE '%theme_mods_%' |
58 | 58 | "); |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param array $sidebars |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - protected function updateWidgetNames(array $sidebars) |
|
66 | - { |
|
67 | - array_walk($sidebars, function(&$widgets) { |
|
68 | - array_walk($widgets, function(&$widget) { |
|
69 | - if (Str::startsWith(Application::ID.'_', $widget)) { |
|
70 | - $widget = Str::replaceFirst(Application::ID.'_', Application::PREFIX, $widget); |
|
71 | - } |
|
72 | - }); |
|
73 | - }); |
|
74 | - return $sidebars; |
|
75 | - } |
|
61 | + /** |
|
62 | + * @param array $sidebars |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + protected function updateWidgetNames(array $sidebars) |
|
66 | + { |
|
67 | + array_walk($sidebars, function(&$widgets) { |
|
68 | + array_walk($widgets, function(&$widget) { |
|
69 | + if (Str::startsWith(Application::ID.'_', $widget)) { |
|
70 | + $widget = Str::replaceFirst(Application::ID.'_', Application::PREFIX, $widget); |
|
71 | + } |
|
72 | + }); |
|
73 | + }); |
|
74 | + return $sidebars; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param array $sidebars |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - protected function widgetsExist($sidebars) |
|
82 | - { |
|
83 | - $widgets = call_user_func_array('array_merge', array_filter(Arr::consolidate($sidebars), 'is_array')); |
|
84 | - foreach ($widgets as $widget) { |
|
85 | - if (Str::startsWith(Application::ID.'_', $widget)) { |
|
86 | - return true; |
|
87 | - } |
|
88 | - } |
|
89 | - return false; |
|
90 | - } |
|
77 | + /** |
|
78 | + * @param array $sidebars |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + protected function widgetsExist($sidebars) |
|
82 | + { |
|
83 | + $widgets = call_user_func_array('array_merge', array_filter(Arr::consolidate($sidebars), 'is_array')); |
|
84 | + foreach ($widgets as $widget) { |
|
85 | + if (Str::startsWith(Application::ID.'_', $widget)) { |
|
86 | + return true; |
|
87 | + } |
|
88 | + } |
|
89 | + return false; |
|
90 | + } |
|
91 | 91 | } |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | */ |
14 | 14 | public function migrateSidebarWidgets() |
15 | 15 | { |
16 | - $sidebars = get_option('sidebars_widgets'); |
|
17 | - if ($this->widgetsExist($sidebars)) { |
|
18 | - $sidebars = $this->updateWidgetNames($sidebars); |
|
19 | - update_option('sidebars_widgets', $sidebars); |
|
16 | + $sidebars = get_option( 'sidebars_widgets' ); |
|
17 | + if( $this->widgetsExist( $sidebars ) ) { |
|
18 | + $sidebars = $this->updateWidgetNames( $sidebars ); |
|
19 | + update_option( 'sidebars_widgets', $sidebars ); |
|
20 | 20 | } |
21 | 21 | } |
22 | 22 | |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | public function migrateThemeModWidgets() |
27 | 27 | { |
28 | 28 | $themes = $this->queryThemeMods(); |
29 | - foreach ($themes as $theme) { |
|
30 | - $themeMod = get_option($theme); |
|
31 | - $sidebars = Arr::get($themeMod, 'sidebars_widgets.data'); |
|
32 | - if ($this->widgetsExist($sidebars)) { |
|
33 | - $themeMod['sidebars_widgets']['data'] = $this->updateWidgetNames($sidebars); |
|
34 | - update_option($theme, $themeMod); |
|
29 | + foreach( $themes as $theme ) { |
|
30 | + $themeMod = get_option( $theme ); |
|
31 | + $sidebars = Arr::get( $themeMod, 'sidebars_widgets.data' ); |
|
32 | + if( $this->widgetsExist( $sidebars ) ) { |
|
33 | + $themeMod['sidebars_widgets']['data'] = $this->updateWidgetNames( $sidebars ); |
|
34 | + update_option( $theme, $themeMod ); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | } |
@@ -51,23 +51,23 @@ discard block |
||
51 | 51 | protected function queryThemeMods() |
52 | 52 | { |
53 | 53 | global $wpdb; |
54 | - return $wpdb->get_col(" |
|
54 | + return $wpdb->get_col( " |
|
55 | 55 | SELECT option_name |
56 | 56 | FROM {$wpdb->options} |
57 | 57 | WHERE option_name LIKE '%theme_mods_%' |
58 | - "); |
|
58 | + " ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | 62 | * @param array $sidebars |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - protected function updateWidgetNames(array $sidebars) |
|
65 | + protected function updateWidgetNames( array $sidebars ) |
|
66 | 66 | { |
67 | - array_walk($sidebars, function(&$widgets) { |
|
68 | - array_walk($widgets, function(&$widget) { |
|
69 | - if (Str::startsWith(Application::ID.'_', $widget)) { |
|
70 | - $widget = Str::replaceFirst(Application::ID.'_', Application::PREFIX, $widget); |
|
67 | + array_walk( $sidebars, function( &$widgets ) { |
|
68 | + array_walk( $widgets, function( &$widget ) { |
|
69 | + if( Str::startsWith( Application::ID.'_', $widget ) ) { |
|
70 | + $widget = Str::replaceFirst( Application::ID.'_', Application::PREFIX, $widget ); |
|
71 | 71 | } |
72 | 72 | }); |
73 | 73 | }); |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * @param array $sidebars |
79 | 79 | * @return bool |
80 | 80 | */ |
81 | - protected function widgetsExist($sidebars) |
|
81 | + protected function widgetsExist( $sidebars ) |
|
82 | 82 | { |
83 | - $widgets = call_user_func_array('array_merge', array_filter(Arr::consolidate($sidebars), 'is_array')); |
|
84 | - foreach ($widgets as $widget) { |
|
85 | - if (Str::startsWith(Application::ID.'_', $widget)) { |
|
83 | + $widgets = call_user_func_array( 'array_merge', array_filter( Arr::consolidate( $sidebars ), 'is_array' ) ); |
|
84 | + foreach( $widgets as $widget ) { |
|
85 | + if( Str::startsWith( Application::ID.'_', $widget ) ) { |
|
86 | 86 | return true; |
87 | 87 | } |
88 | 88 | } |
@@ -12,144 +12,144 @@ |
||
12 | 12 | |
13 | 13 | class Style |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public $fields; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public $fields; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - public $style; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + public $style; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - public $pagination; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + public $pagination; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - public $validation; |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + public $validation; |
|
34 | 34 | |
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
38 | - $this->setConfig(); |
|
39 | - } |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
38 | + $this->setConfig(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $view |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function filterView($view) |
|
46 | - { |
|
47 | - $styledViews = apply_filters('site-reviews/style/views', [ |
|
48 | - 'templates/form/field', |
|
49 | - 'templates/form/response', |
|
50 | - 'templates/form/submit-button', |
|
51 | - 'templates/reviews-form', |
|
52 | - ]); |
|
53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
54 | - return $view; |
|
55 | - } |
|
56 | - $views = $this->generatePossibleViews($view); |
|
57 | - foreach ($views as $possibleView) { |
|
58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
59 | - continue; |
|
60 | - } |
|
61 | - return Str::removePrefix('views/', $possibleView); |
|
62 | - } |
|
63 | - return $view; |
|
64 | - } |
|
41 | + /** |
|
42 | + * @param string $view |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function filterView($view) |
|
46 | + { |
|
47 | + $styledViews = apply_filters('site-reviews/style/views', [ |
|
48 | + 'templates/form/field', |
|
49 | + 'templates/form/response', |
|
50 | + 'templates/form/submit-button', |
|
51 | + 'templates/reviews-form', |
|
52 | + ]); |
|
53 | + if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
54 | + return $view; |
|
55 | + } |
|
56 | + $views = $this->generatePossibleViews($view); |
|
57 | + foreach ($views as $possibleView) { |
|
58 | + if (!file_exists(glsr()->file($possibleView))) { |
|
59 | + continue; |
|
60 | + } |
|
61 | + return Str::removePrefix('views/', $possibleView); |
|
62 | + } |
|
63 | + return $view; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function get() |
|
70 | - { |
|
71 | - return apply_filters('site-reviews/style', $this->style); |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function get() |
|
70 | + { |
|
71 | + return apply_filters('site-reviews/style', $this->style); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - public function setConfig() |
|
78 | - { |
|
79 | - $config = shortcode_atts( |
|
80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | - glsr()->config('styles/'.$this->style) |
|
82 | - ); |
|
83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
86 | - } |
|
74 | + /** |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + public function setConfig() |
|
78 | + { |
|
79 | + $config = shortcode_atts( |
|
80 | + array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | + glsr()->config('styles/'.$this->style) |
|
82 | + ); |
|
83 | + $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | + $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | + $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function modifyField(Builder $instance) |
|
92 | - { |
|
93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
94 | - return; |
|
95 | - } |
|
96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
97 | - } |
|
88 | + /** |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function modifyField(Builder $instance) |
|
92 | + { |
|
93 | + if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
94 | + return; |
|
95 | + } |
|
96 | + call_user_func_array([$this, 'customize'], [$instance]); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - public function paginationArgs(array $args) |
|
103 | - { |
|
104 | - return wp_parse_args($args, $this->pagination); |
|
105 | - } |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + public function paginationArgs(array $args) |
|
103 | + { |
|
104 | + return wp_parse_args($args, $this->pagination); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - protected function customize(Builder $instance) |
|
111 | - { |
|
112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
113 | - return; |
|
114 | - } |
|
115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
116 | - $key = $instance->tag.'_'.$args['type']; |
|
117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
120 | - } |
|
107 | + /** |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + protected function customize(Builder $instance) |
|
111 | + { |
|
112 | + if (!array_key_exists($instance->tag, $this->fields)) { |
|
113 | + return; |
|
114 | + } |
|
115 | + $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
116 | + $key = $instance->tag.'_'.$args['type']; |
|
117 | + $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | + $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | + do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @param string $view |
|
124 | - * @return array |
|
125 | - */ |
|
126 | - protected function generatePossibleViews($view) |
|
127 | - { |
|
128 | - $basename = basename($view); |
|
129 | - $basepath = rtrim($view, $basename); |
|
130 | - $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
131 | - $parts = explode('_', $basename); |
|
132 | - $views = [ |
|
133 | - $customPath.$basename, |
|
134 | - $customPath.$parts[0], |
|
135 | - $view, |
|
136 | - $basepath.$parts[0], |
|
137 | - ]; |
|
138 | - return array_filter($views); |
|
139 | - } |
|
122 | + /** |
|
123 | + * @param string $view |
|
124 | + * @return array |
|
125 | + */ |
|
126 | + protected function generatePossibleViews($view) |
|
127 | + { |
|
128 | + $basename = basename($view); |
|
129 | + $basepath = rtrim($view, $basename); |
|
130 | + $customPath = 'views/partials/styles/'.$this->style.'/'; |
|
131 | + $parts = explode('_', $basename); |
|
132 | + $views = [ |
|
133 | + $customPath.$basename, |
|
134 | + $customPath.$parts[0], |
|
135 | + $view, |
|
136 | + $basepath.$parts[0], |
|
137 | + ]; |
|
138 | + return array_filter($views); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - protected function isPublicInstance(Builder $instance) |
|
145 | - { |
|
146 | - $args = wp_parse_args($instance->args, [ |
|
147 | - 'is_public' => false, |
|
148 | - 'is_raw' => false, |
|
149 | - ]); |
|
150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
151 | - return false; |
|
152 | - } |
|
153 | - return true; |
|
154 | - } |
|
141 | + /** |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + protected function isPublicInstance(Builder $instance) |
|
145 | + { |
|
146 | + $args = wp_parse_args($instance->args, [ |
|
147 | + 'is_public' => false, |
|
148 | + 'is_raw' => false, |
|
149 | + ]); |
|
150 | + if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
151 | + return false; |
|
152 | + } |
|
153 | + return true; |
|
154 | + } |
|
155 | 155 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | public function __construct() |
36 | 36 | { |
37 | - $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default'); |
|
37 | + $this->style = glsr( OptionManager::class )->get( 'settings.general.style', 'default' ); |
|
38 | 38 | $this->setConfig(); |
39 | 39 | } |
40 | 40 | |
@@ -42,23 +42,23 @@ discard block |
||
42 | 42 | * @param string $view |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function filterView($view) |
|
45 | + public function filterView( $view ) |
|
46 | 46 | { |
47 | - $styledViews = apply_filters('site-reviews/style/views', [ |
|
47 | + $styledViews = apply_filters( 'site-reviews/style/views', [ |
|
48 | 48 | 'templates/form/field', |
49 | 49 | 'templates/form/response', |
50 | 50 | 'templates/form/submit-button', |
51 | 51 | 'templates/reviews-form', |
52 | - ]); |
|
53 | - if (!preg_match('('.implode('|', $styledViews).')', $view)) { |
|
52 | + ] ); |
|
53 | + if( !preg_match( '('.implode( '|', $styledViews ).')', $view ) ) { |
|
54 | 54 | return $view; |
55 | 55 | } |
56 | - $views = $this->generatePossibleViews($view); |
|
57 | - foreach ($views as $possibleView) { |
|
58 | - if (!file_exists(glsr()->file($possibleView))) { |
|
56 | + $views = $this->generatePossibleViews( $view ); |
|
57 | + foreach( $views as $possibleView ) { |
|
58 | + if( !file_exists( glsr()->file( $possibleView ) ) ) { |
|
59 | 59 | continue; |
60 | 60 | } |
61 | - return Str::removePrefix('views/', $possibleView); |
|
61 | + return Str::removePrefix( 'views/', $possibleView ); |
|
62 | 62 | } |
63 | 63 | return $view; |
64 | 64 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function get() |
70 | 70 | { |
71 | - return apply_filters('site-reviews/style', $this->style); |
|
71 | + return apply_filters( 'site-reviews/style', $this->style ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,77 +77,77 @@ discard block |
||
77 | 77 | public function setConfig() |
78 | 78 | { |
79 | 79 | $config = shortcode_atts( |
80 | - array_fill_keys(['fields', 'pagination', 'validation'], []), |
|
81 | - glsr()->config('styles/'.$this->style) |
|
80 | + array_fill_keys( ['fields', 'pagination', 'validation'], [] ), |
|
81 | + glsr()->config( 'styles/'.$this->style ) |
|
82 | 82 | ); |
83 | - $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']); |
|
84 | - $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']); |
|
85 | - $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']); |
|
83 | + $this->fields = glsr( StyleFieldsDefaults::class )->restrict( $config['fields'] ); |
|
84 | + $this->pagination = glsr( PaginationDefaults::class )->restrict( $config['pagination'] ); |
|
85 | + $this->validation = glsr( StyleValidationDefaults::class )->restrict( $config['validation'] ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * @return void |
90 | 90 | */ |
91 | - public function modifyField(Builder $instance) |
|
91 | + public function modifyField( Builder $instance ) |
|
92 | 92 | { |
93 | - if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) { |
|
93 | + if( !$this->isPublicInstance( $instance ) || empty(array_filter( $this->fields )) ) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | - call_user_func_array([$this, 'customize'], [$instance]); |
|
96 | + call_user_func_array( [$this, 'customize'], [$instance] ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * @return array |
101 | 101 | */ |
102 | - public function paginationArgs(array $args) |
|
102 | + public function paginationArgs( array $args ) |
|
103 | 103 | { |
104 | - return wp_parse_args($args, $this->pagination); |
|
104 | + return wp_parse_args( $args, $this->pagination ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @return void |
109 | 109 | */ |
110 | - protected function customize(Builder $instance) |
|
110 | + protected function customize( Builder $instance ) |
|
111 | 111 | { |
112 | - if (!array_key_exists($instance->tag, $this->fields)) { |
|
112 | + if( !array_key_exists( $instance->tag, $this->fields ) ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | - $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], '')); |
|
115 | + $args = wp_parse_args( $instance->args, array_fill_keys( ['class', 'type'], '' ) ); |
|
116 | 116 | $key = $instance->tag.'_'.$args['type']; |
117 | - $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag)); |
|
118 | - $instance->args['class'] = trim($args['class'].' '.$classes); |
|
119 | - do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]); |
|
117 | + $classes = Arr::get( $this->fields, $key, Arr::get( $this->fields, $instance->tag ) ); |
|
118 | + $instance->args['class'] = trim( $args['class'].' '.$classes ); |
|
119 | + do_action_ref_array( 'site-reviews/customize/'.$this->style, [$instance] ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @param string $view |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - protected function generatePossibleViews($view) |
|
126 | + protected function generatePossibleViews( $view ) |
|
127 | 127 | { |
128 | - $basename = basename($view); |
|
129 | - $basepath = rtrim($view, $basename); |
|
128 | + $basename = basename( $view ); |
|
129 | + $basepath = rtrim( $view, $basename ); |
|
130 | 130 | $customPath = 'views/partials/styles/'.$this->style.'/'; |
131 | - $parts = explode('_', $basename); |
|
131 | + $parts = explode( '_', $basename ); |
|
132 | 132 | $views = [ |
133 | 133 | $customPath.$basename, |
134 | 134 | $customPath.$parts[0], |
135 | 135 | $view, |
136 | 136 | $basepath.$parts[0], |
137 | 137 | ]; |
138 | - return array_filter($views); |
|
138 | + return array_filter( $views ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @return bool |
143 | 143 | */ |
144 | - protected function isPublicInstance(Builder $instance) |
|
144 | + protected function isPublicInstance( Builder $instance ) |
|
145 | 145 | { |
146 | - $args = wp_parse_args($instance->args, [ |
|
146 | + $args = wp_parse_args( $instance->args, [ |
|
147 | 147 | 'is_public' => false, |
148 | 148 | 'is_raw' => false, |
149 | - ]); |
|
150 | - if (is_admin() || !$args['is_public'] || $args['is_raw']) { |
|
149 | + ] ); |
|
150 | + if( is_admin() || !$args['is_public'] || $args['is_raw'] ) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 | return true; |
@@ -10,135 +10,135 @@ |
||
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 bool |
|
46 | - */ |
|
47 | - public function run() |
|
48 | - { |
|
49 | - return $this->runMigrations($this->getNewMigrationFiles()); |
|
50 | - } |
|
44 | + /** |
|
45 | + * @return bool |
|
46 | + */ |
|
47 | + public function run() |
|
48 | + { |
|
49 | + return $this->runMigrations($this->getNewMigrationFiles()); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function runAll() |
|
56 | - { |
|
57 | - return $this->runMigrations($this->getMigrationFiles()); |
|
58 | - } |
|
52 | + /** |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function runAll() |
|
56 | + { |
|
57 | + return $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 bool |
|
115 | - */ |
|
116 | - protected function runMigrations(array $files) |
|
117 | - { |
|
118 | - if (empty($files)) { |
|
119 | - return false; |
|
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 | - return true; |
|
133 | - } |
|
113 | + /** |
|
114 | + * @return bool |
|
115 | + */ |
|
116 | + protected function runMigrations(array $files) |
|
117 | + { |
|
118 | + if (empty($files)) { |
|
119 | + return false; |
|
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 | + return true; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @param string $previousVersion |
|
137 | - * @return void |
|
138 | - */ |
|
139 | - protected function updateVersionFrom($previousVersion) |
|
140 | - { |
|
141 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
142 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
143 | - } |
|
135 | + /** |
|
136 | + * @param string $previousVersion |
|
137 | + * @return void |
|
138 | + */ |
|
139 | + protected function updateVersionFrom($previousVersion) |
|
140 | + { |
|
141 | + glsr(OptionManager::class)->set('version', glsr()->version); |
|
142 | + glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
143 | + } |
|
144 | 144 | } |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function isMigrationNeeded() |
33 | 33 | { |
34 | - $transient = get_transient($this->transientKey); |
|
35 | - if (false === $transient || !isset($transient[glsr()->version])) { |
|
34 | + $transient = get_transient( $this->transientKey ); |
|
35 | + if( false === $transient || !isset($transient[glsr()->version]) ) { |
|
36 | 36 | $transient = [ |
37 | 37 | glsr()->version => !empty($this->getNewMigrationFiles()), |
38 | 38 | ]; |
39 | - set_transient($this->transientKey, $transient); |
|
39 | + set_transient( $this->transientKey, $transient ); |
|
40 | 40 | } |
41 | - return Helper::castToBool($transient[glsr()->version]); |
|
41 | + return Helper::castToBool( $transient[glsr()->version] ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function run() |
48 | 48 | { |
49 | - return $this->runMigrations($this->getNewMigrationFiles()); |
|
49 | + return $this->runMigrations( $this->getNewMigrationFiles() ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function runAll() |
56 | 56 | { |
57 | - return $this->runMigrations($this->getMigrationFiles()); |
|
57 | + return $this->runMigrations( $this->getMigrationFiles() ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | { |
65 | 65 | $fallback = '0.0.0'; |
66 | 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)) { |
|
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 | 71 | return $version; |
72 | 72 | } |
73 | 73 | } |
@@ -80,15 +80,15 @@ discard block |
||
80 | 80 | protected function getMigrationFiles() |
81 | 81 | { |
82 | 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()) { |
|
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 | 88 | $files[] = $fileinfo->getFilename(); |
89 | 89 | } |
90 | 90 | } |
91 | - natsort($files); |
|
91 | + natsort( $files ); |
|
92 | 92 | } |
93 | 93 | return $files; |
94 | 94 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | protected function getNewMigrationFiles() |
100 | 100 | { |
101 | 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)) { |
|
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 | 107 | unset($files[$index]); |
108 | 108 | } |
109 | 109 | } |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * @return bool |
115 | 115 | */ |
116 | - protected function runMigrations(array $files) |
|
116 | + protected function runMigrations( array $files ) |
|
117 | 117 | { |
118 | - if (empty($files)) { |
|
118 | + if( empty($files) ) { |
|
119 | 119 | return false; |
120 | 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); |
|
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 | 126 | }); |
127 | - if ($this->currentVersion !== glsr()->version) { |
|
128 | - $this->updateVersionFrom($this->currentVersion); |
|
127 | + if( $this->currentVersion !== glsr()->version ) { |
|
128 | + $this->updateVersionFrom( $this->currentVersion ); |
|
129 | 129 | } |
130 | - glsr(OptionManager::class)->set('last_migration_run', current_time('timestamp')); |
|
131 | - delete_transient($this->transientKey); |
|
130 | + glsr( OptionManager::class )->set( 'last_migration_run', current_time( 'timestamp' ) ); |
|
131 | + delete_transient( $this->transientKey ); |
|
132 | 132 | return true; |
133 | 133 | } |
134 | 134 | |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | * @param string $previousVersion |
137 | 137 | * @return void |
138 | 138 | */ |
139 | - protected function updateVersionFrom($previousVersion) |
|
139 | + protected function updateVersionFrom( $previousVersion ) |
|
140 | 140 | { |
141 | - glsr(OptionManager::class)->set('version', glsr()->version); |
|
142 | - glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion); |
|
141 | + glsr( OptionManager::class )->set( 'version', glsr()->version ); |
|
142 | + glsr( OptionManager::class )->set( 'version_upgraded_from', $previousVersion ); |
|
143 | 143 | } |
144 | 144 | } |
@@ -10,437 +10,437 @@ |
||
10 | 10 | |
11 | 11 | class Console |
12 | 12 | { |
13 | - const DEBUG = 0; // Detailed debug information |
|
14 | - const INFO = 1; // Interesting events |
|
15 | - const NOTICE = 2; // Normal but significant events |
|
16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | - const CRITICAL = 16; // Critical conditions |
|
19 | - const ALERT = 32; // Action must be taken immediately |
|
20 | - const EMERGENCY = 64; // System is unusable |
|
21 | - |
|
22 | - protected $file; |
|
23 | - protected $log; |
|
24 | - protected $logOnceKey = 'glsr_log_once'; |
|
25 | - |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->file = glsr()->path('console.log'); |
|
29 | - $this->log = file_exists($this->file) |
|
30 | - ? file_get_contents($this->file) |
|
31 | - : ''; |
|
32 | - $this->reset(); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function __toString() |
|
39 | - { |
|
40 | - return $this->get(); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Action must be taken immediately |
|
45 | - * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up. |
|
46 | - * @param mixed $message |
|
47 | - * @param array $context |
|
48 | - * @return static |
|
49 | - */ |
|
50 | - public function alert($message, array $context = []) |
|
51 | - { |
|
52 | - return $this->log(static::ALERT, $message, $context); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function clear() |
|
59 | - { |
|
60 | - $this->log = ''; |
|
61 | - file_put_contents($this->file, $this->log); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Critical conditions |
|
66 | - * Example: Application component unavailable, unexpected exception. |
|
67 | - * @param mixed $message |
|
68 | - * @param array $context |
|
69 | - * @return static |
|
70 | - */ |
|
71 | - public function critical($message, array $context = []) |
|
72 | - { |
|
73 | - return $this->log(static::CRITICAL, $message, $context); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Detailed debug information. |
|
78 | - * @param mixed $message |
|
79 | - * @param array $context |
|
80 | - * @return static |
|
81 | - */ |
|
82 | - public function debug($message, array $context = []) |
|
83 | - { |
|
84 | - return $this->log(static::DEBUG, $message, $context); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * System is unusable. |
|
89 | - * @param mixed $message |
|
90 | - * @param array $context |
|
91 | - * @return static |
|
92 | - */ |
|
93 | - public function emergency($message, array $context = []) |
|
94 | - { |
|
95 | - return $this->log(static::EMERGENCY, $message, $context); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Runtime errors that do not require immediate action but should typically be logged and monitored. |
|
100 | - * @param mixed $message |
|
101 | - * @param array $context |
|
102 | - * @return static |
|
103 | - */ |
|
104 | - public function error($message, array $context = []) |
|
105 | - { |
|
106 | - return $this->log(static::ERROR, $message, $context); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function get() |
|
113 | - { |
|
114 | - return empty($this->log) |
|
115 | - ? __('Console is empty', 'site-reviews') |
|
116 | - : $this->log; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @return int |
|
121 | - */ |
|
122 | - public function getLevel() |
|
123 | - { |
|
124 | - return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function getLevels() |
|
131 | - { |
|
132 | - $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | - return array_map('strtolower', array_flip($constants)); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function humanLevel() |
|
140 | - { |
|
141 | - $level = $this->getLevel(); |
|
142 | - return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param string|null $valueIfEmpty |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function humanSize($valueIfEmpty = null) |
|
150 | - { |
|
151 | - $bytes = $this->size(); |
|
152 | - if (empty($bytes) && is_string($valueIfEmpty)) { |
|
153 | - return $valueIfEmpty; |
|
154 | - } |
|
155 | - $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | - return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Interesting events |
|
161 | - * Example: User logs in, SQL logs. |
|
162 | - * @param mixed $message |
|
163 | - * @param array $context |
|
164 | - * @return static |
|
165 | - */ |
|
166 | - public function info($message, array $context = []) |
|
167 | - { |
|
168 | - return $this->log(static::INFO, $message, $context); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param int $level |
|
173 | - * @param mixed $message |
|
174 | - * @param array $context |
|
175 | - * @param string $backtraceLine |
|
176 | - * @return static |
|
177 | - */ |
|
178 | - public function log($level, $message, $context = [], $backtraceLine = '') |
|
179 | - { |
|
180 | - if (empty($backtraceLine)) { |
|
181 | - $backtraceLine = $this->getBacktraceLine(); |
|
182 | - } |
|
183 | - if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | - $levelName = Arr::get($this->getLevels(), $level); |
|
185 | - $context = Arr::consolidate($context); |
|
186 | - $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | - $message = $this->interpolate($message, $context); |
|
188 | - $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | - file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | - apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
191 | - $this->reset(); |
|
192 | - } |
|
193 | - return $this; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @return void |
|
198 | - */ |
|
199 | - public function logOnce() |
|
200 | - { |
|
201 | - $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
202 | - $levels = $this->getLevels(); |
|
203 | - foreach ($once as $entry) { |
|
204 | - $levelName = Arr::get($entry, 'level'); |
|
205 | - if (!in_array($levelName, $levels)) { |
|
206 | - continue; |
|
207 | - } |
|
208 | - $level = Arr::get(array_flip($levels), $levelName); |
|
209 | - $message = Arr::get($entry, 'message'); |
|
210 | - $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | - $this->log($level, $message, [], $backtraceLine); |
|
212 | - } |
|
213 | - glsr()->{$this->logOnceKey} = []; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Normal but significant events. |
|
218 | - * @param mixed $message |
|
219 | - * @param array $context |
|
220 | - * @return static |
|
221 | - */ |
|
222 | - public function notice($message, array $context = []) |
|
223 | - { |
|
224 | - return $this->log(static::NOTICE, $message, $context); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param string $levelName |
|
229 | - * @param string $handle |
|
230 | - * @param mixed $data |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function once($levelName, $handle, $data) |
|
234 | - { |
|
235 | - $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
236 | - $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | - return Arr::get($entry, 'level') == $levelName |
|
238 | - && Arr::get($entry, 'handle') == $handle; |
|
239 | - }); |
|
240 | - if (!empty($filtered)) { |
|
241 | - return; |
|
242 | - } |
|
243 | - $once[] = [ |
|
244 | - 'backtrace' => $this->getBacktraceLineFromData($data), |
|
245 | - 'handle' => $handle, |
|
246 | - 'level' => $levelName, |
|
247 | - 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
248 | - ]; |
|
249 | - glsr()->{$this->logOnceKey} = $once; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * @return int |
|
254 | - */ |
|
255 | - public function size() |
|
256 | - { |
|
257 | - return file_exists($this->file) |
|
258 | - ? filesize($this->file) |
|
259 | - : 0; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Exceptional occurrences that are not errors |
|
264 | - * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong. |
|
265 | - * @param mixed $message |
|
266 | - * @param array $context |
|
267 | - * @return static |
|
268 | - */ |
|
269 | - public function warning($message, array $context = []) |
|
270 | - { |
|
271 | - return $this->log(static::WARNING, $message, $context); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * @param array $backtrace |
|
276 | - * @param int $index |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - protected function buildBacktraceLine($backtrace, $index) |
|
280 | - { |
|
281 | - return sprintf('%s:%s', |
|
282 | - Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | - Arr::get($backtrace, $index.'.line') |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @param string $levelName |
|
289 | - * @param mixed $message |
|
290 | - * @param string $backtraceLine |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
294 | - { |
|
295 | - return sprintf('[%s] %s [%s] %s', |
|
296 | - current_time('mysql'), |
|
297 | - strtoupper($levelName), |
|
298 | - $backtraceLine, |
|
299 | - $message |
|
300 | - ); |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * @param int $level |
|
305 | - * @return bool |
|
306 | - */ |
|
307 | - protected function canLogEntry($level, $backtraceLine) |
|
308 | - { |
|
309 | - $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | - if (!Str::contains($backtraceLine, glsr()->path())) { |
|
311 | - return $levelExists; // ignore level restriction if triggered outside of the plugin |
|
312 | - } |
|
313 | - return $levelExists && $level >= $this->getLevel(); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * @return void|string |
|
318 | - */ |
|
319 | - protected function getBacktraceLine() |
|
320 | - { |
|
321 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | - $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | - if (false !== $search) { |
|
324 | - return $this->buildBacktraceLine($backtrace, (int) $search); |
|
325 | - } |
|
326 | - $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | - if (false !== $search) { |
|
328 | - $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
329 | - ? $search + 4 |
|
330 | - : $search + 1; |
|
331 | - return $this->buildBacktraceLine($backtrace, $index); |
|
332 | - } |
|
333 | - return 'Unknown'; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * @param mixed $data |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - protected function getBacktraceLineFromData($data) |
|
341 | - { |
|
342 | - $backtrace = $data instanceof Throwable |
|
343 | - ? $data->getTrace() |
|
344 | - : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | - return $this->buildBacktraceLine($backtrace, 0); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * @param mixed $data |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - protected function getMessageFromData($data) |
|
353 | - { |
|
354 | - return $data instanceof Throwable |
|
355 | - ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | - : print_r($data, 1); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Interpolates context values into the message placeholders. |
|
361 | - * @param mixed $message |
|
362 | - * @param array $context |
|
363 | - * @return string |
|
364 | - */ |
|
365 | - protected function interpolate($message, $context = []) |
|
366 | - { |
|
367 | - if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | - return print_r($message, true); |
|
369 | - } |
|
370 | - $replace = []; |
|
371 | - foreach ($context as $key => $value) { |
|
372 | - $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
373 | - } |
|
374 | - return strtr($message, $replace); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $value |
|
379 | - * @return bool |
|
380 | - */ |
|
381 | - protected function isObjectOrArray($value) |
|
382 | - { |
|
383 | - return is_object($value) || is_array($value); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * @param string $backtraceLine |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - protected function normalizeBacktraceLine($backtraceLine) |
|
391 | - { |
|
392 | - $search = [ |
|
393 | - glsr()->path('plugin/'), |
|
394 | - glsr()->path('plugin/', false), |
|
395 | - trailingslashit(glsr()->path()), |
|
396 | - trailingslashit(glsr()->path('', false)), |
|
397 | - WP_CONTENT_DIR, |
|
398 | - ABSPATH, |
|
399 | - ]; |
|
400 | - return str_replace(array_unique($search), '', $backtraceLine); |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * @param string $message |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - protected function normalizeThrowableMessage($message) |
|
408 | - { |
|
409 | - $calledIn = strpos($message, ', called in'); |
|
410 | - return false !== $calledIn |
|
411 | - ? substr($message, 0, $calledIn) |
|
412 | - : $message; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * @param mixed $value |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - protected function normalizeValue($value) |
|
420 | - { |
|
421 | - if ($value instanceof DateTime) { |
|
422 | - $value = $value->format('Y-m-d H:i:s'); |
|
423 | - } elseif ($this->isObjectOrArray($value)) { |
|
424 | - $value = json_encode($value); |
|
425 | - } |
|
426 | - return (string) $value; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * @return void |
|
431 | - */ |
|
432 | - protected function reset() |
|
433 | - { |
|
434 | - if ($this->size() <= pow(1024, 2) / 8) { |
|
435 | - return; |
|
436 | - } |
|
437 | - $this->clear(); |
|
438 | - file_put_contents( |
|
439 | - $this->file, |
|
440 | - $this->buildLogEntry( |
|
441 | - static::NOTICE, |
|
442 | - __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
443 | - ) |
|
444 | - ); |
|
445 | - } |
|
13 | + const DEBUG = 0; // Detailed debug information |
|
14 | + const INFO = 1; // Interesting events |
|
15 | + const NOTICE = 2; // Normal but significant events |
|
16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | + const CRITICAL = 16; // Critical conditions |
|
19 | + const ALERT = 32; // Action must be taken immediately |
|
20 | + const EMERGENCY = 64; // System is unusable |
|
21 | + |
|
22 | + protected $file; |
|
23 | + protected $log; |
|
24 | + protected $logOnceKey = 'glsr_log_once'; |
|
25 | + |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->file = glsr()->path('console.log'); |
|
29 | + $this->log = file_exists($this->file) |
|
30 | + ? file_get_contents($this->file) |
|
31 | + : ''; |
|
32 | + $this->reset(); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function __toString() |
|
39 | + { |
|
40 | + return $this->get(); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Action must be taken immediately |
|
45 | + * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up. |
|
46 | + * @param mixed $message |
|
47 | + * @param array $context |
|
48 | + * @return static |
|
49 | + */ |
|
50 | + public function alert($message, array $context = []) |
|
51 | + { |
|
52 | + return $this->log(static::ALERT, $message, $context); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function clear() |
|
59 | + { |
|
60 | + $this->log = ''; |
|
61 | + file_put_contents($this->file, $this->log); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Critical conditions |
|
66 | + * Example: Application component unavailable, unexpected exception. |
|
67 | + * @param mixed $message |
|
68 | + * @param array $context |
|
69 | + * @return static |
|
70 | + */ |
|
71 | + public function critical($message, array $context = []) |
|
72 | + { |
|
73 | + return $this->log(static::CRITICAL, $message, $context); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Detailed debug information. |
|
78 | + * @param mixed $message |
|
79 | + * @param array $context |
|
80 | + * @return static |
|
81 | + */ |
|
82 | + public function debug($message, array $context = []) |
|
83 | + { |
|
84 | + return $this->log(static::DEBUG, $message, $context); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * System is unusable. |
|
89 | + * @param mixed $message |
|
90 | + * @param array $context |
|
91 | + * @return static |
|
92 | + */ |
|
93 | + public function emergency($message, array $context = []) |
|
94 | + { |
|
95 | + return $this->log(static::EMERGENCY, $message, $context); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Runtime errors that do not require immediate action but should typically be logged and monitored. |
|
100 | + * @param mixed $message |
|
101 | + * @param array $context |
|
102 | + * @return static |
|
103 | + */ |
|
104 | + public function error($message, array $context = []) |
|
105 | + { |
|
106 | + return $this->log(static::ERROR, $message, $context); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function get() |
|
113 | + { |
|
114 | + return empty($this->log) |
|
115 | + ? __('Console is empty', 'site-reviews') |
|
116 | + : $this->log; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @return int |
|
121 | + */ |
|
122 | + public function getLevel() |
|
123 | + { |
|
124 | + return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function getLevels() |
|
131 | + { |
|
132 | + $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | + return array_map('strtolower', array_flip($constants)); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function humanLevel() |
|
140 | + { |
|
141 | + $level = $this->getLevel(); |
|
142 | + return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param string|null $valueIfEmpty |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function humanSize($valueIfEmpty = null) |
|
150 | + { |
|
151 | + $bytes = $this->size(); |
|
152 | + if (empty($bytes) && is_string($valueIfEmpty)) { |
|
153 | + return $valueIfEmpty; |
|
154 | + } |
|
155 | + $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | + return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Interesting events |
|
161 | + * Example: User logs in, SQL logs. |
|
162 | + * @param mixed $message |
|
163 | + * @param array $context |
|
164 | + * @return static |
|
165 | + */ |
|
166 | + public function info($message, array $context = []) |
|
167 | + { |
|
168 | + return $this->log(static::INFO, $message, $context); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param int $level |
|
173 | + * @param mixed $message |
|
174 | + * @param array $context |
|
175 | + * @param string $backtraceLine |
|
176 | + * @return static |
|
177 | + */ |
|
178 | + public function log($level, $message, $context = [], $backtraceLine = '') |
|
179 | + { |
|
180 | + if (empty($backtraceLine)) { |
|
181 | + $backtraceLine = $this->getBacktraceLine(); |
|
182 | + } |
|
183 | + if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | + $levelName = Arr::get($this->getLevels(), $level); |
|
185 | + $context = Arr::consolidate($context); |
|
186 | + $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | + $message = $this->interpolate($message, $context); |
|
188 | + $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | + file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | + apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
191 | + $this->reset(); |
|
192 | + } |
|
193 | + return $this; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @return void |
|
198 | + */ |
|
199 | + public function logOnce() |
|
200 | + { |
|
201 | + $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
202 | + $levels = $this->getLevels(); |
|
203 | + foreach ($once as $entry) { |
|
204 | + $levelName = Arr::get($entry, 'level'); |
|
205 | + if (!in_array($levelName, $levels)) { |
|
206 | + continue; |
|
207 | + } |
|
208 | + $level = Arr::get(array_flip($levels), $levelName); |
|
209 | + $message = Arr::get($entry, 'message'); |
|
210 | + $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | + $this->log($level, $message, [], $backtraceLine); |
|
212 | + } |
|
213 | + glsr()->{$this->logOnceKey} = []; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Normal but significant events. |
|
218 | + * @param mixed $message |
|
219 | + * @param array $context |
|
220 | + * @return static |
|
221 | + */ |
|
222 | + public function notice($message, array $context = []) |
|
223 | + { |
|
224 | + return $this->log(static::NOTICE, $message, $context); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param string $levelName |
|
229 | + * @param string $handle |
|
230 | + * @param mixed $data |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function once($levelName, $handle, $data) |
|
234 | + { |
|
235 | + $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
236 | + $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | + return Arr::get($entry, 'level') == $levelName |
|
238 | + && Arr::get($entry, 'handle') == $handle; |
|
239 | + }); |
|
240 | + if (!empty($filtered)) { |
|
241 | + return; |
|
242 | + } |
|
243 | + $once[] = [ |
|
244 | + 'backtrace' => $this->getBacktraceLineFromData($data), |
|
245 | + 'handle' => $handle, |
|
246 | + 'level' => $levelName, |
|
247 | + 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
248 | + ]; |
|
249 | + glsr()->{$this->logOnceKey} = $once; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * @return int |
|
254 | + */ |
|
255 | + public function size() |
|
256 | + { |
|
257 | + return file_exists($this->file) |
|
258 | + ? filesize($this->file) |
|
259 | + : 0; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Exceptional occurrences that are not errors |
|
264 | + * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong. |
|
265 | + * @param mixed $message |
|
266 | + * @param array $context |
|
267 | + * @return static |
|
268 | + */ |
|
269 | + public function warning($message, array $context = []) |
|
270 | + { |
|
271 | + return $this->log(static::WARNING, $message, $context); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * @param array $backtrace |
|
276 | + * @param int $index |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + protected function buildBacktraceLine($backtrace, $index) |
|
280 | + { |
|
281 | + return sprintf('%s:%s', |
|
282 | + Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | + Arr::get($backtrace, $index.'.line') |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @param string $levelName |
|
289 | + * @param mixed $message |
|
290 | + * @param string $backtraceLine |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
294 | + { |
|
295 | + return sprintf('[%s] %s [%s] %s', |
|
296 | + current_time('mysql'), |
|
297 | + strtoupper($levelName), |
|
298 | + $backtraceLine, |
|
299 | + $message |
|
300 | + ); |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * @param int $level |
|
305 | + * @return bool |
|
306 | + */ |
|
307 | + protected function canLogEntry($level, $backtraceLine) |
|
308 | + { |
|
309 | + $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | + if (!Str::contains($backtraceLine, glsr()->path())) { |
|
311 | + return $levelExists; // ignore level restriction if triggered outside of the plugin |
|
312 | + } |
|
313 | + return $levelExists && $level >= $this->getLevel(); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * @return void|string |
|
318 | + */ |
|
319 | + protected function getBacktraceLine() |
|
320 | + { |
|
321 | + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | + $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | + if (false !== $search) { |
|
324 | + return $this->buildBacktraceLine($backtrace, (int) $search); |
|
325 | + } |
|
326 | + $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | + if (false !== $search) { |
|
328 | + $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
329 | + ? $search + 4 |
|
330 | + : $search + 1; |
|
331 | + return $this->buildBacktraceLine($backtrace, $index); |
|
332 | + } |
|
333 | + return 'Unknown'; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * @param mixed $data |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + protected function getBacktraceLineFromData($data) |
|
341 | + { |
|
342 | + $backtrace = $data instanceof Throwable |
|
343 | + ? $data->getTrace() |
|
344 | + : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | + return $this->buildBacktraceLine($backtrace, 0); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * @param mixed $data |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + protected function getMessageFromData($data) |
|
353 | + { |
|
354 | + return $data instanceof Throwable |
|
355 | + ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | + : print_r($data, 1); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Interpolates context values into the message placeholders. |
|
361 | + * @param mixed $message |
|
362 | + * @param array $context |
|
363 | + * @return string |
|
364 | + */ |
|
365 | + protected function interpolate($message, $context = []) |
|
366 | + { |
|
367 | + if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | + return print_r($message, true); |
|
369 | + } |
|
370 | + $replace = []; |
|
371 | + foreach ($context as $key => $value) { |
|
372 | + $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
373 | + } |
|
374 | + return strtr($message, $replace); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $value |
|
379 | + * @return bool |
|
380 | + */ |
|
381 | + protected function isObjectOrArray($value) |
|
382 | + { |
|
383 | + return is_object($value) || is_array($value); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * @param string $backtraceLine |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + protected function normalizeBacktraceLine($backtraceLine) |
|
391 | + { |
|
392 | + $search = [ |
|
393 | + glsr()->path('plugin/'), |
|
394 | + glsr()->path('plugin/', false), |
|
395 | + trailingslashit(glsr()->path()), |
|
396 | + trailingslashit(glsr()->path('', false)), |
|
397 | + WP_CONTENT_DIR, |
|
398 | + ABSPATH, |
|
399 | + ]; |
|
400 | + return str_replace(array_unique($search), '', $backtraceLine); |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * @param string $message |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + protected function normalizeThrowableMessage($message) |
|
408 | + { |
|
409 | + $calledIn = strpos($message, ', called in'); |
|
410 | + return false !== $calledIn |
|
411 | + ? substr($message, 0, $calledIn) |
|
412 | + : $message; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * @param mixed $value |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + protected function normalizeValue($value) |
|
420 | + { |
|
421 | + if ($value instanceof DateTime) { |
|
422 | + $value = $value->format('Y-m-d H:i:s'); |
|
423 | + } elseif ($this->isObjectOrArray($value)) { |
|
424 | + $value = json_encode($value); |
|
425 | + } |
|
426 | + return (string) $value; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * @return void |
|
431 | + */ |
|
432 | + protected function reset() |
|
433 | + { |
|
434 | + if ($this->size() <= pow(1024, 2) / 8) { |
|
435 | + return; |
|
436 | + } |
|
437 | + $this->clear(); |
|
438 | + file_put_contents( |
|
439 | + $this->file, |
|
440 | + $this->buildLogEntry( |
|
441 | + static::NOTICE, |
|
442 | + __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
443 | + ) |
|
444 | + ); |
|
445 | + } |
|
446 | 446 | } |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | |
11 | 11 | class Console |
12 | 12 | { |
13 | - const DEBUG = 0; // Detailed debug information |
|
14 | - const INFO = 1; // Interesting events |
|
15 | - const NOTICE = 2; // Normal but significant events |
|
16 | - const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | - const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | - const CRITICAL = 16; // Critical conditions |
|
19 | - const ALERT = 32; // Action must be taken immediately |
|
13 | + const DEBUG = 0; // Detailed debug information |
|
14 | + const INFO = 1; // Interesting events |
|
15 | + const NOTICE = 2; // Normal but significant events |
|
16 | + const WARNING = 4; // Exceptional occurrences that are not errors |
|
17 | + const ERROR = 8; // Runtime errors that do not require immediate action |
|
18 | + const CRITICAL = 16; // Critical conditions |
|
19 | + const ALERT = 32; // Action must be taken immediately |
|
20 | 20 | const EMERGENCY = 64; // System is unusable |
21 | 21 | |
22 | 22 | protected $file; |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | |
26 | 26 | public function __construct() |
27 | 27 | { |
28 | - $this->file = glsr()->path('console.log'); |
|
29 | - $this->log = file_exists($this->file) |
|
30 | - ? file_get_contents($this->file) |
|
28 | + $this->file = glsr()->path( 'console.log' ); |
|
29 | + $this->log = file_exists( $this->file ) |
|
30 | + ? file_get_contents( $this->file ) |
|
31 | 31 | : ''; |
32 | 32 | $this->reset(); |
33 | 33 | } |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * @param array $context |
48 | 48 | * @return static |
49 | 49 | */ |
50 | - public function alert($message, array $context = []) |
|
50 | + public function alert( $message, array $context = [] ) |
|
51 | 51 | { |
52 | - return $this->log(static::ALERT, $message, $context); |
|
52 | + return $this->log( static::ALERT, $message, $context ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function clear() |
59 | 59 | { |
60 | 60 | $this->log = ''; |
61 | - file_put_contents($this->file, $this->log); |
|
61 | + file_put_contents( $this->file, $this->log ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @param array $context |
69 | 69 | * @return static |
70 | 70 | */ |
71 | - public function critical($message, array $context = []) |
|
71 | + public function critical( $message, array $context = [] ) |
|
72 | 72 | { |
73 | - return $this->log(static::CRITICAL, $message, $context); |
|
73 | + return $this->log( static::CRITICAL, $message, $context ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * @param array $context |
80 | 80 | * @return static |
81 | 81 | */ |
82 | - public function debug($message, array $context = []) |
|
82 | + public function debug( $message, array $context = [] ) |
|
83 | 83 | { |
84 | - return $this->log(static::DEBUG, $message, $context); |
|
84 | + return $this->log( static::DEBUG, $message, $context ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | * @param array $context |
91 | 91 | * @return static |
92 | 92 | */ |
93 | - public function emergency($message, array $context = []) |
|
93 | + public function emergency( $message, array $context = [] ) |
|
94 | 94 | { |
95 | - return $this->log(static::EMERGENCY, $message, $context); |
|
95 | + return $this->log( static::EMERGENCY, $message, $context ); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param array $context |
102 | 102 | * @return static |
103 | 103 | */ |
104 | - public function error($message, array $context = []) |
|
104 | + public function error( $message, array $context = [] ) |
|
105 | 105 | { |
106 | - return $this->log(static::ERROR, $message, $context); |
|
106 | + return $this->log( static::ERROR, $message, $context ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function get() |
113 | 113 | { |
114 | 114 | return empty($this->log) |
115 | - ? __('Console is empty', 'site-reviews') |
|
115 | + ? __( 'Console is empty', 'site-reviews' ) |
|
116 | 116 | : $this->log; |
117 | 117 | } |
118 | 118 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function getLevel() |
123 | 123 | { |
124 | - return intval(apply_filters('site-reviews/console/level', static::INFO)); |
|
124 | + return intval( apply_filters( 'site-reviews/console/level', static::INFO ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function getLevels() |
131 | 131 | { |
132 | - $constants = (new ReflectionClass(__CLASS__))->getConstants(); |
|
133 | - return array_map('strtolower', array_flip($constants)); |
|
132 | + $constants = (new ReflectionClass( __CLASS__ ))->getConstants(); |
|
133 | + return array_map( 'strtolower', array_flip( $constants ) ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,21 +139,21 @@ discard block |
||
139 | 139 | public function humanLevel() |
140 | 140 | { |
141 | 141 | $level = $this->getLevel(); |
142 | - return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level); |
|
142 | + return sprintf( '%s (%d)', strtoupper( Arr::get( $this->getLevels(), $level, 'unknown' ) ), $level ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @param string|null $valueIfEmpty |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - public function humanSize($valueIfEmpty = null) |
|
149 | + public function humanSize( $valueIfEmpty = null ) |
|
150 | 150 | { |
151 | 151 | $bytes = $this->size(); |
152 | - if (empty($bytes) && is_string($valueIfEmpty)) { |
|
152 | + if( empty($bytes) && is_string( $valueIfEmpty ) ) { |
|
153 | 153 | return $valueIfEmpty; |
154 | 154 | } |
155 | - $exponent = floor(log(max($bytes, 1), 1024)); |
|
156 | - return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
155 | + $exponent = floor( log( max( $bytes, 1 ), 1024 ) ); |
|
156 | + return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @param array $context |
164 | 164 | * @return static |
165 | 165 | */ |
166 | - public function info($message, array $context = []) |
|
166 | + public function info( $message, array $context = [] ) |
|
167 | 167 | { |
168 | - return $this->log(static::INFO, $message, $context); |
|
168 | + return $this->log( static::INFO, $message, $context ); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -175,19 +175,19 @@ discard block |
||
175 | 175 | * @param string $backtraceLine |
176 | 176 | * @return static |
177 | 177 | */ |
178 | - public function log($level, $message, $context = [], $backtraceLine = '') |
|
178 | + public function log( $level, $message, $context = [], $backtraceLine = '' ) |
|
179 | 179 | { |
180 | - if (empty($backtraceLine)) { |
|
180 | + if( empty($backtraceLine) ) { |
|
181 | 181 | $backtraceLine = $this->getBacktraceLine(); |
182 | 182 | } |
183 | - if ($this->canLogEntry($level, $backtraceLine)) { |
|
184 | - $levelName = Arr::get($this->getLevels(), $level); |
|
185 | - $context = Arr::consolidate($context); |
|
186 | - $backtraceLine = $this->normalizeBacktraceLine($backtraceLine); |
|
187 | - $message = $this->interpolate($message, $context); |
|
188 | - $entry = $this->buildLogEntry($levelName, $message, $backtraceLine); |
|
189 | - file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX); |
|
190 | - apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed |
|
183 | + if( $this->canLogEntry( $level, $backtraceLine ) ) { |
|
184 | + $levelName = Arr::get( $this->getLevels(), $level ); |
|
185 | + $context = Arr::consolidate( $context ); |
|
186 | + $backtraceLine = $this->normalizeBacktraceLine( $backtraceLine ); |
|
187 | + $message = $this->interpolate( $message, $context ); |
|
188 | + $entry = $this->buildLogEntry( $levelName, $message, $backtraceLine ); |
|
189 | + file_put_contents( $this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX ); |
|
190 | + apply_filters( 'console', $message, $levelName, $backtraceLine ); // Show in Blackbar plugin if installed |
|
191 | 191 | $this->reset(); |
192 | 192 | } |
193 | 193 | return $this; |
@@ -198,17 +198,17 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function logOnce() |
200 | 200 | { |
201 | - $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
201 | + $once = Arr::consolidate( glsr()->{$this->logOnceKey}); |
|
202 | 202 | $levels = $this->getLevels(); |
203 | - foreach ($once as $entry) { |
|
204 | - $levelName = Arr::get($entry, 'level'); |
|
205 | - if (!in_array($levelName, $levels)) { |
|
203 | + foreach( $once as $entry ) { |
|
204 | + $levelName = Arr::get( $entry, 'level' ); |
|
205 | + if( !in_array( $levelName, $levels ) ) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | - $level = Arr::get(array_flip($levels), $levelName); |
|
209 | - $message = Arr::get($entry, 'message'); |
|
210 | - $backtraceLine = Arr::get($entry, 'backtrace'); |
|
211 | - $this->log($level, $message, [], $backtraceLine); |
|
208 | + $level = Arr::get( array_flip( $levels ), $levelName ); |
|
209 | + $message = Arr::get( $entry, 'message' ); |
|
210 | + $backtraceLine = Arr::get( $entry, 'backtrace' ); |
|
211 | + $this->log( $level, $message, [], $backtraceLine ); |
|
212 | 212 | } |
213 | 213 | glsr()->{$this->logOnceKey} = []; |
214 | 214 | } |
@@ -219,9 +219,9 @@ discard block |
||
219 | 219 | * @param array $context |
220 | 220 | * @return static |
221 | 221 | */ |
222 | - public function notice($message, array $context = []) |
|
222 | + public function notice( $message, array $context = [] ) |
|
223 | 223 | { |
224 | - return $this->log(static::NOTICE, $message, $context); |
|
224 | + return $this->log( static::NOTICE, $message, $context ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -230,21 +230,21 @@ discard block |
||
230 | 230 | * @param mixed $data |
231 | 231 | * @return void |
232 | 232 | */ |
233 | - public function once($levelName, $handle, $data) |
|
233 | + public function once( $levelName, $handle, $data ) |
|
234 | 234 | { |
235 | - $once = Arr::consolidate(glsr()->{$this->logOnceKey}); |
|
236 | - $filtered = array_filter($once, function ($entry) use ($levelName, $handle) { |
|
237 | - return Arr::get($entry, 'level') == $levelName |
|
238 | - && Arr::get($entry, 'handle') == $handle; |
|
235 | + $once = Arr::consolidate( glsr()->{$this->logOnceKey}); |
|
236 | + $filtered = array_filter( $once, function( $entry ) use ($levelName, $handle) { |
|
237 | + return Arr::get( $entry, 'level' ) == $levelName |
|
238 | + && Arr::get( $entry, 'handle' ) == $handle; |
|
239 | 239 | }); |
240 | - if (!empty($filtered)) { |
|
240 | + if( !empty($filtered) ) { |
|
241 | 241 | return; |
242 | 242 | } |
243 | 243 | $once[] = [ |
244 | - 'backtrace' => $this->getBacktraceLineFromData($data), |
|
244 | + 'backtrace' => $this->getBacktraceLineFromData( $data ), |
|
245 | 245 | 'handle' => $handle, |
246 | 246 | 'level' => $levelName, |
247 | - 'message' => '[RECURRING] '.$this->getMessageFromData($data), |
|
247 | + 'message' => '[RECURRING] '.$this->getMessageFromData( $data ), |
|
248 | 248 | ]; |
249 | 249 | glsr()->{$this->logOnceKey} = $once; |
250 | 250 | } |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function size() |
256 | 256 | { |
257 | - return file_exists($this->file) |
|
258 | - ? filesize($this->file) |
|
257 | + return file_exists( $this->file ) |
|
258 | + ? filesize( $this->file ) |
|
259 | 259 | : 0; |
260 | 260 | } |
261 | 261 | |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | * @param array $context |
267 | 267 | * @return static |
268 | 268 | */ |
269 | - public function warning($message, array $context = []) |
|
269 | + public function warning( $message, array $context = [] ) |
|
270 | 270 | { |
271 | - return $this->log(static::WARNING, $message, $context); |
|
271 | + return $this->log( static::WARNING, $message, $context ); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * @param int $index |
277 | 277 | * @return string |
278 | 278 | */ |
279 | - protected function buildBacktraceLine($backtrace, $index) |
|
279 | + protected function buildBacktraceLine( $backtrace, $index ) |
|
280 | 280 | { |
281 | - return sprintf('%s:%s', |
|
282 | - Arr::get($backtrace, $index.'.file'), // realpath |
|
283 | - Arr::get($backtrace, $index.'.line') |
|
281 | + return sprintf( '%s:%s', |
|
282 | + Arr::get( $backtrace, $index.'.file' ), // realpath |
|
283 | + Arr::get( $backtrace, $index.'.line' ) |
|
284 | 284 | ); |
285 | 285 | } |
286 | 286 | |
@@ -290,11 +290,11 @@ discard block |
||
290 | 290 | * @param string $backtraceLine |
291 | 291 | * @return string |
292 | 292 | */ |
293 | - protected function buildLogEntry($levelName, $message, $backtraceLine = '') |
|
293 | + protected function buildLogEntry( $levelName, $message, $backtraceLine = '' ) |
|
294 | 294 | { |
295 | - return sprintf('[%s] %s [%s] %s', |
|
296 | - current_time('mysql'), |
|
297 | - strtoupper($levelName), |
|
295 | + return sprintf( '[%s] %s [%s] %s', |
|
296 | + current_time( 'mysql' ), |
|
297 | + strtoupper( $levelName ), |
|
298 | 298 | $backtraceLine, |
299 | 299 | $message |
300 | 300 | ); |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | * @param int $level |
305 | 305 | * @return bool |
306 | 306 | */ |
307 | - protected function canLogEntry($level, $backtraceLine) |
|
307 | + protected function canLogEntry( $level, $backtraceLine ) |
|
308 | 308 | { |
309 | - $levelExists = array_key_exists($level, $this->getLevels()); |
|
310 | - if (!Str::contains($backtraceLine, glsr()->path())) { |
|
309 | + $levelExists = array_key_exists( $level, $this->getLevels() ); |
|
310 | + if( !Str::contains( $backtraceLine, glsr()->path() ) ) { |
|
311 | 311 | return $levelExists; // ignore level restriction if triggered outside of the plugin |
312 | 312 | } |
313 | 313 | return $levelExists && $level >= $this->getLevel(); |
@@ -318,17 +318,17 @@ discard block |
||
318 | 318 | */ |
319 | 319 | protected function getBacktraceLine() |
320 | 320 | { |
321 | - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6); |
|
322 | - $search = array_search('glsr_log', glsr_array_column($backtrace, 'function')); |
|
323 | - if (false !== $search) { |
|
324 | - return $this->buildBacktraceLine($backtrace, (int) $search); |
|
321 | + $backtrace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 6 ); |
|
322 | + $search = array_search( 'glsr_log', glsr_array_column( $backtrace, 'function' ) ); |
|
323 | + if( false !== $search ) { |
|
324 | + return $this->buildBacktraceLine( $backtrace, (int)$search ); |
|
325 | 325 | } |
326 | - $search = array_search('log', glsr_array_column($backtrace, 'function')); |
|
327 | - if (false !== $search) { |
|
328 | - $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function') |
|
326 | + $search = array_search( 'log', glsr_array_column( $backtrace, 'function' ) ); |
|
327 | + if( false !== $search ) { |
|
328 | + $index = '{closure}' == Arr::get( $backtrace, ($search + 2).'.function' ) |
|
329 | 329 | ? $search + 4 |
330 | 330 | : $search + 1; |
331 | - return $this->buildBacktraceLine($backtrace, $index); |
|
331 | + return $this->buildBacktraceLine( $backtrace, $index ); |
|
332 | 332 | } |
333 | 333 | return 'Unknown'; |
334 | 334 | } |
@@ -337,23 +337,23 @@ discard block |
||
337 | 337 | * @param mixed $data |
338 | 338 | * @return string |
339 | 339 | */ |
340 | - protected function getBacktraceLineFromData($data) |
|
340 | + protected function getBacktraceLineFromData( $data ) |
|
341 | 341 | { |
342 | 342 | $backtrace = $data instanceof Throwable |
343 | 343 | ? $data->getTrace() |
344 | - : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); |
|
345 | - return $this->buildBacktraceLine($backtrace, 0); |
|
344 | + : debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 ); |
|
345 | + return $this->buildBacktraceLine( $backtrace, 0 ); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
349 | 349 | * @param mixed $data |
350 | 350 | * @return string |
351 | 351 | */ |
352 | - protected function getMessageFromData($data) |
|
352 | + protected function getMessageFromData( $data ) |
|
353 | 353 | { |
354 | 354 | return $data instanceof Throwable |
355 | - ? $this->normalizeThrowableMessage($data->getMessage()) |
|
356 | - : print_r($data, 1); |
|
355 | + ? $this->normalizeThrowableMessage( $data->getMessage() ) |
|
356 | + : print_r( $data, 1 ); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -362,53 +362,53 @@ discard block |
||
362 | 362 | * @param array $context |
363 | 363 | * @return string |
364 | 364 | */ |
365 | - protected function interpolate($message, $context = []) |
|
365 | + protected function interpolate( $message, $context = [] ) |
|
366 | 366 | { |
367 | - if ($this->isObjectOrArray($message) || !is_array($context)) { |
|
368 | - return print_r($message, true); |
|
367 | + if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) { |
|
368 | + return print_r( $message, true ); |
|
369 | 369 | } |
370 | 370 | $replace = []; |
371 | - foreach ($context as $key => $value) { |
|
372 | - $replace['{'.$key.'}'] = $this->normalizeValue($value); |
|
371 | + foreach( $context as $key => $value ) { |
|
372 | + $replace['{'.$key.'}'] = $this->normalizeValue( $value ); |
|
373 | 373 | } |
374 | - return strtr($message, $replace); |
|
374 | + return strtr( $message, $replace ); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
378 | 378 | * @param mixed $value |
379 | 379 | * @return bool |
380 | 380 | */ |
381 | - protected function isObjectOrArray($value) |
|
381 | + protected function isObjectOrArray( $value ) |
|
382 | 382 | { |
383 | - return is_object($value) || is_array($value); |
|
383 | + return is_object( $value ) || is_array( $value ); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
387 | 387 | * @param string $backtraceLine |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - protected function normalizeBacktraceLine($backtraceLine) |
|
390 | + protected function normalizeBacktraceLine( $backtraceLine ) |
|
391 | 391 | { |
392 | 392 | $search = [ |
393 | - glsr()->path('plugin/'), |
|
394 | - glsr()->path('plugin/', false), |
|
395 | - trailingslashit(glsr()->path()), |
|
396 | - trailingslashit(glsr()->path('', false)), |
|
393 | + glsr()->path( 'plugin/' ), |
|
394 | + glsr()->path( 'plugin/', false ), |
|
395 | + trailingslashit( glsr()->path() ), |
|
396 | + trailingslashit( glsr()->path( '', false ) ), |
|
397 | 397 | WP_CONTENT_DIR, |
398 | 398 | ABSPATH, |
399 | 399 | ]; |
400 | - return str_replace(array_unique($search), '', $backtraceLine); |
|
400 | + return str_replace( array_unique( $search ), '', $backtraceLine ); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | /** |
404 | 404 | * @param string $message |
405 | 405 | * @return string |
406 | 406 | */ |
407 | - protected function normalizeThrowableMessage($message) |
|
407 | + protected function normalizeThrowableMessage( $message ) |
|
408 | 408 | { |
409 | - $calledIn = strpos($message, ', called in'); |
|
409 | + $calledIn = strpos( $message, ', called in' ); |
|
410 | 410 | return false !== $calledIn |
411 | - ? substr($message, 0, $calledIn) |
|
411 | + ? substr( $message, 0, $calledIn ) |
|
412 | 412 | : $message; |
413 | 413 | } |
414 | 414 | |
@@ -416,14 +416,14 @@ discard block |
||
416 | 416 | * @param mixed $value |
417 | 417 | * @return string |
418 | 418 | */ |
419 | - protected function normalizeValue($value) |
|
419 | + protected function normalizeValue( $value ) |
|
420 | 420 | { |
421 | - if ($value instanceof DateTime) { |
|
422 | - $value = $value->format('Y-m-d H:i:s'); |
|
423 | - } elseif ($this->isObjectOrArray($value)) { |
|
424 | - $value = json_encode($value); |
|
421 | + if( $value instanceof DateTime ) { |
|
422 | + $value = $value->format( 'Y-m-d H:i:s' ); |
|
423 | + } elseif( $this->isObjectOrArray( $value ) ) { |
|
424 | + $value = json_encode( $value ); |
|
425 | 425 | } |
426 | - return (string) $value; |
|
426 | + return (string)$value; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | */ |
432 | 432 | protected function reset() |
433 | 433 | { |
434 | - if ($this->size() <= pow(1024, 2) / 8) { |
|
434 | + if( $this->size() <= pow( 1024, 2 ) / 8 ) { |
|
435 | 435 | return; |
436 | 436 | } |
437 | 437 | $this->clear(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | $this->file, |
440 | 440 | $this->buildLogEntry( |
441 | 441 | static::NOTICE, |
442 | - __('Console was automatically cleared (128 KB maximum size)', 'site-reviews') |
|
442 | + __( 'Console was automatically cleared (128 KB maximum size)', 'site-reviews' ) |
|
443 | 443 | ) |
444 | 444 | ); |
445 | 445 | } |
@@ -18,357 +18,357 @@ |
||
18 | 18 | */ |
19 | 19 | final class Application extends Container |
20 | 20 | { |
21 | - const CAPABILITY = 'edit_others_posts'; |
|
22 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
23 | - const ID = 'site-reviews'; |
|
24 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
25 | - const POST_TYPE = 'site-review'; |
|
26 | - const PREFIX = 'glsr_'; |
|
27 | - const TAXONOMY = 'site-review-category'; |
|
21 | + const CAPABILITY = 'edit_others_posts'; |
|
22 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
23 | + const ID = 'site-reviews'; |
|
24 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
25 | + const POST_TYPE = 'site-review'; |
|
26 | + const PREFIX = 'glsr_'; |
|
27 | + const TAXONOMY = 'site-review-category'; |
|
28 | 28 | |
29 | - public $addons = []; |
|
30 | - public $defaults; |
|
31 | - public $deprecated = []; |
|
32 | - public $file; |
|
33 | - public $languages; |
|
34 | - public $mceShortcodes = []; //defined elsewhere |
|
35 | - public $name; |
|
36 | - public $postTypeColumns = []; // defined elsewhere |
|
37 | - public $reviewTypes; |
|
38 | - public $schemas = []; //defined elsewhere |
|
39 | - public $version; |
|
29 | + public $addons = []; |
|
30 | + public $defaults; |
|
31 | + public $deprecated = []; |
|
32 | + public $file; |
|
33 | + public $languages; |
|
34 | + public $mceShortcodes = []; //defined elsewhere |
|
35 | + public $name; |
|
36 | + public $postTypeColumns = []; // defined elsewhere |
|
37 | + public $reviewTypes; |
|
38 | + public $schemas = []; //defined elsewhere |
|
39 | + public $version; |
|
40 | 40 | |
41 | - public function __construct() |
|
42 | - { |
|
43 | - static::$instance = $this; |
|
44 | - $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName()); |
|
45 | - $plugin = get_file_data($this->file, [ |
|
46 | - 'languages' => 'Domain Path', |
|
47 | - 'name' => 'Plugin Name', |
|
48 | - 'version' => 'Version', |
|
49 | - ], 'plugin'); |
|
50 | - array_walk($plugin, function ($value, $key) { |
|
51 | - $this->$key = $value; |
|
52 | - }); |
|
53 | - } |
|
41 | + public function __construct() |
|
42 | + { |
|
43 | + static::$instance = $this; |
|
44 | + $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName()); |
|
45 | + $plugin = get_file_data($this->file, [ |
|
46 | + 'languages' => 'Domain Path', |
|
47 | + 'name' => 'Plugin Name', |
|
48 | + 'version' => 'Version', |
|
49 | + ], 'plugin'); |
|
50 | + array_walk($plugin, function ($value, $key) { |
|
51 | + $this->$key = $value; |
|
52 | + }); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function activate() |
|
59 | - { |
|
60 | - $this->scheduleCronJob(); |
|
61 | - add_option(static::ID.'activated', true); |
|
62 | - } |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function activate() |
|
59 | + { |
|
60 | + $this->scheduleCronJob(); |
|
61 | + add_option(static::ID.'activated', true); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param string $view |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function build($view, array $data = []) |
|
69 | - { |
|
70 | - ob_start(); |
|
71 | - $this->render($view, $data); |
|
72 | - return ob_get_clean(); |
|
73 | - } |
|
64 | + /** |
|
65 | + * @param string $view |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function build($view, array $data = []) |
|
69 | + { |
|
70 | + ob_start(); |
|
71 | + $this->render($view, $data); |
|
72 | + return ob_get_clean(); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param string $capability |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function can($capability) |
|
80 | - { |
|
81 | - return $this->make(Role::class)->can($capability); |
|
82 | - } |
|
75 | + /** |
|
76 | + * @param string $capability |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function can($capability) |
|
80 | + { |
|
81 | + return $this->make(Role::class)->can($capability); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function catchFatalError() |
|
88 | - { |
|
89 | - $error = error_get_last(); |
|
90 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
91 | - return; |
|
92 | - } |
|
93 | - glsr_log()->error($error['message']); |
|
94 | - } |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function catchFatalError() |
|
88 | + { |
|
89 | + $error = error_get_last(); |
|
90 | + if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
91 | + return; |
|
92 | + } |
|
93 | + glsr_log()->error($error['message']); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @param string $name |
|
98 | - * @return array |
|
99 | - */ |
|
100 | - public function config($name) |
|
101 | - { |
|
102 | - $path = apply_filters('site-reviews/config', 'config/'.$name.'.php'); |
|
103 | - $configFile = $this->path($path); |
|
104 | - $config = file_exists($configFile) |
|
105 | - ? include $configFile |
|
106 | - : []; |
|
107 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
108 | - } |
|
96 | + /** |
|
97 | + * @param string $name |
|
98 | + * @return array |
|
99 | + */ |
|
100 | + public function config($name) |
|
101 | + { |
|
102 | + $path = apply_filters('site-reviews/config', 'config/'.$name.'.php'); |
|
103 | + $configFile = $this->path($path); |
|
104 | + $config = file_exists($configFile) |
|
105 | + ? include $configFile |
|
106 | + : []; |
|
107 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @param string $property |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function constant($property, $className = 'static') |
|
115 | - { |
|
116 | - $constant = $className.'::'.$property; |
|
117 | - return defined($constant) |
|
118 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
119 | - : ''; |
|
120 | - } |
|
110 | + /** |
|
111 | + * @param string $property |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function constant($property, $className = 'static') |
|
115 | + { |
|
116 | + $constant = $className.'::'.$property; |
|
117 | + return defined($constant) |
|
118 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
119 | + : ''; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function deactivate() |
|
126 | - { |
|
127 | - $this->unscheduleCronJob(); |
|
128 | - } |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function deactivate() |
|
126 | + { |
|
127 | + $this->unscheduleCronJob(); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @param string $view |
|
132 | - * @return void|string |
|
133 | - */ |
|
134 | - public function file($view) |
|
135 | - { |
|
136 | - $view.= '.php'; |
|
137 | - $filePaths = []; |
|
138 | - if (Str::startsWith('templates/', $view)) { |
|
139 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
140 | - } |
|
141 | - $filePaths[] = $this->path($view); |
|
142 | - $filePaths[] = $this->path('views/'.$view); |
|
143 | - foreach ($filePaths as $file) { |
|
144 | - if (!file_exists($file)) { |
|
145 | - continue; |
|
146 | - } |
|
147 | - return $file; |
|
148 | - } |
|
149 | - } |
|
130 | + /** |
|
131 | + * @param string $view |
|
132 | + * @return void|string |
|
133 | + */ |
|
134 | + public function file($view) |
|
135 | + { |
|
136 | + $view.= '.php'; |
|
137 | + $filePaths = []; |
|
138 | + if (Str::startsWith('templates/', $view)) { |
|
139 | + $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
140 | + } |
|
141 | + $filePaths[] = $this->path($view); |
|
142 | + $filePaths[] = $this->path('views/'.$view); |
|
143 | + foreach ($filePaths as $file) { |
|
144 | + if (!file_exists($file)) { |
|
145 | + continue; |
|
146 | + } |
|
147 | + return $file; |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public function getDefaults() |
|
155 | - { |
|
156 | - if (empty($this->defaults)) { |
|
157 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
158 | - } |
|
159 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
160 | - } |
|
151 | + /** |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public function getDefaults() |
|
155 | + { |
|
156 | + if (empty($this->defaults)) { |
|
157 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
158 | + } |
|
159 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @param string $page |
|
164 | - * @param string $tab |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function getPermission($page = '', $tab = 'index') |
|
168 | - { |
|
169 | - $fallback = 'edit_posts'; |
|
170 | - $permissions = [ |
|
171 | - 'addons' => 'install_plugins', |
|
172 | - 'documentation' => [ |
|
173 | - 'faq' => 'edit_others_posts', |
|
174 | - 'functions' => 'manage_options', |
|
175 | - 'hooks' => 'edit_others_posts', |
|
176 | - 'index' => 'edit_posts', |
|
177 | - 'support' => 'edit_others_posts', |
|
178 | - ], |
|
179 | - 'settings' => 'manage_options', |
|
180 | - 'tools' => [ |
|
181 | - 'console' => 'edit_others_posts', |
|
182 | - 'general' => 'edit_others_posts', |
|
183 | - 'index' => 'edit_others_posts', |
|
184 | - 'sync' => 'manage_options', |
|
185 | - 'system-info' => 'edit_others_posts', |
|
186 | - ] |
|
187 | - ]; |
|
188 | - $permission = Arr::get($permissions, $page, $fallback); |
|
189 | - if (is_array($permission)) { |
|
190 | - $permission = Arr::get($permission, $tab, $fallback); |
|
191 | - } |
|
192 | - return empty($permission) || !is_string($permission) |
|
193 | - ? $fallback |
|
194 | - : $permission; |
|
195 | - } |
|
162 | + /** |
|
163 | + * @param string $page |
|
164 | + * @param string $tab |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function getPermission($page = '', $tab = 'index') |
|
168 | + { |
|
169 | + $fallback = 'edit_posts'; |
|
170 | + $permissions = [ |
|
171 | + 'addons' => 'install_plugins', |
|
172 | + 'documentation' => [ |
|
173 | + 'faq' => 'edit_others_posts', |
|
174 | + 'functions' => 'manage_options', |
|
175 | + 'hooks' => 'edit_others_posts', |
|
176 | + 'index' => 'edit_posts', |
|
177 | + 'support' => 'edit_others_posts', |
|
178 | + ], |
|
179 | + 'settings' => 'manage_options', |
|
180 | + 'tools' => [ |
|
181 | + 'console' => 'edit_others_posts', |
|
182 | + 'general' => 'edit_others_posts', |
|
183 | + 'index' => 'edit_others_posts', |
|
184 | + 'sync' => 'manage_options', |
|
185 | + 'system-info' => 'edit_others_posts', |
|
186 | + ] |
|
187 | + ]; |
|
188 | + $permission = Arr::get($permissions, $page, $fallback); |
|
189 | + if (is_array($permission)) { |
|
190 | + $permission = Arr::get($permission, $tab, $fallback); |
|
191 | + } |
|
192 | + return empty($permission) || !is_string($permission) |
|
193 | + ? $fallback |
|
194 | + : $permission; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @param string $page |
|
199 | - * @param string $tab |
|
200 | - * @return bool |
|
201 | - */ |
|
202 | - public function hasPermission($page = '', $tab = 'index') |
|
203 | - { |
|
204 | - $isAdmin = $this->isAdmin(); |
|
205 | - return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
206 | - } |
|
197 | + /** |
|
198 | + * @param string $page |
|
199 | + * @param string $tab |
|
200 | + * @return bool |
|
201 | + */ |
|
202 | + public function hasPermission($page = '', $tab = 'index') |
|
203 | + { |
|
204 | + $isAdmin = $this->isAdmin(); |
|
205 | + return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public function init() |
|
212 | - { |
|
213 | - $this->make(Actions::class)->run(); |
|
214 | - $this->make(Filters::class)->run(); |
|
215 | - } |
|
208 | + /** |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public function init() |
|
212 | + { |
|
213 | + $this->make(Actions::class)->run(); |
|
214 | + $this->make(Filters::class)->run(); |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @return bool |
|
219 | - */ |
|
220 | - public function isAdmin() |
|
221 | - { |
|
222 | - return is_admin() && !wp_doing_ajax(); |
|
223 | - } |
|
217 | + /** |
|
218 | + * @return bool |
|
219 | + */ |
|
220 | + public function isAdmin() |
|
221 | + { |
|
222 | + return is_admin() && !wp_doing_ajax(); |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * @param string $file |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function path($file = '', $realpath = true) |
|
230 | - { |
|
231 | - $path = plugin_dir_path($this->file); |
|
232 | - if (!$realpath) { |
|
233 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
234 | - } |
|
235 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
236 | - return apply_filters('site-reviews/path', $path, $file); |
|
237 | - } |
|
225 | + /** |
|
226 | + * @param string $file |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function path($file = '', $realpath = true) |
|
230 | + { |
|
231 | + $path = plugin_dir_path($this->file); |
|
232 | + if (!$realpath) { |
|
233 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
234 | + } |
|
235 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
236 | + return apply_filters('site-reviews/path', $path, $file); |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * @param object $addon |
|
241 | - * @return void |
|
242 | - */ |
|
243 | - public function register($addon) |
|
244 | - { |
|
245 | - try { |
|
246 | - $reflection = new \ReflectionClass($addon); |
|
247 | - if ($id = $reflection->getConstant('ID')) { |
|
248 | - $this->addons[] = $id; |
|
249 | - $this->bind($id, $addon); |
|
250 | - $addon->init(); |
|
251 | - } |
|
252 | - } catch(\ReflectionException $e) { |
|
253 | - glsr_log()->error('Attempted to register an invalid addon.'); |
|
254 | - } |
|
255 | - } |
|
239 | + /** |
|
240 | + * @param object $addon |
|
241 | + * @return void |
|
242 | + */ |
|
243 | + public function register($addon) |
|
244 | + { |
|
245 | + try { |
|
246 | + $reflection = new \ReflectionClass($addon); |
|
247 | + if ($id = $reflection->getConstant('ID')) { |
|
248 | + $this->addons[] = $id; |
|
249 | + $this->bind($id, $addon); |
|
250 | + $addon->init(); |
|
251 | + } |
|
252 | + } catch(\ReflectionException $e) { |
|
253 | + glsr_log()->error('Attempted to register an invalid addon.'); |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * @return void |
|
259 | - */ |
|
260 | - public function registerAddons() |
|
261 | - { |
|
262 | - do_action('site-reviews/addon/register', $this); |
|
263 | - } |
|
257 | + /** |
|
258 | + * @return void |
|
259 | + */ |
|
260 | + public function registerAddons() |
|
261 | + { |
|
262 | + do_action('site-reviews/addon/register', $this); |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function registerLanguages() |
|
269 | - { |
|
270 | - load_plugin_textdomain(static::ID, false, |
|
271 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
272 | - ); |
|
273 | - } |
|
265 | + /** |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function registerLanguages() |
|
269 | + { |
|
270 | + load_plugin_textdomain(static::ID, false, |
|
271 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
272 | + ); |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * @return void |
|
277 | - */ |
|
278 | - public function registerReviewTypes() |
|
279 | - { |
|
280 | - $types = apply_filters('site-reviews/addon/types', []); |
|
281 | - $this->reviewTypes = wp_parse_args($types, [ |
|
282 | - 'local' => __('Local', 'site-reviews'), |
|
283 | - ]); |
|
284 | - } |
|
275 | + /** |
|
276 | + * @return void |
|
277 | + */ |
|
278 | + public function registerReviewTypes() |
|
279 | + { |
|
280 | + $types = apply_filters('site-reviews/addon/types', []); |
|
281 | + $this->reviewTypes = wp_parse_args($types, [ |
|
282 | + 'local' => __('Local', 'site-reviews'), |
|
283 | + ]); |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * @param string $view |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function render($view, array $data = []) |
|
291 | - { |
|
292 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
293 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
294 | - if (!file_exists($file)) { |
|
295 | - glsr_log()->error(sprintf('File not found: (%s) %s', $view, $file)); |
|
296 | - return; |
|
297 | - } |
|
298 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
299 | - extract($data); |
|
300 | - include $file; |
|
301 | - } |
|
286 | + /** |
|
287 | + * @param string $view |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function render($view, array $data = []) |
|
291 | + { |
|
292 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
293 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
294 | + if (!file_exists($file)) { |
|
295 | + glsr_log()->error(sprintf('File not found: (%s) %s', $view, $file)); |
|
296 | + return; |
|
297 | + } |
|
298 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
299 | + extract($data); |
|
300 | + include $file; |
|
301 | + } |
|
302 | 302 | |
303 | - /** |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - public function scheduleCronJob() |
|
307 | - { |
|
308 | - if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
309 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
310 | - } |
|
311 | - } |
|
303 | + /** |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + public function scheduleCronJob() |
|
307 | + { |
|
308 | + if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
309 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
310 | + } |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * @return void |
|
315 | - */ |
|
316 | - public function setDefaults() |
|
317 | - { |
|
318 | - if (get_option(static::ID.'activated')) { |
|
319 | - $this->make(DefaultsManager::class)->set(); |
|
320 | - delete_option(static::ID.'activated'); |
|
321 | - } |
|
322 | - } |
|
313 | + /** |
|
314 | + * @return void |
|
315 | + */ |
|
316 | + public function setDefaults() |
|
317 | + { |
|
318 | + if (get_option(static::ID.'activated')) { |
|
319 | + $this->make(DefaultsManager::class)->set(); |
|
320 | + delete_option(static::ID.'activated'); |
|
321 | + } |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * @param string $file |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - public function themePath($file = '') |
|
329 | - { |
|
330 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
331 | - } |
|
324 | + /** |
|
325 | + * @param string $file |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + public function themePath($file = '') |
|
329 | + { |
|
330 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
331 | + } |
|
332 | 332 | |
333 | - /** |
|
334 | - * @return void |
|
335 | - */ |
|
336 | - public function unscheduleCronJob() |
|
337 | - { |
|
338 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
339 | - } |
|
333 | + /** |
|
334 | + * @return void |
|
335 | + */ |
|
336 | + public function unscheduleCronJob() |
|
337 | + { |
|
338 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
339 | + } |
|
340 | 340 | |
341 | - /** |
|
342 | - * @param string $path |
|
343 | - * @return string |
|
344 | - */ |
|
345 | - public function url($path = '') |
|
346 | - { |
|
347 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
348 | - return apply_filters('site-reviews/url', $url, $path); |
|
349 | - } |
|
341 | + /** |
|
342 | + * @param string $path |
|
343 | + * @return string |
|
344 | + */ |
|
345 | + public function url($path = '') |
|
346 | + { |
|
347 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
348 | + return apply_filters('site-reviews/url', $url, $path); |
|
349 | + } |
|
350 | 350 | |
351 | - /** |
|
352 | - * @param string $versionLevel |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function version($versionLevel = '') |
|
356 | - { |
|
357 | - $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
358 | - preg_match($pattern, $this->version, $matches); |
|
359 | - switch ($versionLevel) { |
|
360 | - case 'major': |
|
361 | - $version = Arr::get($matches, 1); |
|
362 | - break; |
|
363 | - case 'minor': |
|
364 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
365 | - break; |
|
366 | - case 'patch': |
|
367 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
368 | - break; |
|
369 | - } |
|
370 | - return empty($version) |
|
371 | - ? $this->version |
|
372 | - : $version; |
|
373 | - } |
|
351 | + /** |
|
352 | + * @param string $versionLevel |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function version($versionLevel = '') |
|
356 | + { |
|
357 | + $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
358 | + preg_match($pattern, $this->version, $matches); |
|
359 | + switch ($versionLevel) { |
|
360 | + case 'major': |
|
361 | + $version = Arr::get($matches, 1); |
|
362 | + break; |
|
363 | + case 'minor': |
|
364 | + $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
365 | + break; |
|
366 | + case 'patch': |
|
367 | + $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
368 | + break; |
|
369 | + } |
|
370 | + return empty($version) |
|
371 | + ? $this->version |
|
372 | + : $version; |
|
373 | + } |
|
374 | 374 | } |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | public function __construct() |
42 | 42 | { |
43 | 43 | static::$instance = $this; |
44 | - $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName()); |
|
45 | - $plugin = get_file_data($this->file, [ |
|
44 | + $this->file = str_replace( 'plugin/Application', static::ID, (new ReflectionClass( $this ))->getFileName() ); |
|
45 | + $plugin = get_file_data( $this->file, [ |
|
46 | 46 | 'languages' => 'Domain Path', |
47 | 47 | 'name' => 'Plugin Name', |
48 | 48 | 'version' => 'Version', |
49 | - ], 'plugin'); |
|
50 | - array_walk($plugin, function ($value, $key) { |
|
49 | + ], 'plugin' ); |
|
50 | + array_walk( $plugin, function( $value, $key ) { |
|
51 | 51 | $this->$key = $value; |
52 | 52 | }); |
53 | 53 | } |
@@ -58,17 +58,17 @@ discard block |
||
58 | 58 | public function activate() |
59 | 59 | { |
60 | 60 | $this->scheduleCronJob(); |
61 | - add_option(static::ID.'activated', true); |
|
61 | + add_option( static::ID.'activated', true ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @param string $view |
66 | 66 | * @return string |
67 | 67 | */ |
68 | - public function build($view, array $data = []) |
|
68 | + public function build( $view, array $data = [] ) |
|
69 | 69 | { |
70 | 70 | ob_start(); |
71 | - $this->render($view, $data); |
|
71 | + $this->render( $view, $data ); |
|
72 | 72 | return ob_get_clean(); |
73 | 73 | } |
74 | 74 | |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * @param string $capability |
77 | 77 | * @return bool |
78 | 78 | */ |
79 | - public function can($capability) |
|
79 | + public function can( $capability ) |
|
80 | 80 | { |
81 | - return $this->make(Role::class)->can($capability); |
|
81 | + return $this->make( Role::class )->can( $capability ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -87,35 +87,35 @@ discard block |
||
87 | 87 | public function catchFatalError() |
88 | 88 | { |
89 | 89 | $error = error_get_last(); |
90 | - if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) { |
|
90 | + if( E_ERROR !== $error['type'] || !Str::contains( $error['message'], $this->path() ) ) { |
|
91 | 91 | return; |
92 | 92 | } |
93 | - glsr_log()->error($error['message']); |
|
93 | + glsr_log()->error( $error['message'] ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | 97 | * @param string $name |
98 | 98 | * @return array |
99 | 99 | */ |
100 | - public function config($name) |
|
100 | + public function config( $name ) |
|
101 | 101 | { |
102 | - $path = apply_filters('site-reviews/config', 'config/'.$name.'.php'); |
|
103 | - $configFile = $this->path($path); |
|
104 | - $config = file_exists($configFile) |
|
102 | + $path = apply_filters( 'site-reviews/config', 'config/'.$name.'.php' ); |
|
103 | + $configFile = $this->path( $path ); |
|
104 | + $config = file_exists( $configFile ) |
|
105 | 105 | ? include $configFile |
106 | 106 | : []; |
107 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
107 | + return apply_filters( 'site-reviews/config/'.$name, $config ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * @param string $property |
112 | 112 | * @return string |
113 | 113 | */ |
114 | - public function constant($property, $className = 'static') |
|
114 | + public function constant( $property, $className = 'static' ) |
|
115 | 115 | { |
116 | 116 | $constant = $className.'::'.$property; |
117 | - return defined($constant) |
|
118 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
117 | + return defined( $constant ) |
|
118 | + ? apply_filters( 'site-reviews/const/'.$property, constant( $constant ) ) |
|
119 | 119 | : ''; |
120 | 120 | } |
121 | 121 | |
@@ -131,17 +131,17 @@ discard block |
||
131 | 131 | * @param string $view |
132 | 132 | * @return void|string |
133 | 133 | */ |
134 | - public function file($view) |
|
134 | + public function file( $view ) |
|
135 | 135 | { |
136 | - $view.= '.php'; |
|
136 | + $view .= '.php'; |
|
137 | 137 | $filePaths = []; |
138 | - if (Str::startsWith('templates/', $view)) { |
|
139 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
138 | + if( Str::startsWith( 'templates/', $view ) ) { |
|
139 | + $filePaths[] = $this->themePath( Str::removePrefix( 'templates/', $view ) ); |
|
140 | 140 | } |
141 | - $filePaths[] = $this->path($view); |
|
142 | - $filePaths[] = $this->path('views/'.$view); |
|
143 | - foreach ($filePaths as $file) { |
|
144 | - if (!file_exists($file)) { |
|
141 | + $filePaths[] = $this->path( $view ); |
|
142 | + $filePaths[] = $this->path( 'views/'.$view ); |
|
143 | + foreach( $filePaths as $file ) { |
|
144 | + if( !file_exists( $file ) ) { |
|
145 | 145 | continue; |
146 | 146 | } |
147 | 147 | return $file; |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function getDefaults() |
155 | 155 | { |
156 | - if (empty($this->defaults)) { |
|
157 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
156 | + if( empty($this->defaults) ) { |
|
157 | + $this->defaults = $this->make( DefaultsManager::class )->get(); |
|
158 | 158 | } |
159 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
159 | + return apply_filters( 'site-reviews/get/defaults', $this->defaults ); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | * @param string $tab |
165 | 165 | * @return string |
166 | 166 | */ |
167 | - public function getPermission($page = '', $tab = 'index') |
|
167 | + public function getPermission( $page = '', $tab = 'index' ) |
|
168 | 168 | { |
169 | 169 | $fallback = 'edit_posts'; |
170 | 170 | $permissions = [ |
@@ -185,11 +185,11 @@ discard block |
||
185 | 185 | 'system-info' => 'edit_others_posts', |
186 | 186 | ] |
187 | 187 | ]; |
188 | - $permission = Arr::get($permissions, $page, $fallback); |
|
189 | - if (is_array($permission)) { |
|
190 | - $permission = Arr::get($permission, $tab, $fallback); |
|
188 | + $permission = Arr::get( $permissions, $page, $fallback ); |
|
189 | + if( is_array( $permission ) ) { |
|
190 | + $permission = Arr::get( $permission, $tab, $fallback ); |
|
191 | 191 | } |
192 | - return empty($permission) || !is_string($permission) |
|
192 | + return empty($permission) || !is_string( $permission ) |
|
193 | 193 | ? $fallback |
194 | 194 | : $permission; |
195 | 195 | } |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * @param string $tab |
200 | 200 | * @return bool |
201 | 201 | */ |
202 | - public function hasPermission($page = '', $tab = 'index') |
|
202 | + public function hasPermission( $page = '', $tab = 'index' ) |
|
203 | 203 | { |
204 | 204 | $isAdmin = $this->isAdmin(); |
205 | - return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab))); |
|
205 | + return !$isAdmin || ($isAdmin && $this->can( $this->getPermission( $page, $tab ) )); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public function init() |
212 | 212 | { |
213 | - $this->make(Actions::class)->run(); |
|
214 | - $this->make(Filters::class)->run(); |
|
213 | + $this->make( Actions::class )->run(); |
|
214 | + $this->make( Filters::class )->run(); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -226,31 +226,31 @@ discard block |
||
226 | 226 | * @param string $file |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function path($file = '', $realpath = true) |
|
229 | + public function path( $file = '', $realpath = true ) |
|
230 | 230 | { |
231 | - $path = plugin_dir_path($this->file); |
|
232 | - if (!$realpath) { |
|
233 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
231 | + $path = plugin_dir_path( $this->file ); |
|
232 | + if( !$realpath ) { |
|
233 | + $path = trailingslashit( WP_PLUGIN_DIR ).basename( dirname( $this->file ) ); |
|
234 | 234 | } |
235 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
236 | - return apply_filters('site-reviews/path', $path, $file); |
|
235 | + $path = trailingslashit( $path ).ltrim( trim( $file ), '/' ); |
|
236 | + return apply_filters( 'site-reviews/path', $path, $file ); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
240 | 240 | * @param object $addon |
241 | 241 | * @return void |
242 | 242 | */ |
243 | - public function register($addon) |
|
243 | + public function register( $addon ) |
|
244 | 244 | { |
245 | 245 | try { |
246 | - $reflection = new \ReflectionClass($addon); |
|
247 | - if ($id = $reflection->getConstant('ID')) { |
|
246 | + $reflection = new \ReflectionClass( $addon ); |
|
247 | + if( $id = $reflection->getConstant( 'ID' ) ) { |
|
248 | 248 | $this->addons[] = $id; |
249 | - $this->bind($id, $addon); |
|
249 | + $this->bind( $id, $addon ); |
|
250 | 250 | $addon->init(); |
251 | 251 | } |
252 | - } catch(\ReflectionException $e) { |
|
253 | - glsr_log()->error('Attempted to register an invalid addon.'); |
|
252 | + } catch( \ReflectionException $e ) { |
|
253 | + glsr_log()->error( 'Attempted to register an invalid addon.' ); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public function registerAddons() |
261 | 261 | { |
262 | - do_action('site-reviews/addon/register', $this); |
|
262 | + do_action( 'site-reviews/addon/register', $this ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function registerLanguages() |
269 | 269 | { |
270 | - load_plugin_textdomain(static::ID, false, |
|
271 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
270 | + load_plugin_textdomain( static::ID, false, |
|
271 | + trailingslashit( plugin_basename( $this->path() ).'/'.$this->languages ) |
|
272 | 272 | ); |
273 | 273 | } |
274 | 274 | |
@@ -277,26 +277,26 @@ discard block |
||
277 | 277 | */ |
278 | 278 | public function registerReviewTypes() |
279 | 279 | { |
280 | - $types = apply_filters('site-reviews/addon/types', []); |
|
281 | - $this->reviewTypes = wp_parse_args($types, [ |
|
282 | - 'local' => __('Local', 'site-reviews'), |
|
283 | - ]); |
|
280 | + $types = apply_filters( 'site-reviews/addon/types', [] ); |
|
281 | + $this->reviewTypes = wp_parse_args( $types, [ |
|
282 | + 'local' => __( 'Local', 'site-reviews' ), |
|
283 | + ] ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
287 | 287 | * @param string $view |
288 | 288 | * @return void |
289 | 289 | */ |
290 | - public function render($view, array $data = []) |
|
290 | + public function render( $view, array $data = [] ) |
|
291 | 291 | { |
292 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
293 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
294 | - if (!file_exists($file)) { |
|
295 | - glsr_log()->error(sprintf('File not found: (%s) %s', $view, $file)); |
|
292 | + $view = apply_filters( 'site-reviews/render/view', $view, $data ); |
|
293 | + $file = apply_filters( 'site-reviews/views/file', $this->file( $view ), $view, $data ); |
|
294 | + if( !file_exists( $file ) ) { |
|
295 | + glsr_log()->error( sprintf( 'File not found: (%s) %s', $view, $file ) ); |
|
296 | 296 | return; |
297 | 297 | } |
298 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
299 | - extract($data); |
|
298 | + $data = apply_filters( 'site-reviews/views/data', $data, $view ); |
|
299 | + extract( $data ); |
|
300 | 300 | include $file; |
301 | 301 | } |
302 | 302 | |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | */ |
306 | 306 | public function scheduleCronJob() |
307 | 307 | { |
308 | - if (false === wp_next_scheduled(static::CRON_EVENT)) { |
|
309 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
308 | + if( false === wp_next_scheduled( static::CRON_EVENT ) ) { |
|
309 | + wp_schedule_event( time(), 'twicedaily', static::CRON_EVENT ); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
@@ -315,9 +315,9 @@ discard block |
||
315 | 315 | */ |
316 | 316 | public function setDefaults() |
317 | 317 | { |
318 | - if (get_option(static::ID.'activated')) { |
|
319 | - $this->make(DefaultsManager::class)->set(); |
|
320 | - delete_option(static::ID.'activated'); |
|
318 | + if( get_option( static::ID.'activated' ) ) { |
|
319 | + $this->make( DefaultsManager::class )->set(); |
|
320 | + delete_option( static::ID.'activated' ); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | * @param string $file |
326 | 326 | * @return string |
327 | 327 | */ |
328 | - public function themePath($file = '') |
|
328 | + public function themePath( $file = '' ) |
|
329 | 329 | { |
330 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
330 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim( trim( $file ), '/' ); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -335,36 +335,36 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function unscheduleCronJob() |
337 | 337 | { |
338 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
338 | + wp_unschedule_event( intval( wp_next_scheduled( static::CRON_EVENT ) ), static::CRON_EVENT ); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | 342 | * @param string $path |
343 | 343 | * @return string |
344 | 344 | */ |
345 | - public function url($path = '') |
|
345 | + public function url( $path = '' ) |
|
346 | 346 | { |
347 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
348 | - return apply_filters('site-reviews/url', $url, $path); |
|
347 | + $url = esc_url( plugin_dir_url( $this->file ).ltrim( trim( $path ), '/' ) ); |
|
348 | + return apply_filters( 'site-reviews/url', $url, $path ); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
352 | 352 | * @param string $versionLevel |
353 | 353 | * @return string |
354 | 354 | */ |
355 | - public function version($versionLevel = '') |
|
355 | + public function version( $versionLevel = '' ) |
|
356 | 356 | { |
357 | 357 | $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
358 | - preg_match($pattern, $this->version, $matches); |
|
359 | - switch ($versionLevel) { |
|
358 | + preg_match( $pattern, $this->version, $matches ); |
|
359 | + switch( $versionLevel ) { |
|
360 | 360 | case 'major': |
361 | - $version = Arr::get($matches, 1); |
|
361 | + $version = Arr::get( $matches, 1 ); |
|
362 | 362 | break; |
363 | 363 | case 'minor': |
364 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
364 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ); |
|
365 | 365 | break; |
366 | 366 | case 'patch': |
367 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
367 | + $version = Arr::get( $matches, 1 ).Arr::get( $matches, 2 ).Arr::get( $matches, 3 ); |
|
368 | 368 | break; |
369 | 369 | } |
370 | 370 | return empty($version) |
@@ -8,18 +8,18 @@ |
||
8 | 8 | |
9 | 9 | class RegisterWidgets |
10 | 10 | { |
11 | - /** |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function handle(Command $command) |
|
15 | - { |
|
16 | - foreach ($command->widgets as $baseId => $args) { |
|
17 | - $widgetClass = Helper::buildClassName($baseId.'-widget', 'Widgets'); |
|
18 | - if (!class_exists($widgetClass)) { |
|
19 | - glsr_log()->error(sprintf('Widget class missing (%s)', $widgetClass)); |
|
20 | - continue; |
|
21 | - } |
|
22 | - register_widget(new $widgetClass(Application::PREFIX.$baseId, $args['name'], $args)); |
|
23 | - } |
|
24 | - } |
|
11 | + /** |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function handle(Command $command) |
|
15 | + { |
|
16 | + foreach ($command->widgets as $baseId => $args) { |
|
17 | + $widgetClass = Helper::buildClassName($baseId.'-widget', 'Widgets'); |
|
18 | + if (!class_exists($widgetClass)) { |
|
19 | + glsr_log()->error(sprintf('Widget class missing (%s)', $widgetClass)); |
|
20 | + continue; |
|
21 | + } |
|
22 | + register_widget(new $widgetClass(Application::PREFIX.$baseId, $args['name'], $args)); |
|
23 | + } |
|
24 | + } |
|
25 | 25 | } |
@@ -11,15 +11,15 @@ |
||
11 | 11 | /** |
12 | 12 | * @return void |
13 | 13 | */ |
14 | - public function handle(Command $command) |
|
14 | + public function handle( Command $command ) |
|
15 | 15 | { |
16 | - foreach ($command->widgets as $baseId => $args) { |
|
17 | - $widgetClass = Helper::buildClassName($baseId.'-widget', 'Widgets'); |
|
18 | - if (!class_exists($widgetClass)) { |
|
19 | - glsr_log()->error(sprintf('Widget class missing (%s)', $widgetClass)); |
|
16 | + foreach( $command->widgets as $baseId => $args ) { |
|
17 | + $widgetClass = Helper::buildClassName( $baseId.'-widget', 'Widgets' ); |
|
18 | + if( !class_exists( $widgetClass ) ) { |
|
19 | + glsr_log()->error( sprintf( 'Widget class missing (%s)', $widgetClass ) ); |
|
20 | 20 | continue; |
21 | 21 | } |
22 | - register_widget(new $widgetClass(Application::PREFIX.$baseId, $args['name'], $args)); |
|
22 | + register_widget( new $widgetClass( Application::PREFIX.$baseId, $args['name'], $args ) ); |
|
23 | 23 | } |
24 | 24 | } |
25 | 25 | } |
@@ -10,158 +10,158 @@ |
||
10 | 10 | |
11 | 11 | class EnqueueAdminAssets |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $pointers; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $pointers; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function handle(Command $command) |
|
22 | - { |
|
23 | - $this->generatePointers($command->pointers); |
|
24 | - $this->enqueueAssets(); |
|
25 | - $this->localizeAssets(); |
|
26 | - } |
|
18 | + /** |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function handle(Command $command) |
|
22 | + { |
|
23 | + $this->generatePointers($command->pointers); |
|
24 | + $this->enqueueAssets(); |
|
25 | + $this->localizeAssets(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public function enqueueAssets() |
|
32 | - { |
|
33 | - if (!$this->isCurrentScreen()) { |
|
34 | - return; |
|
35 | - } |
|
36 | - wp_enqueue_style( |
|
37 | - Application::ID.'/admin', |
|
38 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
39 | - [], |
|
40 | - glsr()->version |
|
41 | - ); |
|
42 | - wp_enqueue_script( |
|
43 | - Application::ID.'/admin', |
|
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | - $this->getDependencies(), |
|
46 | - glsr()->version, |
|
47 | - true |
|
48 | - ); |
|
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
52 | - } |
|
53 | - } |
|
28 | + /** |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public function enqueueAssets() |
|
32 | + { |
|
33 | + if (!$this->isCurrentScreen()) { |
|
34 | + return; |
|
35 | + } |
|
36 | + wp_enqueue_style( |
|
37 | + Application::ID.'/admin', |
|
38 | + glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
39 | + [], |
|
40 | + glsr()->version |
|
41 | + ); |
|
42 | + wp_enqueue_script( |
|
43 | + Application::ID.'/admin', |
|
44 | + glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
45 | + $this->getDependencies(), |
|
46 | + glsr()->version, |
|
47 | + true |
|
48 | + ); |
|
49 | + if (!empty($this->pointers)) { |
|
50 | + wp_enqueue_style('wp-pointer'); |
|
51 | + wp_enqueue_script('wp-pointer'); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function localizeAssets() |
|
59 | - { |
|
60 | - $variables = [ |
|
61 | - 'action' => Application::PREFIX.'action', |
|
62 | - 'addons' => [], |
|
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | - 'hideoptions' => [ |
|
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | - ], |
|
69 | - 'nameprefix' => Application::ID, |
|
70 | - 'nonce' => [ |
|
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | - ], |
|
79 | - 'pointers' => $this->pointers, |
|
80 | - 'shortcodes' => [], |
|
81 | - 'tinymce' => [ |
|
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | - ], |
|
84 | - ]; |
|
85 | - if (user_can_richedit()) { |
|
86 | - $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | - } |
|
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID.'/admin', 'GLSR', $variables); |
|
90 | - } |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function localizeAssets() |
|
59 | + { |
|
60 | + $variables = [ |
|
61 | + 'action' => Application::PREFIX.'action', |
|
62 | + 'addons' => [], |
|
63 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
64 | + 'hideoptions' => [ |
|
65 | + 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
68 | + ], |
|
69 | + 'nameprefix' => Application::ID, |
|
70 | + 'nonce' => [ |
|
71 | + 'change-status' => wp_create_nonce('change-status'), |
|
72 | + 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | + 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | + 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | + 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | + 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | + 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
78 | + ], |
|
79 | + 'pointers' => $this->pointers, |
|
80 | + 'shortcodes' => [], |
|
81 | + 'tinymce' => [ |
|
82 | + 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
83 | + ], |
|
84 | + ]; |
|
85 | + if (user_can_richedit()) { |
|
86 | + $variables['shortcodes'] = $this->localizeShortcodes(); |
|
87 | + } |
|
88 | + $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | + wp_localize_script(Application::ID.'/admin', 'GLSR', $variables); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - protected function getDependencies() |
|
96 | - { |
|
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
99 | - 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | - ]); |
|
101 | - return $dependencies; |
|
102 | - } |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + protected function getDependencies() |
|
96 | + { |
|
97 | + $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | + $dependencies = array_merge($dependencies, [ |
|
99 | + 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
|
100 | + ]); |
|
101 | + return $dependencies; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - protected function generatePointer(array $pointer) |
|
108 | - { |
|
109 | - return [ |
|
110 | - 'id' => $pointer['id'], |
|
111 | - 'options' => [ |
|
112 | - 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | - 'position' => $pointer['position'], |
|
114 | - ], |
|
115 | - 'screen' => $pointer['screen'], |
|
116 | - 'target' => $pointer['target'], |
|
117 | - ]; |
|
118 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + protected function generatePointer(array $pointer) |
|
108 | + { |
|
109 | + return [ |
|
110 | + 'id' => $pointer['id'], |
|
111 | + 'options' => [ |
|
112 | + 'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>', |
|
113 | + 'position' => $pointer['position'], |
|
114 | + ], |
|
115 | + 'screen' => $pointer['screen'], |
|
116 | + 'target' => $pointer['target'], |
|
117 | + ]; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - protected function generatePointers(array $pointers) |
|
124 | - { |
|
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | - $generatedPointers = []; |
|
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | - continue; |
|
131 | - } |
|
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | - continue; |
|
134 | - } |
|
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | - } |
|
137 | - $this->pointers = $generatedPointers; |
|
138 | - } |
|
120 | + /** |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + protected function generatePointers(array $pointers) |
|
124 | + { |
|
125 | + $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | + $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
127 | + $generatedPointers = []; |
|
128 | + foreach ($pointers as $pointer) { |
|
129 | + if ($pointer['screen'] != glsr_current_screen()->id) { |
|
130 | + continue; |
|
131 | + } |
|
132 | + if (in_array($pointer['id'], $dismissedPointers)) { |
|
133 | + continue; |
|
134 | + } |
|
135 | + $generatedPointers[] = $this->generatePointer($pointer); |
|
136 | + } |
|
137 | + $this->pointers = $generatedPointers; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - protected function isCurrentScreen() |
|
144 | - { |
|
145 | - $screen = glsr_current_screen(); |
|
146 | - return Application::POST_TYPE == $screen->post_type |
|
147 | - || 'dashboard' == $screen->id |
|
148 | - || 'plugins_page_'.Application::ID == $screen->id |
|
149 | - || 'post' == $screen->base |
|
150 | - || 'widgets' == $screen->id; |
|
151 | - } |
|
140 | + /** |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + protected function isCurrentScreen() |
|
144 | + { |
|
145 | + $screen = glsr_current_screen(); |
|
146 | + return Application::POST_TYPE == $screen->post_type |
|
147 | + || 'dashboard' == $screen->id |
|
148 | + || 'plugins_page_'.Application::ID == $screen->id |
|
149 | + || 'post' == $screen->base |
|
150 | + || 'widgets' == $screen->id; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function localizeShortcodes() |
|
157 | - { |
|
158 | - $variables = []; |
|
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
161 | - continue; |
|
162 | - } |
|
163 | - $variables[$tag] = $args['required']; |
|
164 | - } |
|
165 | - return $variables; |
|
166 | - } |
|
153 | + /** |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function localizeShortcodes() |
|
157 | + { |
|
158 | + $variables = []; |
|
159 | + foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | + if (empty($args['required'])) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + $variables[$tag] = $args['required']; |
|
164 | + } |
|
165 | + return $variables; |
|
166 | + } |
|
167 | 167 | } |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function handle(Command $command) |
|
21 | + public function handle( Command $command ) |
|
22 | 22 | { |
23 | - $this->generatePointers($command->pointers); |
|
23 | + $this->generatePointers( $command->pointers ); |
|
24 | 24 | $this->enqueueAssets(); |
25 | 25 | $this->localizeAssets(); |
26 | 26 | } |
@@ -30,25 +30,25 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function enqueueAssets() |
32 | 32 | { |
33 | - if (!$this->isCurrentScreen()) { |
|
33 | + if( !$this->isCurrentScreen() ) { |
|
34 | 34 | return; |
35 | 35 | } |
36 | 36 | wp_enqueue_style( |
37 | 37 | Application::ID.'/admin', |
38 | - glsr()->url('assets/styles/'.Application::ID.'-admin.css'), |
|
38 | + glsr()->url( 'assets/styles/'.Application::ID.'-admin.css' ), |
|
39 | 39 | [], |
40 | 40 | glsr()->version |
41 | 41 | ); |
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID.'/admin', |
44 | - glsr()->url('assets/scripts/'.Application::ID.'-admin.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'-admin.js' ), |
|
45 | 45 | $this->getDependencies(), |
46 | 46 | glsr()->version, |
47 | 47 | true |
48 | 48 | ); |
49 | - if (!empty($this->pointers)) { |
|
50 | - wp_enqueue_style('wp-pointer'); |
|
51 | - wp_enqueue_script('wp-pointer'); |
|
49 | + if( !empty($this->pointers) ) { |
|
50 | + wp_enqueue_style( 'wp-pointer' ); |
|
51 | + wp_enqueue_script( 'wp-pointer' ); |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
@@ -60,33 +60,33 @@ discard block |
||
60 | 60 | $variables = [ |
61 | 61 | 'action' => Application::PREFIX.'action', |
62 | 62 | 'addons' => [], |
63 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
63 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
64 | 64 | 'hideoptions' => [ |
65 | - 'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
66 | - 'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
67 | - 'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
65 | + 'site_reviews' => glsr( SiteReviewsShortcode::class )->getHideOptions(), |
|
66 | + 'site_reviews_form' => glsr( SiteReviewsFormShortcode::class )->getHideOptions(), |
|
67 | + 'site_reviews_summary' => glsr( SiteReviewsSummaryShortcode::class )->getHideOptions(), |
|
68 | 68 | ], |
69 | 69 | 'nameprefix' => Application::ID, |
70 | 70 | 'nonce' => [ |
71 | - 'change-status' => wp_create_nonce('change-status'), |
|
72 | - 'clear-console' => wp_create_nonce('clear-console'), |
|
73 | - 'count-reviews' => wp_create_nonce('count-reviews'), |
|
74 | - 'fetch-console' => wp_create_nonce('fetch-console'), |
|
75 | - 'mce-shortcode' => wp_create_nonce('mce-shortcode'), |
|
76 | - 'sync-reviews' => wp_create_nonce('sync-reviews'), |
|
77 | - 'toggle-pinned' => wp_create_nonce('toggle-pinned'), |
|
71 | + 'change-status' => wp_create_nonce( 'change-status' ), |
|
72 | + 'clear-console' => wp_create_nonce( 'clear-console' ), |
|
73 | + 'count-reviews' => wp_create_nonce( 'count-reviews' ), |
|
74 | + 'fetch-console' => wp_create_nonce( 'fetch-console' ), |
|
75 | + 'mce-shortcode' => wp_create_nonce( 'mce-shortcode' ), |
|
76 | + 'sync-reviews' => wp_create_nonce( 'sync-reviews' ), |
|
77 | + 'toggle-pinned' => wp_create_nonce( 'toggle-pinned' ), |
|
78 | 78 | ], |
79 | 79 | 'pointers' => $this->pointers, |
80 | 80 | 'shortcodes' => [], |
81 | 81 | 'tinymce' => [ |
82 | - 'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'), |
|
82 | + 'glsr_shortcode' => glsr()->url( 'assets/scripts/mce-plugin.js' ), |
|
83 | 83 | ], |
84 | 84 | ]; |
85 | - if (user_can_richedit()) { |
|
85 | + if( user_can_richedit() ) { |
|
86 | 86 | $variables['shortcodes'] = $this->localizeShortcodes(); |
87 | 87 | } |
88 | - $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables); |
|
89 | - wp_localize_script(Application::ID.'/admin', 'GLSR', $variables); |
|
88 | + $variables = apply_filters( 'site-reviews/enqueue/admin/localize', $variables ); |
|
89 | + wp_localize_script( Application::ID.'/admin', 'GLSR', $variables ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function getDependencies() |
96 | 96 | { |
97 | - $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []); |
|
98 | - $dependencies = array_merge($dependencies, [ |
|
97 | + $dependencies = apply_filters( 'site-reviews/enqueue/admin/dependencies', [] ); |
|
98 | + $dependencies = array_merge( $dependencies, [ |
|
99 | 99 | 'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util', |
100 | - ]); |
|
100 | + ] ); |
|
101 | 101 | return $dependencies; |
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @return array |
106 | 106 | */ |
107 | - protected function generatePointer(array $pointer) |
|
107 | + protected function generatePointer( array $pointer ) |
|
108 | 108 | { |
109 | 109 | return [ |
110 | 110 | 'id' => $pointer['id'], |
@@ -120,19 +120,19 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * @return void |
122 | 122 | */ |
123 | - protected function generatePointers(array $pointers) |
|
123 | + protected function generatePointers( array $pointers ) |
|
124 | 124 | { |
125 | - $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true); |
|
126 | - $dismissedPointers = explode(',', (string) $dismissedPointers); |
|
125 | + $dismissedPointers = get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ); |
|
126 | + $dismissedPointers = explode( ',', (string)$dismissedPointers ); |
|
127 | 127 | $generatedPointers = []; |
128 | - foreach ($pointers as $pointer) { |
|
129 | - if ($pointer['screen'] != glsr_current_screen()->id) { |
|
128 | + foreach( $pointers as $pointer ) { |
|
129 | + if( $pointer['screen'] != glsr_current_screen()->id ) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | - if (in_array($pointer['id'], $dismissedPointers)) { |
|
132 | + if( in_array( $pointer['id'], $dismissedPointers ) ) { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | - $generatedPointers[] = $this->generatePointer($pointer); |
|
135 | + $generatedPointers[] = $this->generatePointer( $pointer ); |
|
136 | 136 | } |
137 | 137 | $this->pointers = $generatedPointers; |
138 | 138 | } |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | protected function localizeShortcodes() |
157 | 157 | { |
158 | 158 | $variables = []; |
159 | - foreach (glsr()->mceShortcodes as $tag => $args) { |
|
160 | - if (empty($args['required'])) { |
|
159 | + foreach( glsr()->mceShortcodes as $tag => $args ) { |
|
160 | + if( empty($args['required']) ) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | 163 | $variables[$tag] = $args['required']; |
@@ -7,18 +7,18 @@ |
||
7 | 7 | |
8 | 8 | class RegisterShortcodes |
9 | 9 | { |
10 | - /** |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function handle(Command $command) |
|
14 | - { |
|
15 | - foreach ($command->shortcodes as $shortcode) { |
|
16 | - $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
17 | - if (!class_exists($shortcodeClass)) { |
|
18 | - glsr_log()->error(sprintf('Shortcode class missing (%s)', $shortcodeClass)); |
|
19 | - continue; |
|
20 | - } |
|
21 | - add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
22 | - } |
|
23 | - } |
|
10 | + /** |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function handle(Command $command) |
|
14 | + { |
|
15 | + foreach ($command->shortcodes as $shortcode) { |
|
16 | + $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
17 | + if (!class_exists($shortcodeClass)) { |
|
18 | + glsr_log()->error(sprintf('Shortcode class missing (%s)', $shortcodeClass)); |
|
19 | + continue; |
|
20 | + } |
|
21 | + add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
22 | + } |
|
23 | + } |
|
24 | 24 | } |
@@ -10,15 +10,15 @@ |
||
10 | 10 | /** |
11 | 11 | * @return void |
12 | 12 | */ |
13 | - public function handle(Command $command) |
|
13 | + public function handle( Command $command ) |
|
14 | 14 | { |
15 | - foreach ($command->shortcodes as $shortcode) { |
|
16 | - $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes'); |
|
17 | - if (!class_exists($shortcodeClass)) { |
|
18 | - glsr_log()->error(sprintf('Shortcode class missing (%s)', $shortcodeClass)); |
|
15 | + foreach( $command->shortcodes as $shortcode ) { |
|
16 | + $shortcodeClass = Helper::buildClassName( $shortcode.'-shortcode', 'Shortcodes' ); |
|
17 | + if( !class_exists( $shortcodeClass ) ) { |
|
18 | + glsr_log()->error( sprintf( 'Shortcode class missing (%s)', $shortcodeClass ) ); |
|
19 | 19 | continue; |
20 | 20 | } |
21 | - add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']); |
|
21 | + add_shortcode( $shortcode, [glsr( $shortcodeClass ), 'buildShortcode'] ); |
|
22 | 22 | } |
23 | 23 | } |
24 | 24 | } |
@@ -7,22 +7,22 @@ |
||
7 | 7 | |
8 | 8 | class RegisterTinymcePopups |
9 | 9 | { |
10 | - /** |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function handle(Command $command) |
|
14 | - { |
|
15 | - foreach ($command->popups as $slug => $label) { |
|
16 | - $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
17 | - if (!class_exists($buttonClass)) { |
|
18 | - glsr_log()->error(sprintf('Tinymce Popup class missing (%s)', $buttonClass)); |
|
19 | - continue; |
|
20 | - } |
|
21 | - $shortcode = glsr($buttonClass)->register($slug, [ |
|
22 | - 'label' => $label, |
|
23 | - 'title' => $label, |
|
24 | - ]); |
|
25 | - glsr()->mceShortcodes[$slug] = $shortcode->properties; |
|
26 | - } |
|
27 | - } |
|
10 | + /** |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function handle(Command $command) |
|
14 | + { |
|
15 | + foreach ($command->popups as $slug => $label) { |
|
16 | + $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
17 | + if (!class_exists($buttonClass)) { |
|
18 | + glsr_log()->error(sprintf('Tinymce Popup class missing (%s)', $buttonClass)); |
|
19 | + continue; |
|
20 | + } |
|
21 | + $shortcode = glsr($buttonClass)->register($slug, [ |
|
22 | + 'label' => $label, |
|
23 | + 'title' => $label, |
|
24 | + ]); |
|
25 | + glsr()->mceShortcodes[$slug] = $shortcode->properties; |
|
26 | + } |
|
27 | + } |
|
28 | 28 | } |
@@ -10,18 +10,18 @@ |
||
10 | 10 | /** |
11 | 11 | * @return void |
12 | 12 | */ |
13 | - public function handle(Command $command) |
|
13 | + public function handle( Command $command ) |
|
14 | 14 | { |
15 | - foreach ($command->popups as $slug => $label) { |
|
16 | - $buttonClass = Helper::buildClassName($slug.'-popup', 'Shortcodes'); |
|
17 | - if (!class_exists($buttonClass)) { |
|
18 | - glsr_log()->error(sprintf('Tinymce Popup class missing (%s)', $buttonClass)); |
|
15 | + foreach( $command->popups as $slug => $label ) { |
|
16 | + $buttonClass = Helper::buildClassName( $slug.'-popup', 'Shortcodes' ); |
|
17 | + if( !class_exists( $buttonClass ) ) { |
|
18 | + glsr_log()->error( sprintf( 'Tinymce Popup class missing (%s)', $buttonClass ) ); |
|
19 | 19 | continue; |
20 | 20 | } |
21 | - $shortcode = glsr($buttonClass)->register($slug, [ |
|
21 | + $shortcode = glsr( $buttonClass )->register( $slug, [ |
|
22 | 22 | 'label' => $label, |
23 | 23 | 'title' => $label, |
24 | - ]); |
|
24 | + ] ); |
|
25 | 25 | glsr()->mceShortcodes[$slug] = $shortcode->properties; |
26 | 26 | } |
27 | 27 | } |