@@ -9,25 +9,25 @@ discard block |
||
9 | 9 | * @return mixed |
10 | 10 | */ |
11 | 11 | add_filter('plugins_loaded', function () { |
12 | - $hooks = array( |
|
13 | - 'glsr_calculate_ratings' => 1, |
|
14 | - 'glsr_create_review' => 2, |
|
15 | - 'glsr_debug' => 10, |
|
16 | - 'glsr_get' => 4, |
|
17 | - 'glsr_get_option' => 4, |
|
18 | - 'glsr_get_options' => 1, |
|
19 | - 'glsr_get_review' => 2, |
|
20 | - 'glsr_get_reviews' => 2, |
|
21 | - 'glsr_log' => 3, |
|
22 | - 'glsr_star_rating' => 2, |
|
23 | - ); |
|
24 | - foreach ($hooks as $function => $acceptedArgs) { |
|
25 | - add_filter($function, function () use ($function) { |
|
26 | - $args = func_get_args(); |
|
27 | - array_shift($args); // remove the fallback value |
|
28 | - return call_user_func_array($function, $args); |
|
29 | - }, 10, $acceptedArgs); |
|
30 | - } |
|
12 | + $hooks = array( |
|
13 | + 'glsr_calculate_ratings' => 1, |
|
14 | + 'glsr_create_review' => 2, |
|
15 | + 'glsr_debug' => 10, |
|
16 | + 'glsr_get' => 4, |
|
17 | + 'glsr_get_option' => 4, |
|
18 | + 'glsr_get_options' => 1, |
|
19 | + 'glsr_get_review' => 2, |
|
20 | + 'glsr_get_reviews' => 2, |
|
21 | + 'glsr_log' => 3, |
|
22 | + 'glsr_star_rating' => 2, |
|
23 | + ); |
|
24 | + foreach ($hooks as $function => $acceptedArgs) { |
|
25 | + add_filter($function, function () use ($function) { |
|
26 | + $args = func_get_args(); |
|
27 | + array_shift($args); // remove the fallback value |
|
28 | + return call_user_func_array($function, $args); |
|
29 | + }, 10, $acceptedArgs); |
|
30 | + } |
|
31 | 31 | }); |
32 | 32 | |
33 | 33 | /** |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function glsr($alias = null) |
37 | 37 | { |
38 | - $app = \GeminiLabs\SiteReviews\Application::load(); |
|
39 | - return !is_null($alias) |
|
40 | - ? $app->make($alias) |
|
41 | - : $app; |
|
38 | + $app = \GeminiLabs\SiteReviews\Application::load(); |
|
39 | + return !is_null($alias) |
|
40 | + ? $app->make($alias) |
|
41 | + : $app; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | */ |
49 | 49 | function glsr_array_column(array $array, $column) |
50 | 50 | { |
51 | - $result = array(); |
|
52 | - foreach ($array as $subarray) { |
|
53 | - $subarray = (array) $subarray; |
|
54 | - if (!isset($subarray[$column])) { |
|
55 | - continue; |
|
56 | - } |
|
57 | - $result[] = $subarray[$column]; |
|
58 | - } |
|
59 | - return $result; |
|
51 | + $result = array(); |
|
52 | + foreach ($array as $subarray) { |
|
53 | + $subarray = (array) $subarray; |
|
54 | + if (!isset($subarray[$column])) { |
|
55 | + continue; |
|
56 | + } |
|
57 | + $result[] = $subarray[$column]; |
|
58 | + } |
|
59 | + return $result; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | */ |
65 | 65 | function glsr_calculate_ratings() |
66 | 66 | { |
67 | - glsr('Database\CountsManager')->updateAll(); |
|
68 | - glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews')); |
|
67 | + glsr('Database\CountsManager')->updateAll(); |
|
68 | + glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews')); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | */ |
74 | 74 | function glsr_create_review($reviewValues = array()) |
75 | 75 | { |
76 | - $review = new \GeminiLabs\SiteReviews\Commands\CreateReview( |
|
77 | - \GeminiLabs\SiteReviews\Helpers\Arr::consolidate($reviewValues) |
|
78 | - ); |
|
79 | - return glsr('Database\ReviewManager')->create($review); |
|
76 | + $review = new \GeminiLabs\SiteReviews\Commands\CreateReview( |
|
77 | + \GeminiLabs\SiteReviews\Helpers\Arr::consolidate($reviewValues) |
|
78 | + ); |
|
79 | + return glsr('Database\ReviewManager')->create($review); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | */ |
85 | 85 | function glsr_current_screen() |
86 | 86 | { |
87 | - if (function_exists('get_current_screen')) { |
|
88 | - $screen = get_current_screen(); |
|
89 | - } |
|
90 | - return empty($screen) |
|
91 | - ? (object) array_fill_keys(['base', 'id', 'post_type'], null) |
|
92 | - : $screen; |
|
87 | + if (function_exists('get_current_screen')) { |
|
88 | + $screen = get_current_screen(); |
|
89 | + } |
|
90 | + return empty($screen) |
|
91 | + ? (object) array_fill_keys(['base', 'id', 'post_type'], null) |
|
92 | + : $screen; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,16 +98,16 @@ discard block |
||
98 | 98 | */ |
99 | 99 | function glsr_debug(...$vars) |
100 | 100 | { |
101 | - if (1 == count($vars)) { |
|
102 | - $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
|
103 | - printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
|
104 | - } else { |
|
105 | - echo '<div class="glsr-debug-group">'; |
|
106 | - foreach ($vars as $var) { |
|
107 | - glsr_debug($var); |
|
108 | - } |
|
109 | - echo '</div>'; |
|
110 | - } |
|
101 | + if (1 == count($vars)) { |
|
102 | + $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8'); |
|
103 | + printf('<div class="glsr-debug"><pre>%s</pre></div>', $value); |
|
104 | + } else { |
|
105 | + echo '<div class="glsr-debug-group">'; |
|
106 | + foreach ($vars as $var) { |
|
107 | + glsr_debug($var); |
|
108 | + } |
|
109 | + echo '</div>'; |
|
110 | + } |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | */ |
119 | 119 | function glsr_get($array, $path = '', $fallback = '') |
120 | 120 | { |
121 | - return \GeminiLabs\SiteReviews\Helpers\Arr::get($array, $path, $fallback); |
|
121 | + return \GeminiLabs\SiteReviews\Helpers\Arr::get($array, $path, $fallback); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | */ |
130 | 130 | function glsr_get_option($path = '', $fallback = '', $cast = '') |
131 | 131 | { |
132 | - return is_string($path) |
|
133 | - ? glsr('Database\OptionManager')->get(\GeminiLabs\SiteReviews\Helpers\Str::prefix('settings.', $path), $fallback, $cast) |
|
134 | - : $fallback; |
|
132 | + return is_string($path) |
|
133 | + ? glsr('Database\OptionManager')->get(\GeminiLabs\SiteReviews\Helpers\Str::prefix('settings.', $path), $fallback, $cast) |
|
134 | + : $fallback; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | function glsr_get_options() |
141 | 141 | { |
142 | - return glsr('Database\OptionManager')->get('settings'); |
|
142 | + return glsr('Database\OptionManager')->get('settings'); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | */ |
149 | 149 | function glsr_get_review($post) |
150 | 150 | { |
151 | - if (is_numeric($post)) { |
|
152 | - $post = get_post($post); |
|
153 | - } |
|
154 | - if (!($post instanceof WP_Post)) { |
|
155 | - $post = new WP_Post((object) []); |
|
156 | - } |
|
157 | - return glsr('Database\ReviewManager')->single($post); |
|
151 | + if (is_numeric($post)) { |
|
152 | + $post = get_post($post); |
|
153 | + } |
|
154 | + if (!($post instanceof WP_Post)) { |
|
155 | + $post = new WP_Post((object) []); |
|
156 | + } |
|
157 | + return glsr('Database\ReviewManager')->single($post); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | function glsr_get_reviews($args = array()) |
164 | 164 | { |
165 | - return glsr('Database\ReviewManager')->get(\GeminiLabs\SiteReviews\Helpers\Arr::consolidate($args)); |
|
165 | + return glsr('Database\ReviewManager')->get(\GeminiLabs\SiteReviews\Helpers\Arr::consolidate($args)); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | */ |
171 | 171 | function glsr_log() |
172 | 172 | { |
173 | - $args = func_get_args(); |
|
174 | - $console = glsr('Modules\Console'); |
|
175 | - if ($value = \GeminiLabs\SiteReviews\Helpers\Arr::get($args, '0')) { |
|
176 | - return $console->debug($value, \GeminiLabs\SiteReviews\Helpers\Arr::get($args, '1', [])); |
|
177 | - } |
|
178 | - return $console; |
|
173 | + $args = func_get_args(); |
|
174 | + $console = glsr('Modules\Console'); |
|
175 | + if ($value = \GeminiLabs\SiteReviews\Helpers\Arr::get($args, '0')) { |
|
176 | + return $console->debug($value, \GeminiLabs\SiteReviews\Helpers\Arr::get($args, '1', [])); |
|
177 | + } |
|
178 | + return $console; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,5 +183,5 @@ discard block |
||
183 | 183 | */ |
184 | 184 | function glsr_star_rating($rating) |
185 | 185 | { |
186 | - return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]); |
|
186 | + return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]); |
|
187 | 187 | } |
@@ -1,22 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - 'fields' => [ |
|
5 | - 'input' => 'input', |
|
6 | - 'input_checkbox' => 'input', |
|
7 | - 'input_radio' => 'input', |
|
8 | - 'label' => 'et_pb_contact_form_label', |
|
9 | - 'select' => 'et_pb_contact_select input', |
|
10 | - 'textarea' => 'et_pb_contact_message input', |
|
11 | - ], |
|
12 | - 'validation' => [ |
|
13 | - 'field_error_class' => 'et_contact_error', |
|
14 | - 'input_error_class' => 'et_contact_error', |
|
15 | - // 'input_valid_class' => 'glsr-is-valid', |
|
16 | - // 'message_error_class' => 'glsr-has-errors', |
|
17 | - // 'message_initial_class' => 'glsr-is-visible', |
|
18 | - // 'message_success_class' => 'glsr-has-success', |
|
19 | - // 'message_tag' => 'div', |
|
20 | - // 'message_tag_class' => 'glsr-form-message', |
|
21 | - ], |
|
4 | + 'fields' => [ |
|
5 | + 'input' => 'input', |
|
6 | + 'input_checkbox' => 'input', |
|
7 | + 'input_radio' => 'input', |
|
8 | + 'label' => 'et_pb_contact_form_label', |
|
9 | + 'select' => 'et_pb_contact_select input', |
|
10 | + 'textarea' => 'et_pb_contact_message input', |
|
11 | + ], |
|
12 | + 'validation' => [ |
|
13 | + 'field_error_class' => 'et_contact_error', |
|
14 | + 'input_error_class' => 'et_contact_error', |
|
15 | + // 'input_valid_class' => 'glsr-is-valid', |
|
16 | + // 'message_error_class' => 'glsr-has-errors', |
|
17 | + // 'message_initial_class' => 'glsr-is-visible', |
|
18 | + // 'message_success_class' => 'glsr-has-success', |
|
19 | + // 'message_tag' => 'div', |
|
20 | + // 'message_tag_class' => 'glsr-form-message', |
|
21 | + ], |
|
22 | 22 | ]; |
@@ -3,144 +3,144 @@ |
||
3 | 3 | defined('WPINC') || die; |
4 | 4 | |
5 | 5 | if (apply_filters('site-reviews/support/deprecated/v4', true)) { |
6 | - // Unprotected review meta has been deprecated |
|
7 | - add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) { |
|
8 | - $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
9 | - if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
10 | - return $data; |
|
11 | - } |
|
12 | - glsr()->deprecated[] = sprintf( |
|
13 | - 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
|
14 | - $metaKey |
|
15 | - ); |
|
16 | - return get_post_meta($postId, '_'.$metaKey, $single); |
|
17 | - }, 10, 4); |
|
6 | + // Unprotected review meta has been deprecated |
|
7 | + add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) { |
|
8 | + $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults()); |
|
9 | + if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) { |
|
10 | + return $data; |
|
11 | + } |
|
12 | + glsr()->deprecated[] = sprintf( |
|
13 | + 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
|
14 | + $metaKey |
|
15 | + ); |
|
16 | + return get_post_meta($postId, '_'.$metaKey, $single); |
|
17 | + }, 10, 4); |
|
18 | 18 | |
19 | - // Modules/Html/Template.php |
|
20 | - add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
|
21 | - $search = '{{ navigation }}'; |
|
22 | - if (false !== strpos($template, $search)) { |
|
23 | - $context['navigation'] = $context['pagination']; |
|
24 | - glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
|
25 | - } |
|
26 | - return $context; |
|
27 | - }, 10, 2); |
|
19 | + // Modules/Html/Template.php |
|
20 | + add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
|
21 | + $search = '{{ navigation }}'; |
|
22 | + if (false !== strpos($template, $search)) { |
|
23 | + $context['navigation'] = $context['pagination']; |
|
24 | + glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.'; |
|
25 | + } |
|
26 | + return $context; |
|
27 | + }, 10, 2); |
|
28 | 28 | |
29 | - // Modules/Html/Template.php |
|
30 | - add_filter('site-reviews/build/template/reviews', function ($template) { |
|
31 | - if (has_filter('site-reviews/reviews/pagination-wrapper')) { |
|
32 | - glsr()->deprecated[] = 'The "site-reviews/reviews/pagination-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.'; |
|
33 | - } |
|
34 | - if (has_filter('site-reviews/reviews/reviews-wrapper')) { |
|
35 | - glsr()->deprecated[] = 'The "site-reviews/reviews/reviews-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.'; |
|
36 | - } |
|
37 | - }); |
|
29 | + // Modules/Html/Template.php |
|
30 | + add_filter('site-reviews/build/template/reviews', function ($template) { |
|
31 | + if (has_filter('site-reviews/reviews/pagination-wrapper')) { |
|
32 | + glsr()->deprecated[] = 'The "site-reviews/reviews/pagination-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.'; |
|
33 | + } |
|
34 | + if (has_filter('site-reviews/reviews/reviews-wrapper')) { |
|
35 | + glsr()->deprecated[] = 'The "site-reviews/reviews/reviews-wrapper" hook has been removed. Please use the "site-reviews/builder/result" hook instead.'; |
|
36 | + } |
|
37 | + }); |
|
38 | 38 | |
39 | - // Database/ReviewManager.php |
|
40 | - add_action('site-reviews/review/created', function ($review) { |
|
41 | - if (has_action('site-reviews/local/review/create')) { |
|
42 | - glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
|
43 | - do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
44 | - } |
|
45 | - }, 9); |
|
39 | + // Database/ReviewManager.php |
|
40 | + add_action('site-reviews/review/created', function ($review) { |
|
41 | + if (has_action('site-reviews/local/review/create')) { |
|
42 | + glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
|
43 | + do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
44 | + } |
|
45 | + }, 9); |
|
46 | 46 | |
47 | - // Handlers/CreateReview.php |
|
48 | - add_action('site-reviews/review/submitted', function ($review) { |
|
49 | - if (has_action('site-reviews/local/review/submitted')) { |
|
50 | - glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
|
51 | - do_action('site-reviews/local/review/submitted', null, $review); |
|
52 | - } |
|
53 | - if (has_filter('site-reviews/local/review/submitted/message')) { |
|
54 | - glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
|
55 | - } |
|
56 | - }, 9); |
|
47 | + // Handlers/CreateReview.php |
|
48 | + add_action('site-reviews/review/submitted', function ($review) { |
|
49 | + if (has_action('site-reviews/local/review/submitted')) { |
|
50 | + glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
|
51 | + do_action('site-reviews/local/review/submitted', null, $review); |
|
52 | + } |
|
53 | + if (has_filter('site-reviews/local/review/submitted/message')) { |
|
54 | + glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
|
55 | + } |
|
56 | + }, 9); |
|
57 | 57 | |
58 | - // Database/ReviewManager.php |
|
59 | - add_filter('site-reviews/create/review-values', function ($values, $command) { |
|
60 | - if (has_filter('site-reviews/local/review')) { |
|
61 | - glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
|
62 | - return apply_filters('site-reviews/local/review', $values, $command); |
|
63 | - } |
|
64 | - return $values; |
|
65 | - }, 9, 2); |
|
58 | + // Database/ReviewManager.php |
|
59 | + add_filter('site-reviews/create/review-values', function ($values, $command) { |
|
60 | + if (has_filter('site-reviews/local/review')) { |
|
61 | + glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
|
62 | + return apply_filters('site-reviews/local/review', $values, $command); |
|
63 | + } |
|
64 | + return $values; |
|
65 | + }, 9, 2); |
|
66 | 66 | |
67 | - // Handlers/EnqueuePublicAssets.php |
|
68 | - add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
|
69 | - if (has_filter('site-reviews/enqueue/localize')) { |
|
70 | - glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
|
71 | - return apply_filters('site-reviews/enqueue/localize', $variables); |
|
72 | - } |
|
73 | - return $variables; |
|
74 | - }, 9); |
|
67 | + // Handlers/EnqueuePublicAssets.php |
|
68 | + add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
|
69 | + if (has_filter('site-reviews/enqueue/localize')) { |
|
70 | + glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
|
71 | + return apply_filters('site-reviews/enqueue/localize', $variables); |
|
72 | + } |
|
73 | + return $variables; |
|
74 | + }, 9); |
|
75 | 75 | |
76 | - // Modules/Rating.php |
|
77 | - add_filter('site-reviews/rating/average', function ($average) { |
|
78 | - if (has_filter('site-reviews/average/rating')) { |
|
79 | - glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
|
80 | - } |
|
81 | - return $average; |
|
82 | - }, 9); |
|
76 | + // Modules/Rating.php |
|
77 | + add_filter('site-reviews/rating/average', function ($average) { |
|
78 | + if (has_filter('site-reviews/average/rating')) { |
|
79 | + glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
|
80 | + } |
|
81 | + return $average; |
|
82 | + }, 9); |
|
83 | 83 | |
84 | - // Modules/Rating.php |
|
85 | - add_filter('site-reviews/rating/ranking', function ($ranking) { |
|
86 | - if (has_filter('site-reviews/bayesian/ranking')) { |
|
87 | - glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
|
88 | - } |
|
89 | - return $ranking; |
|
90 | - }, 9); |
|
84 | + // Modules/Rating.php |
|
85 | + add_filter('site-reviews/rating/ranking', function ($ranking) { |
|
86 | + if (has_filter('site-reviews/bayesian/ranking')) { |
|
87 | + glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
|
88 | + } |
|
89 | + return $ranking; |
|
90 | + }, 9); |
|
91 | 91 | |
92 | - // Modules/Html/Partials/SiteReviews.php |
|
93 | - add_filter('site-reviews/review/build/after', function ($renderedFields) { |
|
94 | - if (has_filter('site-reviews/reviews/review/text')) { |
|
95 | - glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
96 | - } |
|
97 | - if (has_filter('site-reviews/reviews/review/title')) { |
|
98 | - glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
99 | - } |
|
100 | - return $renderedFields; |
|
101 | - }, 9); |
|
92 | + // Modules/Html/Partials/SiteReviews.php |
|
93 | + add_filter('site-reviews/review/build/after', function ($renderedFields) { |
|
94 | + if (has_filter('site-reviews/reviews/review/text')) { |
|
95 | + glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
96 | + } |
|
97 | + if (has_filter('site-reviews/reviews/review/title')) { |
|
98 | + glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
|
99 | + } |
|
100 | + return $renderedFields; |
|
101 | + }, 9); |
|
102 | 102 | |
103 | - // Modules/Html/Partials/SiteReviews.php |
|
104 | - add_filter('site-reviews/review/build/before', function ($review) { |
|
105 | - if (has_filter('site-reviews/rendered/review')) { |
|
106 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
|
107 | - } |
|
108 | - if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
109 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
110 | - } |
|
111 | - if (has_filter('site-reviews/rendered/review/order')) { |
|
112 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
113 | - } |
|
114 | - if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
115 | - glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
|
116 | - } |
|
117 | - if (has_filter('site-reviews/reviews/navigation_links')) { |
|
118 | - glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
|
119 | - } |
|
120 | - return $review; |
|
121 | - }, 9); |
|
103 | + // Modules/Html/Partials/SiteReviews.php |
|
104 | + add_filter('site-reviews/review/build/before', function ($review) { |
|
105 | + if (has_filter('site-reviews/rendered/review')) { |
|
106 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.'; |
|
107 | + } |
|
108 | + if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
109 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
110 | + } |
|
111 | + if (has_filter('site-reviews/rendered/review/order')) { |
|
112 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
|
113 | + } |
|
114 | + if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
115 | + glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).'; |
|
116 | + } |
|
117 | + if (has_filter('site-reviews/reviews/navigation_links')) { |
|
118 | + glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
|
119 | + } |
|
120 | + return $review; |
|
121 | + }, 9); |
|
122 | 122 | |
123 | - add_filter('site-reviews/validate/custom', function ($result, $request) { |
|
124 | - if (has_filter('site-reviews/validate/review/submission')) { |
|
125 | - glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
126 | - return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
127 | - } |
|
128 | - return $result; |
|
129 | - }, 9, 2); |
|
123 | + add_filter('site-reviews/validate/custom', function ($result, $request) { |
|
124 | + if (has_filter('site-reviews/validate/review/submission')) { |
|
125 | + glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
126 | + return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
127 | + } |
|
128 | + return $result; |
|
129 | + }, 9, 2); |
|
130 | 130 | |
131 | - add_filter('site-reviews/views/file', function ($file, $view, $data) { |
|
132 | - if (has_filter('site-reviews/addon/views/file')) { |
|
133 | - glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
|
134 | - $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
135 | - } |
|
136 | - return $file; |
|
137 | - }, 9, 3); |
|
131 | + add_filter('site-reviews/views/file', function ($file, $view, $data) { |
|
132 | + if (has_filter('site-reviews/addon/views/file')) { |
|
133 | + glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
|
134 | + $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
135 | + } |
|
136 | + return $file; |
|
137 | + }, 9, 3); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | add_action('wp_footer', function () { |
141 | - $notices = array_keys(array_flip(glsr()->deprecated)); |
|
142 | - natsort($notices); |
|
143 | - foreach ($notices as $notice) { |
|
144 | - glsr_log()->warning($notice); |
|
145 | - } |
|
141 | + $notices = array_keys(array_flip(glsr()->deprecated)); |
|
142 | + natsort($notices); |
|
143 | + foreach ($notices as $notice) { |
|
144 | + glsr_log()->warning($notice); |
|
145 | + } |
|
146 | 146 | }); |
@@ -6,26 +6,26 @@ |
||
6 | 6 | <p><?= __('Add-ons extend the functionality of Site Reviews.', 'site-reviews'); ?></p> |
7 | 7 | <div class="glsr-addons wp-clearfix"> |
8 | 8 | <?php |
9 | - $template->render('partials/addons/addon', [ |
|
10 | - 'beta' => false, |
|
11 | - 'context' => [ |
|
12 | - 'description' => __('This add-on allows your site visitors to filter, search, and sort your reviews. Apply now to test the unreleased beta version.', 'site-reviews'), |
|
13 | - 'link' => 'https://niftyplugins.com/plugins/filters/', |
|
14 | - 'slug' => 'filters', |
|
15 | - 'title' => 'Filters', |
|
16 | - ], |
|
17 | - 'plugin' => 'site-reviews-filters/site-reviews-filters.php', |
|
18 | - ]); |
|
19 | - $template->render('partials/addons/addon', [ |
|
20 | - 'beta' => true, |
|
21 | - 'context' => [ |
|
22 | - 'description' => __('This add-on allows your site visitors to submit images with their reviews. Apply now to test the unreleased beta version.', 'site-reviews'), |
|
23 | - 'link' => 'https://niftyplugins.com/plugins/images/', |
|
24 | - 'slug' => 'images', |
|
25 | - 'title' => 'Images', |
|
26 | - ], |
|
27 | - 'plugin' => 'site-reviews-images/site-reviews-images.php', |
|
28 | - ]); |
|
29 | - ?> |
|
9 | + $template->render('partials/addons/addon', [ |
|
10 | + 'beta' => false, |
|
11 | + 'context' => [ |
|
12 | + 'description' => __('This add-on allows your site visitors to filter, search, and sort your reviews. Apply now to test the unreleased beta version.', 'site-reviews'), |
|
13 | + 'link' => 'https://niftyplugins.com/plugins/filters/', |
|
14 | + 'slug' => 'filters', |
|
15 | + 'title' => 'Filters', |
|
16 | + ], |
|
17 | + 'plugin' => 'site-reviews-filters/site-reviews-filters.php', |
|
18 | + ]); |
|
19 | + $template->render('partials/addons/addon', [ |
|
20 | + 'beta' => true, |
|
21 | + 'context' => [ |
|
22 | + 'description' => __('This add-on allows your site visitors to submit images with their reviews. Apply now to test the unreleased beta version.', 'site-reviews'), |
|
23 | + 'link' => 'https://niftyplugins.com/plugins/images/', |
|
24 | + 'slug' => 'images', |
|
25 | + 'title' => 'Images', |
|
26 | + ], |
|
27 | + 'plugin' => 'site-reviews-images/site-reviews-images.php', |
|
28 | + ]); |
|
29 | + ?> |
|
30 | 30 | </div> |
31 | 31 | </div> |
@@ -8,218 +8,218 @@ |
||
8 | 8 | |
9 | 9 | class Helper |
10 | 10 | { |
11 | - /** |
|
12 | - * @param string $name |
|
13 | - * @param string $path |
|
14 | - * @return string |
|
15 | - */ |
|
16 | - public static function buildClassName($name, $path = '') |
|
17 | - { |
|
18 | - $className = Str::camelCase($name); |
|
19 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
20 | - return !empty($path) |
|
21 | - ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
22 | - : $className; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @param string $name |
|
27 | - * @param string $prefix |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public static function buildMethodName($name, $prefix = '') |
|
31 | - { |
|
32 | - return lcfirst($prefix.static::buildClassName($name)); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @param string $name |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public static function buildPropertyName($name) |
|
40 | - { |
|
41 | - return static::buildMethodName($name); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param string $cast |
|
46 | - * @param mixed $value |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public static function castTo($cast = '', $value) |
|
50 | - { |
|
51 | - $method = static::buildMethodName($cast, 'castTo'); |
|
52 | - return !empty($cast) && method_exists(__CLASS__, $method) |
|
53 | - ? static::$method($value) |
|
54 | - : $value; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param mixed $value |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public static function castToArray($value) |
|
62 | - { |
|
63 | - return (array) $value; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @param mixed $value |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public static function castToBool($value) |
|
71 | - { |
|
72 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param mixed $value |
|
77 | - * @return float |
|
78 | - */ |
|
79 | - public static function castToFloat($value) |
|
80 | - { |
|
81 | - return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param mixed $value |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public static function castToInt($value) |
|
89 | - { |
|
90 | - return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param mixed $value |
|
95 | - * @return object |
|
96 | - */ |
|
97 | - public static function castToObject($value) |
|
98 | - { |
|
99 | - return (object) (array) $value; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param mixed $value |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public static function castToString($value) |
|
107 | - { |
|
108 | - if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
109 | - return (string) $value->__toString(); |
|
110 | - } |
|
111 | - if (is_array($value) || is_object($value)) { |
|
112 | - return serialize($value); |
|
113 | - } |
|
114 | - return (string) $value; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $key |
|
119 | - * @return mixed |
|
120 | - */ |
|
121 | - public static function filterInput($key, array $request = []) |
|
122 | - { |
|
123 | - if (isset($request[$key])) { |
|
124 | - return $request[$key]; |
|
125 | - } |
|
126 | - $variable = filter_input(INPUT_POST, $key); |
|
127 | - if (is_null($variable) && isset($_POST[$key])) { |
|
128 | - $variable = $_POST[$key]; |
|
129 | - } |
|
130 | - return $variable; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $key |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public static function filterInputArray($key) |
|
138 | - { |
|
139 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
140 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
141 | - $variable = $_POST[$key]; |
|
142 | - } |
|
143 | - return (array) $variable; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public static function getIpAddress() |
|
150 | - { |
|
151 | - $whitelist = []; |
|
152 | - $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
153 | - if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
154 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
155 | - $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
|
156 | - if (defined('AF_INET6')) { |
|
157 | - $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
|
158 | - } |
|
159 | - } |
|
160 | - $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
161 | - $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
162 | - $whip = new Whip($methods, $whitelist); |
|
163 | - do_action_ref_array('site-reviews/whip', [$whip]); |
|
164 | - if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
165 | - return (string) $clientAddress; |
|
166 | - } |
|
167 | - glsr_log()->error('Unable to detect IP address, please see the FAQ page for a possible solution.'); |
|
168 | - return 'unknown'; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param mixed $value |
|
173 | - * @param string|int $min |
|
174 | - * @param string|int $max |
|
175 | - * @return bool |
|
176 | - */ |
|
177 | - public static function inRange($value, $min, $max) |
|
178 | - { |
|
179 | - $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | - 'min_range' => intval($min), |
|
181 | - 'max_range' => intval($max), |
|
182 | - ]]); |
|
183 | - return false !== $inRange; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @param int|string $value |
|
188 | - * @param int|string $compareWithValue |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public static function isGreaterThan($value, $compareWithValue) |
|
192 | - { |
|
193 | - return version_compare($value, $compareWithValue, '>'); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param int|string $value |
|
198 | - * @param int|string $compareWithValue |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public static function isGreaterThanOrEqual($value, $compareWithValue) |
|
202 | - { |
|
203 | - return version_compare($value, $compareWithValue, '>='); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param int|string $value |
|
208 | - * @param int|string $compareWithValue |
|
209 | - * @return bool |
|
210 | - */ |
|
211 | - public static function isLessThan($value, $compareWithValue) |
|
212 | - { |
|
213 | - return version_compare($value, $compareWithValue, '<'); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @param int|string $value |
|
218 | - * @param int|string $compareWithValue |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public static function isLessThanOrEqual($value, $compareWithValue) |
|
222 | - { |
|
223 | - return version_compare($value, $compareWithValue, '<='); |
|
224 | - } |
|
11 | + /** |
|
12 | + * @param string $name |
|
13 | + * @param string $path |
|
14 | + * @return string |
|
15 | + */ |
|
16 | + public static function buildClassName($name, $path = '') |
|
17 | + { |
|
18 | + $className = Str::camelCase($name); |
|
19 | + $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
20 | + return !empty($path) |
|
21 | + ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
22 | + : $className; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @param string $name |
|
27 | + * @param string $prefix |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public static function buildMethodName($name, $prefix = '') |
|
31 | + { |
|
32 | + return lcfirst($prefix.static::buildClassName($name)); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @param string $name |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public static function buildPropertyName($name) |
|
40 | + { |
|
41 | + return static::buildMethodName($name); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param string $cast |
|
46 | + * @param mixed $value |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public static function castTo($cast = '', $value) |
|
50 | + { |
|
51 | + $method = static::buildMethodName($cast, 'castTo'); |
|
52 | + return !empty($cast) && method_exists(__CLASS__, $method) |
|
53 | + ? static::$method($value) |
|
54 | + : $value; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param mixed $value |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public static function castToArray($value) |
|
62 | + { |
|
63 | + return (array) $value; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @param mixed $value |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public static function castToBool($value) |
|
71 | + { |
|
72 | + return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param mixed $value |
|
77 | + * @return float |
|
78 | + */ |
|
79 | + public static function castToFloat($value) |
|
80 | + { |
|
81 | + return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param mixed $value |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public static function castToInt($value) |
|
89 | + { |
|
90 | + return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param mixed $value |
|
95 | + * @return object |
|
96 | + */ |
|
97 | + public static function castToObject($value) |
|
98 | + { |
|
99 | + return (object) (array) $value; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param mixed $value |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public static function castToString($value) |
|
107 | + { |
|
108 | + if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
109 | + return (string) $value->__toString(); |
|
110 | + } |
|
111 | + if (is_array($value) || is_object($value)) { |
|
112 | + return serialize($value); |
|
113 | + } |
|
114 | + return (string) $value; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $key |
|
119 | + * @return mixed |
|
120 | + */ |
|
121 | + public static function filterInput($key, array $request = []) |
|
122 | + { |
|
123 | + if (isset($request[$key])) { |
|
124 | + return $request[$key]; |
|
125 | + } |
|
126 | + $variable = filter_input(INPUT_POST, $key); |
|
127 | + if (is_null($variable) && isset($_POST[$key])) { |
|
128 | + $variable = $_POST[$key]; |
|
129 | + } |
|
130 | + return $variable; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $key |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public static function filterInputArray($key) |
|
138 | + { |
|
139 | + $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
140 | + if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
141 | + $variable = $_POST[$key]; |
|
142 | + } |
|
143 | + return (array) $variable; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public static function getIpAddress() |
|
150 | + { |
|
151 | + $whitelist = []; |
|
152 | + $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
153 | + if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
154 | + $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
155 | + $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
|
156 | + if (defined('AF_INET6')) { |
|
157 | + $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
|
158 | + } |
|
159 | + } |
|
160 | + $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
161 | + $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
162 | + $whip = new Whip($methods, $whitelist); |
|
163 | + do_action_ref_array('site-reviews/whip', [$whip]); |
|
164 | + if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
165 | + return (string) $clientAddress; |
|
166 | + } |
|
167 | + glsr_log()->error('Unable to detect IP address, please see the FAQ page for a possible solution.'); |
|
168 | + return 'unknown'; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param mixed $value |
|
173 | + * @param string|int $min |
|
174 | + * @param string|int $max |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | + public static function inRange($value, $min, $max) |
|
178 | + { |
|
179 | + $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | + 'min_range' => intval($min), |
|
181 | + 'max_range' => intval($max), |
|
182 | + ]]); |
|
183 | + return false !== $inRange; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @param int|string $value |
|
188 | + * @param int|string $compareWithValue |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public static function isGreaterThan($value, $compareWithValue) |
|
192 | + { |
|
193 | + return version_compare($value, $compareWithValue, '>'); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param int|string $value |
|
198 | + * @param int|string $compareWithValue |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public static function isGreaterThanOrEqual($value, $compareWithValue) |
|
202 | + { |
|
203 | + return version_compare($value, $compareWithValue, '>='); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param int|string $value |
|
208 | + * @param int|string $compareWithValue |
|
209 | + * @return bool |
|
210 | + */ |
|
211 | + public static function isLessThan($value, $compareWithValue) |
|
212 | + { |
|
213 | + return version_compare($value, $compareWithValue, '<'); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @param int|string $value |
|
218 | + * @param int|string $compareWithValue |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public static function isLessThanOrEqual($value, $compareWithValue) |
|
222 | + { |
|
223 | + return version_compare($value, $compareWithValue, '<='); |
|
224 | + } |
|
225 | 225 | } |
@@ -13,294 +13,294 @@ |
||
13 | 13 | |
14 | 14 | class SiteReviewsForm implements PartialContract |
15 | 15 | { |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected $args; |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected $args; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $errors; |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $errors; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected $message; |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected $message; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $required; |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $required; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $values; |
|
36 | + /** |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $values; |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritdoc} |
|
43 | - */ |
|
44 | - public function build(array $args = []) |
|
45 | - { |
|
46 | - $this->args = $args; |
|
47 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
48 | - return $this->buildLoginRegister(); |
|
49 | - } |
|
50 | - $this->errors = glsr()->sessionGet($args['id'].'errors', []); |
|
51 | - $this->message = glsr()->sessionGet($args['id'].'message', ''); |
|
52 | - $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []); |
|
53 | - $this->values = glsr()->sessionGet($args['id'].'values', []); |
|
54 | - $fields = array_reduce($this->getFields(), function ($carry, $field) { |
|
55 | - return $carry.$field; |
|
56 | - }); |
|
57 | - return glsr(Template::class)->build('templates/reviews-form', [ |
|
58 | - 'args' => $args, |
|
59 | - 'context' => [ |
|
60 | - 'class' => $this->getClass(), |
|
61 | - 'fields' => $fields, |
|
62 | - 'id' => $this->args['id'], |
|
63 | - 'response' => $this->buildResponse(), |
|
64 | - 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(), |
|
65 | - ], |
|
66 | - ]); |
|
67 | - } |
|
41 | + /** |
|
42 | + * {@inheritdoc} |
|
43 | + */ |
|
44 | + public function build(array $args = []) |
|
45 | + { |
|
46 | + $this->args = $args; |
|
47 | + if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
48 | + return $this->buildLoginRegister(); |
|
49 | + } |
|
50 | + $this->errors = glsr()->sessionGet($args['id'].'errors', []); |
|
51 | + $this->message = glsr()->sessionGet($args['id'].'message', ''); |
|
52 | + $this->required = glsr(OptionManager::class)->get('settings.submissions.required', []); |
|
53 | + $this->values = glsr()->sessionGet($args['id'].'values', []); |
|
54 | + $fields = array_reduce($this->getFields(), function ($carry, $field) { |
|
55 | + return $carry.$field; |
|
56 | + }); |
|
57 | + return glsr(Template::class)->build('templates/reviews-form', [ |
|
58 | + 'args' => $args, |
|
59 | + 'context' => [ |
|
60 | + 'class' => $this->getClass(), |
|
61 | + 'fields' => $fields, |
|
62 | + 'id' => $this->args['id'], |
|
63 | + 'response' => $this->buildResponse(), |
|
64 | + 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(), |
|
65 | + ], |
|
66 | + ]); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - protected function buildLoginRegister() |
|
73 | - { |
|
74 | - return glsr(Template::class)->build('templates/login-register', [ |
|
75 | - 'context' => [ |
|
76 | - 'text' => trim($this->getLoginText().' '.$this->getRegisterText()), |
|
77 | - ], |
|
78 | - ]); |
|
79 | - } |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + protected function buildLoginRegister() |
|
73 | + { |
|
74 | + return glsr(Template::class)->build('templates/login-register', [ |
|
75 | + 'context' => [ |
|
76 | + 'text' => trim($this->getLoginText().' '.$this->getRegisterText()), |
|
77 | + ], |
|
78 | + ]); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return void|string |
|
83 | - */ |
|
84 | - protected function buildRecaptcha() |
|
85 | - { |
|
86 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
87 | - return; |
|
88 | - } |
|
89 | - return glsr(Builder::class)->div([ |
|
90 | - 'class' => 'glsr-recaptcha-holder', |
|
91 | - 'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'), |
|
92 | - 'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')), |
|
93 | - 'data-size' => 'invisible', |
|
94 | - ]); |
|
95 | - } |
|
81 | + /** |
|
82 | + * @return void|string |
|
83 | + */ |
|
84 | + protected function buildRecaptcha() |
|
85 | + { |
|
86 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
87 | + return; |
|
88 | + } |
|
89 | + return glsr(Builder::class)->div([ |
|
90 | + 'class' => 'glsr-recaptcha-holder', |
|
91 | + 'data-badge' => glsr(OptionManager::class)->get('settings.submissions.recaptcha.position'), |
|
92 | + 'data-sitekey' => sanitize_text_field(glsr(OptionManager::class)->get('settings.submissions.recaptcha.key')), |
|
93 | + 'data-size' => 'invisible', |
|
94 | + ]); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - protected function buildResponse() |
|
101 | - { |
|
102 | - $classes = !empty($this->errors) |
|
103 | - ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class'] |
|
104 | - : ''; |
|
105 | - return glsr(Template::class)->build('templates/form/response', [ |
|
106 | - 'context' => [ |
|
107 | - 'class' => $classes, |
|
108 | - 'message' => wpautop($this->message), |
|
109 | - ], |
|
110 | - 'has_errors' => !empty($this->errors), |
|
111 | - ]); |
|
112 | - } |
|
97 | + /** |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + protected function buildResponse() |
|
101 | + { |
|
102 | + $classes = !empty($this->errors) |
|
103 | + ? glsr(StyleValidationDefaults::class)->defaults()['message_error_class'] |
|
104 | + : ''; |
|
105 | + return glsr(Template::class)->build('templates/form/response', [ |
|
106 | + 'context' => [ |
|
107 | + 'class' => $classes, |
|
108 | + 'message' => wpautop($this->message), |
|
109 | + ], |
|
110 | + 'has_errors' => !empty($this->errors), |
|
111 | + ]); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - protected function buildSubmitButton() |
|
118 | - { |
|
119 | - return glsr(Template::class)->build('templates/form/submit-button', [ |
|
120 | - 'context' => [ |
|
121 | - 'text' => __('Submit your review', 'site-reviews'), |
|
122 | - ], |
|
123 | - ]); |
|
124 | - } |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + protected function buildSubmitButton() |
|
118 | + { |
|
119 | + return glsr(Template::class)->build('templates/form/submit-button', [ |
|
120 | + 'context' => [ |
|
121 | + 'text' => __('Submit your review', 'site-reviews'), |
|
122 | + ], |
|
123 | + ]); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - protected function getClass() |
|
130 | - { |
|
131 | - return trim('glsr-form '.$this->args['class']); |
|
132 | - } |
|
126 | + /** |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + protected function getClass() |
|
130 | + { |
|
131 | + return trim('glsr-form '.$this->args['class']); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - protected function getFields() |
|
138 | - { |
|
139 | - $hiddenFields = $this->getHiddenFields(); |
|
140 | - $hiddenFields[] = $this->getHoneypotField(); |
|
141 | - $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form')); |
|
142 | - $paths = array_map(function ($obj) { |
|
143 | - return $obj->field['path']; |
|
144 | - }, $hiddenFields); |
|
145 | - foreach ($fields as $field) { |
|
146 | - $index = array_search($field->field['path'], $paths); |
|
147 | - if (false === $index) { |
|
148 | - continue; |
|
149 | - } |
|
150 | - unset($hiddenFields[$index]); |
|
151 | - } |
|
152 | - return array_merge($hiddenFields, $fields); |
|
153 | - } |
|
134 | + /** |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + protected function getFields() |
|
138 | + { |
|
139 | + $hiddenFields = $this->getHiddenFields(); |
|
140 | + $hiddenFields[] = $this->getHoneypotField(); |
|
141 | + $fields = $this->normalizeFields(glsr(Form::class)->getFields('submission-form')); |
|
142 | + $paths = array_map(function ($obj) { |
|
143 | + return $obj->field['path']; |
|
144 | + }, $hiddenFields); |
|
145 | + foreach ($fields as $field) { |
|
146 | + $index = array_search($field->field['path'], $paths); |
|
147 | + if (false === $index) { |
|
148 | + continue; |
|
149 | + } |
|
150 | + unset($hiddenFields[$index]); |
|
151 | + } |
|
152 | + return array_merge($hiddenFields, $fields); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - protected function getLoginText() |
|
159 | - { |
|
160 | - $loginLink = glsr(Builder::class)->a([ |
|
161 | - 'href' => wp_login_url(strval(get_permalink())), |
|
162 | - 'text' => __('logged in', 'site-reviews'), |
|
163 | - ]); |
|
164 | - return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink); |
|
165 | - } |
|
155 | + /** |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + protected function getLoginText() |
|
159 | + { |
|
160 | + $loginLink = glsr(Builder::class)->a([ |
|
161 | + 'href' => wp_login_url(strval(get_permalink())), |
|
162 | + 'text' => __('logged in', 'site-reviews'), |
|
163 | + ]); |
|
164 | + return sprintf(__('You must be %s to submit a review.', 'site-reviews'), $loginLink); |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @return void|string |
|
169 | - */ |
|
170 | - protected function getRegisterText() |
|
171 | - { |
|
172 | - if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
173 | - return; |
|
174 | - } |
|
175 | - $registerLink = glsr(Builder::class)->a([ |
|
176 | - 'href' => wp_registration_url(), |
|
177 | - 'text' => __('register', 'site-reviews'), |
|
178 | - ]); |
|
179 | - return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink); |
|
180 | - } |
|
167 | + /** |
|
168 | + * @return void|string |
|
169 | + */ |
|
170 | + protected function getRegisterText() |
|
171 | + { |
|
172 | + if (!get_option('users_can_register') || !glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
173 | + return; |
|
174 | + } |
|
175 | + $registerLink = glsr(Builder::class)->a([ |
|
176 | + 'href' => wp_registration_url(), |
|
177 | + 'text' => __('register', 'site-reviews'), |
|
178 | + ]); |
|
179 | + return sprintf(__('You may also %s for an account.', 'site-reviews'), $registerLink); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * @return array |
|
184 | - */ |
|
185 | - protected function getHiddenFields() |
|
186 | - { |
|
187 | - $fields = [[ |
|
188 | - 'name' => '_action', |
|
189 | - 'value' => 'submit-review', |
|
190 | - ], [ |
|
191 | - 'name' => '_counter', |
|
192 | - ], [ |
|
193 | - 'name' => '_nonce', |
|
194 | - 'value' => wp_create_nonce('submit-review'), |
|
195 | - ], [ |
|
196 | - 'name' => '_post_id', |
|
197 | - 'value' => get_the_ID(), |
|
198 | - ], [ |
|
199 | - 'name' => '_referer', |
|
200 | - 'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')), |
|
201 | - ], [ |
|
202 | - 'name' => 'assign_to', |
|
203 | - 'value' => $this->args['assign_to'], |
|
204 | - ], [ |
|
205 | - 'name' => 'category', |
|
206 | - 'value' => $this->args['category'], |
|
207 | - ], [ |
|
208 | - 'name' => 'excluded', |
|
209 | - 'value' => $this->args['hide'], |
|
210 | - ], [ |
|
211 | - 'name' => 'form_id', |
|
212 | - 'value' => $this->args['id'], |
|
213 | - ]]; |
|
214 | - return array_map(function ($field) { |
|
215 | - return new Field(wp_parse_args($field, ['type' => 'hidden'])); |
|
216 | - }, $fields); |
|
217 | - } |
|
182 | + /** |
|
183 | + * @return array |
|
184 | + */ |
|
185 | + protected function getHiddenFields() |
|
186 | + { |
|
187 | + $fields = [[ |
|
188 | + 'name' => '_action', |
|
189 | + 'value' => 'submit-review', |
|
190 | + ], [ |
|
191 | + 'name' => '_counter', |
|
192 | + ], [ |
|
193 | + 'name' => '_nonce', |
|
194 | + 'value' => wp_create_nonce('submit-review'), |
|
195 | + ], [ |
|
196 | + 'name' => '_post_id', |
|
197 | + 'value' => get_the_ID(), |
|
198 | + ], [ |
|
199 | + 'name' => '_referer', |
|
200 | + 'value' => wp_unslash(filter_input(INPUT_SERVER, 'REQUEST_URI')), |
|
201 | + ], [ |
|
202 | + 'name' => 'assign_to', |
|
203 | + 'value' => $this->args['assign_to'], |
|
204 | + ], [ |
|
205 | + 'name' => 'category', |
|
206 | + 'value' => $this->args['category'], |
|
207 | + ], [ |
|
208 | + 'name' => 'excluded', |
|
209 | + 'value' => $this->args['hide'], |
|
210 | + ], [ |
|
211 | + 'name' => 'form_id', |
|
212 | + 'value' => $this->args['id'], |
|
213 | + ]]; |
|
214 | + return array_map(function ($field) { |
|
215 | + return new Field(wp_parse_args($field, ['type' => 'hidden'])); |
|
216 | + }, $fields); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @return Field |
|
221 | - */ |
|
222 | - protected function getHoneypotField() |
|
223 | - { |
|
224 | - return new Field([ |
|
225 | - 'name' => 'gotcha', |
|
226 | - 'type' => 'honeypot', |
|
227 | - ]); |
|
228 | - } |
|
219 | + /** |
|
220 | + * @return Field |
|
221 | + */ |
|
222 | + protected function getHoneypotField() |
|
223 | + { |
|
224 | + return new Field([ |
|
225 | + 'name' => 'gotcha', |
|
226 | + 'type' => 'honeypot', |
|
227 | + ]); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - protected function normalizeFieldId(Field &$field) |
|
234 | - { |
|
235 | - if (empty($this->args['id']) || empty($field->field['id'])) { |
|
236 | - return; |
|
237 | - } |
|
238 | - $field->field['id'].= '-'.$this->args['id']; |
|
239 | - } |
|
230 | + /** |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + protected function normalizeFieldId(Field &$field) |
|
234 | + { |
|
235 | + if (empty($this->args['id']) || empty($field->field['id'])) { |
|
236 | + return; |
|
237 | + } |
|
238 | + $field->field['id'].= '-'.$this->args['id']; |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - protected function normalizeFieldClass(Field &$field) |
|
245 | - { |
|
246 | - $field->field['class'] = trim(Arr::get($field->field, 'class').' glsr-field-control'); |
|
247 | - } |
|
241 | + /** |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + protected function normalizeFieldClass(Field &$field) |
|
245 | + { |
|
246 | + $field->field['class'] = trim(Arr::get($field->field, 'class').' glsr-field-control'); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * @return void |
|
251 | - */ |
|
252 | - protected function normalizeFieldErrors(Field &$field) |
|
253 | - { |
|
254 | - if (!array_key_exists($field->field['path'], $this->errors)) { |
|
255 | - return; |
|
256 | - } |
|
257 | - $field->field['errors'] = $this->errors[$field->field['path']]; |
|
258 | - } |
|
249 | + /** |
|
250 | + * @return void |
|
251 | + */ |
|
252 | + protected function normalizeFieldErrors(Field &$field) |
|
253 | + { |
|
254 | + if (!array_key_exists($field->field['path'], $this->errors)) { |
|
255 | + return; |
|
256 | + } |
|
257 | + $field->field['errors'] = $this->errors[$field->field['path']]; |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - protected function normalizeFieldRequired(Field &$field) |
|
264 | - { |
|
265 | - if (!in_array($field->field['path'], $this->required)) { |
|
266 | - return; |
|
267 | - } |
|
268 | - $field->field['required'] = true; |
|
269 | - } |
|
260 | + /** |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + protected function normalizeFieldRequired(Field &$field) |
|
264 | + { |
|
265 | + if (!in_array($field->field['path'], $this->required)) { |
|
266 | + return; |
|
267 | + } |
|
268 | + $field->field['required'] = true; |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * @return array |
|
273 | - */ |
|
274 | - protected function normalizeFields($fields) |
|
275 | - { |
|
276 | - $normalizedFields = []; |
|
277 | - foreach ($fields as $field) { |
|
278 | - if (in_array($field->field['path'], $this->args['hide'])) { |
|
279 | - continue; |
|
280 | - } |
|
281 | - $field->field['is_public'] = true; |
|
282 | - $this->normalizeFieldClass($field); |
|
283 | - $this->normalizeFieldErrors($field); |
|
284 | - $this->normalizeFieldRequired($field); |
|
285 | - $this->normalizeFieldValue($field); |
|
286 | - $this->normalizeFieldId($field); |
|
287 | - $normalizedFields[] = $field; |
|
288 | - } |
|
289 | - return $normalizedFields; |
|
290 | - } |
|
271 | + /** |
|
272 | + * @return array |
|
273 | + */ |
|
274 | + protected function normalizeFields($fields) |
|
275 | + { |
|
276 | + $normalizedFields = []; |
|
277 | + foreach ($fields as $field) { |
|
278 | + if (in_array($field->field['path'], $this->args['hide'])) { |
|
279 | + continue; |
|
280 | + } |
|
281 | + $field->field['is_public'] = true; |
|
282 | + $this->normalizeFieldClass($field); |
|
283 | + $this->normalizeFieldErrors($field); |
|
284 | + $this->normalizeFieldRequired($field); |
|
285 | + $this->normalizeFieldValue($field); |
|
286 | + $this->normalizeFieldId($field); |
|
287 | + $normalizedFields[] = $field; |
|
288 | + } |
|
289 | + return $normalizedFields; |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * @return void |
|
294 | - */ |
|
295 | - protected function normalizeFieldValue(Field &$field) |
|
296 | - { |
|
297 | - if (!array_key_exists($field->field['path'], $this->values)) { |
|
298 | - return; |
|
299 | - } |
|
300 | - if (in_array($field->field['type'], ['radio', 'checkbox'])) { |
|
301 | - $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
|
302 | - } else { |
|
303 | - $field->field['value'] = $this->values[$field->field['path']]; |
|
304 | - } |
|
305 | - } |
|
292 | + /** |
|
293 | + * @return void |
|
294 | + */ |
|
295 | + protected function normalizeFieldValue(Field &$field) |
|
296 | + { |
|
297 | + if (!array_key_exists($field->field['path'], $this->values)) { |
|
298 | + return; |
|
299 | + } |
|
300 | + if (in_array($field->field['type'], ['radio', 'checkbox'])) { |
|
301 | + $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
|
302 | + } else { |
|
303 | + $field->field['value'] = $this->values[$field->field['path']]; |
|
304 | + } |
|
305 | + } |
|
306 | 306 | } |
@@ -10,52 +10,52 @@ |
||
10 | 10 | |
11 | 11 | class Pagination implements PartialContract |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $args; |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $args; |
|
17 | 17 | |
18 | - /** |
|
19 | - * {@inheritdoc} |
|
20 | - */ |
|
21 | - public function build(array $args = []) |
|
22 | - { |
|
23 | - $this->args = $this->normalize($args); |
|
24 | - if ($this->args['total'] < 2) { |
|
25 | - return ''; |
|
26 | - } |
|
27 | - return glsr(Template::class)->build('templates/pagination', [ |
|
28 | - 'context' => [ |
|
29 | - 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
30 | - 'loader' => '<div class="glsr-loader"></div>', |
|
31 | - 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
32 | - ], |
|
33 | - ]); |
|
34 | - } |
|
18 | + /** |
|
19 | + * {@inheritdoc} |
|
20 | + */ |
|
21 | + public function build(array $args = []) |
|
22 | + { |
|
23 | + $this->args = $this->normalize($args); |
|
24 | + if ($this->args['total'] < 2) { |
|
25 | + return ''; |
|
26 | + } |
|
27 | + return glsr(Template::class)->build('templates/pagination', [ |
|
28 | + 'context' => [ |
|
29 | + 'links' => apply_filters('site-reviews/paginate_links', $this->buildLinks(), $this->args), |
|
30 | + 'loader' => '<div class="glsr-loader"></div>', |
|
31 | + 'screen_reader_text' => __('Site Reviews navigation', 'site-reviews'), |
|
32 | + ], |
|
33 | + ]); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected function buildLinks() |
|
40 | - { |
|
41 | - $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | - if ('array' == $args['type']) { |
|
43 | - $args['type'] = 'plain'; |
|
44 | - } |
|
45 | - return paginate_links($args); |
|
46 | - } |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected function buildLinks() |
|
40 | + { |
|
41 | + $args = glsr(Style::class)->paginationArgs($this->args); |
|
42 | + if ('array' == $args['type']) { |
|
43 | + $args['type'] = 'plain'; |
|
44 | + } |
|
45 | + return paginate_links($args); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - protected function normalize(array $args) |
|
52 | - { |
|
53 | - if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
54 | - $args['base'] = $baseUrl.'%_%'; |
|
55 | - } |
|
56 | - return wp_parse_args(array_filter($args), [ |
|
57 | - 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
58 | - 'total' => 1, |
|
59 | - ]); |
|
60 | - } |
|
48 | + /** |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + protected function normalize(array $args) |
|
52 | + { |
|
53 | + if ($baseUrl = Arr::get($args, 'baseUrl')) { |
|
54 | + $args['base'] = $baseUrl.'%_%'; |
|
55 | + } |
|
56 | + return wp_parse_args(array_filter($args), [ |
|
57 | + 'current' => glsr(QueryBuilder::class)->getPaged(), |
|
58 | + 'total' => 1, |
|
59 | + ]); |
|
60 | + } |
|
61 | 61 | } |
@@ -11,197 +11,197 @@ |
||
11 | 11 | |
12 | 12 | class SiteReviewsSummary implements PartialContract |
13 | 13 | { |
14 | - /** |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $args; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var float |
|
21 | - */ |
|
22 | - protected $averageRating; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected $ratingCounts; |
|
28 | - |
|
29 | - /** |
|
30 | - * {@inheritdoc} |
|
31 | - */ |
|
32 | - public function build(array $args = []) |
|
33 | - { |
|
34 | - $this->args = $args; |
|
35 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args); |
|
36 | - if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) { |
|
37 | - return ''; |
|
38 | - } |
|
39 | - $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts); |
|
40 | - $this->generateSchema(); |
|
41 | - return glsr(Template::class)->build('templates/reviews-summary', [ |
|
42 | - 'context' => [ |
|
43 | - 'assigned_to' => $this->args['assigned_to'], |
|
44 | - 'category' => $this->args['category'], |
|
45 | - 'class' => $this->getClass(), |
|
46 | - 'id' => $this->args['id'], |
|
47 | - 'percentages' => $this->buildPercentage(), |
|
48 | - 'rating' => $this->buildRating(), |
|
49 | - 'stars' => $this->buildStars(), |
|
50 | - 'text' => $this->buildText(), |
|
51 | - ], |
|
52 | - ]); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @return void|string |
|
57 | - */ |
|
58 | - protected function buildPercentage() |
|
59 | - { |
|
60 | - if ($this->isHidden('bars')) { |
|
61 | - return; |
|
62 | - } |
|
63 | - $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts)); |
|
64 | - $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) { |
|
65 | - $label = $this->buildPercentageLabel($this->args['labels'][$level]); |
|
66 | - $background = $this->buildPercentageBackground($percentages[$level]); |
|
67 | - $count = apply_filters('site-reviews/summary/counts', |
|
68 | - $percentages[$level], |
|
69 | - $this->ratingCounts[$level] |
|
70 | - ); |
|
71 | - $percent = $this->buildPercentageCount($count); |
|
72 | - $value = $label.$background.$percent; |
|
73 | - $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [ |
|
74 | - 'percent' => wp_strip_all_tags($count, true), |
|
75 | - 'rating' => $level, |
|
76 | - ]); |
|
77 | - return $carry.glsr(Builder::class)->div($value, [ |
|
78 | - 'class' => 'glsr-bar', |
|
79 | - ]); |
|
80 | - }); |
|
81 | - return $this->wrap('percentage', $bars); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string $percent |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - protected function buildPercentageBackground($percent) |
|
89 | - { |
|
90 | - $backgroundPercent = glsr(Builder::class)->span([ |
|
91 | - 'class' => 'glsr-bar-background-percent', |
|
92 | - 'style' => 'width:'.$percent, |
|
93 | - ]); |
|
94 | - return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param string $count |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - protected function buildPercentageCount($count) |
|
102 | - { |
|
103 | - return '<span class="glsr-bar-percent">'.$count.'</span>'; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param string $label |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - protected function buildPercentageLabel($label) |
|
111 | - { |
|
112 | - return '<span class="glsr-bar-label">'.$label.'</span>'; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @return void|string |
|
117 | - */ |
|
118 | - protected function buildRating() |
|
119 | - { |
|
120 | - if ($this->isHidden('rating')) { |
|
121 | - return; |
|
122 | - } |
|
123 | - return $this->wrap('rating', '<span>'.$this->averageRating.'</span>'); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @return void|string |
|
128 | - */ |
|
129 | - protected function buildStars() |
|
130 | - { |
|
131 | - if ($this->isHidden('stars')) { |
|
132 | - return; |
|
133 | - } |
|
134 | - $stars = glsr_star_rating($this->averageRating); |
|
135 | - return $this->wrap('stars', $stars); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return void|string |
|
140 | - */ |
|
141 | - protected function buildText() |
|
142 | - { |
|
143 | - if ($this->isHidden('summary')) { |
|
144 | - return; |
|
145 | - } |
|
146 | - $count = intval(array_sum($this->ratingCounts)); |
|
147 | - if (empty($this->args['text'])) { |
|
148 | - // @todo document this change |
|
149 | - $this->args['text'] = _nx( |
|
150 | - '{rating} out of {max} stars (based on {num} review)', |
|
151 | - '{rating} out of {max} stars (based on {num} reviews)', |
|
152 | - $count, |
|
153 | - 'Do not translate {rating}, {max}, and {num}, they are template tags.', |
|
154 | - 'site-reviews' |
|
155 | - ); |
|
156 | - } |
|
157 | - $summary = str_replace( |
|
158 | - ['{rating}', '{max}', '{num}'], |
|
159 | - [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count], |
|
160 | - $this->args['text'] |
|
161 | - ); |
|
162 | - return $this->wrap('text', '<span>'.$summary.'</span>'); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - protected function generateSchema() |
|
169 | - { |
|
170 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
171 | - return; |
|
172 | - } |
|
173 | - glsr(Schema::class)->store( |
|
174 | - glsr(Schema::class)->buildSummary($this->args) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - protected function getClass() |
|
182 | - { |
|
183 | - return trim('glsr-summary '.$this->args['class']); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @param string $key |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - protected function isHidden($key) |
|
191 | - { |
|
192 | - return in_array($key, $this->args['hide']); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @param string $key |
|
197 | - * @param string $value |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - protected function wrap($key, $value) |
|
201 | - { |
|
202 | - $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args); |
|
203 | - return glsr(Builder::class)->div($value, [ |
|
204 | - 'class' => 'glsr-summary-'.$key, |
|
205 | - ]); |
|
206 | - } |
|
14 | + /** |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $args; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var float |
|
21 | + */ |
|
22 | + protected $averageRating; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected $ratingCounts; |
|
28 | + |
|
29 | + /** |
|
30 | + * {@inheritdoc} |
|
31 | + */ |
|
32 | + public function build(array $args = []) |
|
33 | + { |
|
34 | + $this->args = $args; |
|
35 | + $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args); |
|
36 | + if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) { |
|
37 | + return ''; |
|
38 | + } |
|
39 | + $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts); |
|
40 | + $this->generateSchema(); |
|
41 | + return glsr(Template::class)->build('templates/reviews-summary', [ |
|
42 | + 'context' => [ |
|
43 | + 'assigned_to' => $this->args['assigned_to'], |
|
44 | + 'category' => $this->args['category'], |
|
45 | + 'class' => $this->getClass(), |
|
46 | + 'id' => $this->args['id'], |
|
47 | + 'percentages' => $this->buildPercentage(), |
|
48 | + 'rating' => $this->buildRating(), |
|
49 | + 'stars' => $this->buildStars(), |
|
50 | + 'text' => $this->buildText(), |
|
51 | + ], |
|
52 | + ]); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @return void|string |
|
57 | + */ |
|
58 | + protected function buildPercentage() |
|
59 | + { |
|
60 | + if ($this->isHidden('bars')) { |
|
61 | + return; |
|
62 | + } |
|
63 | + $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts)); |
|
64 | + $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) { |
|
65 | + $label = $this->buildPercentageLabel($this->args['labels'][$level]); |
|
66 | + $background = $this->buildPercentageBackground($percentages[$level]); |
|
67 | + $count = apply_filters('site-reviews/summary/counts', |
|
68 | + $percentages[$level], |
|
69 | + $this->ratingCounts[$level] |
|
70 | + ); |
|
71 | + $percent = $this->buildPercentageCount($count); |
|
72 | + $value = $label.$background.$percent; |
|
73 | + $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [ |
|
74 | + 'percent' => wp_strip_all_tags($count, true), |
|
75 | + 'rating' => $level, |
|
76 | + ]); |
|
77 | + return $carry.glsr(Builder::class)->div($value, [ |
|
78 | + 'class' => 'glsr-bar', |
|
79 | + ]); |
|
80 | + }); |
|
81 | + return $this->wrap('percentage', $bars); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string $percent |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + protected function buildPercentageBackground($percent) |
|
89 | + { |
|
90 | + $backgroundPercent = glsr(Builder::class)->span([ |
|
91 | + 'class' => 'glsr-bar-background-percent', |
|
92 | + 'style' => 'width:'.$percent, |
|
93 | + ]); |
|
94 | + return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @param string $count |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + protected function buildPercentageCount($count) |
|
102 | + { |
|
103 | + return '<span class="glsr-bar-percent">'.$count.'</span>'; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param string $label |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + protected function buildPercentageLabel($label) |
|
111 | + { |
|
112 | + return '<span class="glsr-bar-label">'.$label.'</span>'; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @return void|string |
|
117 | + */ |
|
118 | + protected function buildRating() |
|
119 | + { |
|
120 | + if ($this->isHidden('rating')) { |
|
121 | + return; |
|
122 | + } |
|
123 | + return $this->wrap('rating', '<span>'.$this->averageRating.'</span>'); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @return void|string |
|
128 | + */ |
|
129 | + protected function buildStars() |
|
130 | + { |
|
131 | + if ($this->isHidden('stars')) { |
|
132 | + return; |
|
133 | + } |
|
134 | + $stars = glsr_star_rating($this->averageRating); |
|
135 | + return $this->wrap('stars', $stars); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return void|string |
|
140 | + */ |
|
141 | + protected function buildText() |
|
142 | + { |
|
143 | + if ($this->isHidden('summary')) { |
|
144 | + return; |
|
145 | + } |
|
146 | + $count = intval(array_sum($this->ratingCounts)); |
|
147 | + if (empty($this->args['text'])) { |
|
148 | + // @todo document this change |
|
149 | + $this->args['text'] = _nx( |
|
150 | + '{rating} out of {max} stars (based on {num} review)', |
|
151 | + '{rating} out of {max} stars (based on {num} reviews)', |
|
152 | + $count, |
|
153 | + 'Do not translate {rating}, {max}, and {num}, they are template tags.', |
|
154 | + 'site-reviews' |
|
155 | + ); |
|
156 | + } |
|
157 | + $summary = str_replace( |
|
158 | + ['{rating}', '{max}', '{num}'], |
|
159 | + [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count], |
|
160 | + $this->args['text'] |
|
161 | + ); |
|
162 | + return $this->wrap('text', '<span>'.$summary.'</span>'); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + protected function generateSchema() |
|
169 | + { |
|
170 | + if (!wp_validate_boolean($this->args['schema'])) { |
|
171 | + return; |
|
172 | + } |
|
173 | + glsr(Schema::class)->store( |
|
174 | + glsr(Schema::class)->buildSummary($this->args) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + protected function getClass() |
|
182 | + { |
|
183 | + return trim('glsr-summary '.$this->args['class']); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @param string $key |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + protected function isHidden($key) |
|
191 | + { |
|
192 | + return in_array($key, $this->args['hide']); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @param string $key |
|
197 | + * @param string $value |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + protected function wrap($key, $value) |
|
201 | + { |
|
202 | + $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args); |
|
203 | + return glsr(Builder::class)->div($value, [ |
|
204 | + 'class' => 'glsr-summary-'.$key, |
|
205 | + ]); |
|
206 | + } |
|
207 | 207 | } |
@@ -8,54 +8,54 @@ |
||
8 | 8 | |
9 | 9 | class StarRating implements PartialContract |
10 | 10 | { |
11 | - protected $prefix; |
|
12 | - protected $rating; |
|
11 | + protected $prefix; |
|
12 | + protected $rating; |
|
13 | 13 | |
14 | - /** |
|
15 | - * {@inheritdoc} |
|
16 | - */ |
|
17 | - public function build(array $args = []) |
|
18 | - { |
|
19 | - $this->setProperties($args); |
|
20 | - $fullStars = intval(floor($this->rating)); |
|
21 | - $halfStars = intval(ceil($this->rating - $fullStars)); |
|
22 | - $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
23 | - return glsr(Template::class)->build('templates/rating/stars', [ |
|
24 | - 'context' => [ |
|
25 | - 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
26 | - 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
27 | - 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
28 | - 'prefix' => $this->prefix, |
|
29 | - 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
30 | - ], |
|
31 | - ]); |
|
32 | - } |
|
14 | + /** |
|
15 | + * {@inheritdoc} |
|
16 | + */ |
|
17 | + public function build(array $args = []) |
|
18 | + { |
|
19 | + $this->setProperties($args); |
|
20 | + $fullStars = intval(floor($this->rating)); |
|
21 | + $halfStars = intval(ceil($this->rating - $fullStars)); |
|
22 | + $emptyStars = max(0, glsr()->constant('MAX_RATING', Rating::class) - $fullStars - $halfStars); |
|
23 | + return glsr(Template::class)->build('templates/rating/stars', [ |
|
24 | + 'context' => [ |
|
25 | + 'empty_stars' => $this->getTemplate('empty-star', $emptyStars), |
|
26 | + 'full_stars' => $this->getTemplate('full-star', $fullStars), |
|
27 | + 'half_stars' => $this->getTemplate('half-star', $halfStars), |
|
28 | + 'prefix' => $this->prefix, |
|
29 | + 'title' => sprintf(__('%s rating', 'site-reviews'), number_format_i18n($this->rating, 1)), |
|
30 | + ], |
|
31 | + ]); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $templateName |
|
36 | - * @param int $timesRepeated |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - protected function getTemplate($templateName, $timesRepeated) |
|
40 | - { |
|
41 | - $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
42 | - 'context' => [ |
|
43 | - 'prefix' => $this->prefix, |
|
44 | - ], |
|
45 | - ]); |
|
46 | - return str_repeat($template, $timesRepeated); |
|
47 | - } |
|
34 | + /** |
|
35 | + * @param string $templateName |
|
36 | + * @param int $timesRepeated |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + protected function getTemplate($templateName, $timesRepeated) |
|
40 | + { |
|
41 | + $template = glsr(Template::class)->build('templates/rating/'.$templateName, [ |
|
42 | + 'context' => [ |
|
43 | + 'prefix' => $this->prefix, |
|
44 | + ], |
|
45 | + ]); |
|
46 | + return str_repeat($template, $timesRepeated); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - protected function setProperties(array $args) |
|
53 | - { |
|
54 | - $args = wp_parse_args($args, [ |
|
55 | - 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
|
56 | - 'rating' => 0, |
|
57 | - ]); |
|
58 | - $this->prefix = $args['prefix']; |
|
59 | - $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
60 | - } |
|
49 | + /** |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + protected function setProperties(array $args) |
|
53 | + { |
|
54 | + $args = wp_parse_args($args, [ |
|
55 | + 'prefix' => glsr()->isAdmin() ? '' : 'glsr-', |
|
56 | + 'rating' => 0, |
|
57 | + ]); |
|
58 | + $this->prefix = $args['prefix']; |
|
59 | + $this->rating = (float) str_replace(',', '.', $args['rating']); |
|
60 | + } |
|
61 | 61 | } |