@@ -21,16 +21,16 @@ discard block |
||
21 | 21 | * @return array |
22 | 22 | * @filter site-reviews/settings/callback |
23 | 23 | */ |
24 | - public function filterSettingsCallback(array $settings) |
|
24 | + public function filterSettingsCallback( array $settings ) |
|
25 | 25 | { |
26 | - if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
26 | + if( 'yes' !== Arr::get( $settings, $this->enabledKey ) ) { |
|
27 | 27 | return $settings; |
28 | 28 | } |
29 | - $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | - $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | - $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false); |
|
32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | - $settings = $this->sanitizeRebusifySettings($settings); |
|
29 | + $isApiKeyModified = $this->isEmptyOrModified( $this->apiKey, $settings ); |
|
30 | + $isEmailModified = $this->isEmptyOrModified( $this->emailKey, $settings ); |
|
31 | + $isAccountVerified = glsr( OptionManager::class )->getWP( $this->rebusifyKey, false ); |
|
32 | + if( !$isAccountVerified || $isApiKeyModified || $isEmailModified ) { |
|
33 | + $settings = $this->sanitizeRebusifySettings( $settings ); |
|
34 | 34 | } |
35 | 35 | return $settings; |
36 | 36 | } |
@@ -40,21 +40,21 @@ discard block |
||
40 | 40 | * @return array |
41 | 41 | * @filter site-reviews/interpolate/partials/form/table-row-multiple |
42 | 42 | */ |
43 | - public function filterSettingsTableRow(array $context, $template, array $data) |
|
43 | + public function filterSettingsTableRow( array $context, $template, array $data ) |
|
44 | 44 | { |
45 | - if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
45 | + if( $this->enabledKey !== Arr::get( $data, 'field.path' ) ) { |
|
46 | 46 | return $context; |
47 | 47 | } |
48 | - $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | - if ('P' === $rebusifyProductType) { |
|
48 | + $rebusifyProductType = glsr( OptionManager::class )->getWP( $this->rebusifyKey ); |
|
49 | + if( 'P' === $rebusifyProductType ) { |
|
50 | 50 | return $context; |
51 | 51 | } |
52 | - if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
52 | + if( 'F' === $rebusifyProductType && 'yes' === glsr_get_option( 'general.rebusify' ) ) { |
|
53 | 53 | $button = $this->buildUpgradeButton(); |
54 | 54 | } else { |
55 | 55 | $button = $this->buildCreateButton(); |
56 | 56 | } |
57 | - $context['field'].= $button; |
|
57 | + $context['field'] .= $button; |
|
58 | 58 | return $context; |
59 | 59 | } |
60 | 60 | |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | * @return void |
64 | 64 | * @action site-reviews/review/created |
65 | 65 | */ |
66 | - public function onCreated(Review $review) |
|
66 | + public function onCreated( Review $review ) |
|
67 | 67 | { |
68 | - if (!$this->canPostReview($review)) { |
|
68 | + if( !$this->canPostReview( $review ) ) { |
|
69 | 69 | return; |
70 | 70 | } |
71 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | - if ($rebusify->success) { |
|
73 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
71 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
72 | + if( $rebusify->success ) { |
|
73 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | * @return void |
80 | 80 | * @action site-reviews/review/reverted |
81 | 81 | */ |
82 | - public function onReverted(Review $review) |
|
82 | + public function onReverted( Review $review ) |
|
83 | 83 | { |
84 | - if (!$this->canPostReview($review)) { |
|
84 | + if( !$this->canPostReview( $review ) ) { |
|
85 | 85 | return; |
86 | 86 | } |
87 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | - if ($rebusify->success) { |
|
89 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
87 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
88 | + if( $rebusify->success ) { |
|
89 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * @return void |
96 | 96 | * @action site-reviews/review/saved |
97 | 97 | */ |
98 | - public function onSaved(Review $review) |
|
98 | + public function onSaved( Review $review ) |
|
99 | 99 | { |
100 | - if (!$this->canPostReview($review)) { |
|
100 | + if( !$this->canPostReview( $review ) ) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | - if ($rebusify->success) { |
|
105 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
103 | + $rebusify = glsr( Rebusify::class )->sendReview( $review ); |
|
104 | + if( $rebusify->success ) { |
|
105 | + glsr( Database::class )->set( $review->ID, 'rebusify', $rebusify->review_id ); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | * @return void |
115 | 115 | * @action updated_postmeta |
116 | 116 | */ |
117 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
117 | + public function onUpdatedMeta( $metaId, $postId, $metaKey ) |
|
118 | 118 | { |
119 | - $review = glsr_get_review($postId); |
|
120 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
119 | + $review = glsr_get_review( $postId ); |
|
120 | + if( !$this->canPostResponse( $review ) || '_response' !== $metaKey ) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | - $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | - if ($rebusify->success) { |
|
125 | - glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
123 | + $rebusify = glsr( Rebusify::class )->sendReviewResponse( $review ); |
|
124 | + if( $rebusify->success ) { |
|
125 | + glsr( Database::class )->set( $review->ID, 'rebusify_response', true ); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function buildCreateButton() |
133 | 133 | { |
134 | - return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
134 | + return glsr( Builder::class )->a( __( 'Create Your Rebusify Account', 'site-reviews' ), [ |
|
135 | 135 | 'class' => 'button', |
136 | 136 | 'href' => Rebusify::WEB_URL, |
137 | 137 | 'target' => '_blank', |
138 | - ]); |
|
138 | + ] ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,37 +143,37 @@ discard block |
||
143 | 143 | */ |
144 | 144 | protected function buildUpgradeButton() |
145 | 145 | { |
146 | - $build = glsr(Builder::class); |
|
147 | - $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | - $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
146 | + $build = glsr( Builder::class ); |
|
147 | + $notice = $build->p( __( 'Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews' ) ); |
|
148 | + $button = $build->a( __( 'Upgrade Your Rebusify Plan', 'site-reviews' ), [ |
|
149 | 149 | 'class' => 'button', |
150 | 150 | 'href' => Rebusify::WEB_URL, |
151 | 151 | 'target' => '_blank', |
152 | - ]); |
|
153 | - return $build->div($notice.$button, [ |
|
152 | + ] ); |
|
153 | + return $build->div( $notice.$button, [ |
|
154 | 154 | 'class' => 'glsr-notice-inline notice inline notice-info', |
155 | - ]); |
|
155 | + ] ); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * @return bool |
160 | 160 | */ |
161 | - protected function canPostResponse(Review $review) |
|
161 | + protected function canPostResponse( Review $review ) |
|
162 | 162 | { |
163 | 163 | $requiredValues = [ |
164 | - glsr(Database::class)->get($review->ID, 'rebusify'), |
|
164 | + glsr( Database::class )->get( $review->ID, 'rebusify' ), |
|
165 | 165 | $review->response, |
166 | 166 | $review->review_id, |
167 | 167 | ]; |
168 | - return $this->canProceed($review, 'rebusify_response') |
|
168 | + return $this->canProceed( $review, 'rebusify_response' ) |
|
169 | 169 | && 'publish' === $review->status |
170 | - && 3 === count(array_filter($requiredValues)); |
|
170 | + && 3 === count( array_filter( $requiredValues ) ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
174 | 174 | * @return bool |
175 | 175 | */ |
176 | - protected function canPostReview(Review $review) |
|
176 | + protected function canPostReview( Review $review ) |
|
177 | 177 | { |
178 | 178 | $requiredValues = [ |
179 | 179 | $review->author, |
@@ -182,60 +182,60 @@ discard block |
||
182 | 182 | $review->review_id, |
183 | 183 | $review->title, |
184 | 184 | ]; |
185 | - return $this->canProceed($review) |
|
185 | + return $this->canProceed( $review ) |
|
186 | 186 | && 'publish' === $review->status |
187 | - && 5 === count(array_filter($requiredValues)); |
|
187 | + && 5 === count( array_filter( $requiredValues ) ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * @param string $metaKey |
192 | 192 | * @return bool |
193 | 193 | */ |
194 | - protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
194 | + protected function canProceed( Review $review, $metaKey = 'rebusify' ) |
|
195 | 195 | { |
196 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | - && $this->isReviewPostId($review->ID) |
|
198 | - && !$this->hasMetaKey($review, $metaKey); |
|
196 | + return glsr( OptionManager::class )->getBool( $this->enabledKey ) |
|
197 | + && $this->isReviewPostId( $review->ID ) |
|
198 | + && !$this->hasMetaKey( $review, $metaKey ); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | 202 | * @param string $metaKey |
203 | 203 | * @return bool |
204 | 204 | */ |
205 | - protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
205 | + protected function hasMetaKey( Review $review, $metaKey = 'rebusify' ) |
|
206 | 206 | { |
207 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
207 | + return '' !== glsr( Database::class )->get( $review->ID, $metaKey ); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | 211 | * @param string $key |
212 | 212 | * @return bool |
213 | 213 | */ |
214 | - protected function isEmptyOrModified($key, array $settings) |
|
214 | + protected function isEmptyOrModified( $key, array $settings ) |
|
215 | 215 | { |
216 | - $oldValue = glsr_get_option($key); |
|
217 | - $newValue = Arr::get($settings, $key); |
|
216 | + $oldValue = glsr_get_option( $key ); |
|
217 | + $newValue = Arr::get( $settings, $key ); |
|
218 | 218 | return empty($newValue) || $newValue !== $oldValue; |
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | 222 | * @return array |
223 | 223 | */ |
224 | - protected function sanitizeRebusifySettings(array $settings) |
|
224 | + protected function sanitizeRebusifySettings( array $settings ) |
|
225 | 225 | { |
226 | - $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | - Arr::get($settings, $this->apiKey), |
|
228 | - Arr::get($settings, $this->emailKey) |
|
226 | + $rebusify = glsr( Rebusify::class )->activateKey( |
|
227 | + Arr::get( $settings, $this->apiKey ), |
|
228 | + Arr::get( $settings, $this->emailKey ) |
|
229 | 229 | ); |
230 | - if ($rebusify->success) { |
|
231 | - update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype')); |
|
230 | + if( $rebusify->success ) { |
|
231 | + update_option( $this->rebusifyKey, Arr::get( $rebusify->response, 'producttype' ) ); |
|
232 | 232 | } else { |
233 | - delete_option($this->rebusifyKey); |
|
234 | - $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
235 | - glsr(Notice::class)->addError(sprintf( |
|
236 | - __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
233 | + delete_option( $this->rebusifyKey ); |
|
234 | + $settings = Arr::set( $settings, $this->enabledKey, 'no' ); |
|
235 | + glsr( Notice::class )->addError( sprintf( |
|
236 | + __( 'Your Rebusify account details could not be verified, please try again. %s', 'site-reviews' ), |
|
237 | 237 | '('.$rebusify->message.')' |
238 | - )); |
|
238 | + ) ); |
|
239 | 239 | } |
240 | 240 | return $settings; |
241 | 241 | } |
@@ -37,7 +37,7 @@ |
||
37 | 37 | 'pinned' => false, |
38 | 38 | 'rating' => '', |
39 | 39 | 'response' => '', |
40 | - 'review_id' => md5(time().mt_rand()), |
|
40 | + 'review_id' => md5( time().mt_rand() ), |
|
41 | 41 | 'review_type' => 'local', |
42 | 42 | 'title' => '', |
43 | 43 | 'url' => '', |
@@ -58,20 +58,20 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * @return static |
60 | 60 | */ |
61 | - public function validate(array $request) |
|
61 | + public function validate( array $request ) |
|
62 | 62 | { |
63 | 63 | $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
64 | 64 | $this->form_id = $request['form_id']; |
65 | - $this->options = glsr(OptionManager::class)->all(); |
|
66 | - $this->request = $this->validateRequest($request); |
|
65 | + $this->options = glsr( OptionManager::class )->all(); |
|
66 | + $this->request = $this->validateRequest( $request ); |
|
67 | 67 | $this->validateCustom(); |
68 | 68 | $this->validateHoneyPot(); |
69 | 69 | $this->validateReviewLimits(); |
70 | 70 | $this->validateBlacklist(); |
71 | 71 | $this->validateAkismet(); |
72 | 72 | $this->validateRecaptcha(); |
73 | - if (!empty($this->error)) { |
|
74 | - $this->setSessionValues('message', $this->error); |
|
73 | + if( !empty($this->error) ) { |
|
74 | + $this->setSessionValues( 'message', $this->error ); |
|
75 | 75 | } |
76 | 76 | return $this; |
77 | 77 | } |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | * @param mixed $fallback |
82 | 82 | * @return mixed |
83 | 83 | */ |
84 | - protected function getOption($path, $fallback = '') |
|
84 | + protected function getOption( $path, $fallback = '' ) |
|
85 | 85 | { |
86 | - return Arr::get($this->options, $path, $fallback); |
|
86 | + return Arr::get( $this->options, $path, $fallback ); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | protected function getRecaptchaStatus() |
93 | 93 | { |
94 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
94 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
95 | 95 | return static::RECAPTCHA_DISABLED; |
96 | 96 | } |
97 | - if (empty($this->request['_recaptcha-token'])) { |
|
98 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
97 | + if( empty($this->request['_recaptcha-token']) ) { |
|
98 | + return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) ) |
|
99 | 99 | ? static::RECAPTCHA_EMPTY |
100 | 100 | : static::RECAPTCHA_FAILED; |
101 | 101 | } |
@@ -107,23 +107,23 @@ discard block |
||
107 | 107 | */ |
108 | 108 | protected function getRecaptchaTokenStatus() |
109 | 109 | { |
110 | - $endpoint = add_query_arg([ |
|
110 | + $endpoint = add_query_arg( [ |
|
111 | 111 | 'remoteip' => Helper::getIpAddress(), |
112 | 112 | 'response' => $this->request['_recaptcha-token'], |
113 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
114 | - ], static::RECAPTCHA_ENDPOINT); |
|
115 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
116 | - glsr_log()->error($response->get_error_message()); |
|
113 | + 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
|
114 | + ], static::RECAPTCHA_ENDPOINT ); |
|
115 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
116 | + glsr_log()->error( $response->get_error_message() ); |
|
117 | 117 | return static::RECAPTCHA_FAILED; |
118 | 118 | } |
119 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
120 | - if (!empty($response->success)) { |
|
121 | - return boolval($response->success) |
|
119 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
120 | + if( !empty($response->success) ) { |
|
121 | + return boolval( $response->success ) |
|
122 | 122 | ? static::RECAPTCHA_VALID |
123 | 123 | : static::RECAPTCHA_INVALID; |
124 | 124 | } |
125 | - foreach ($response->{'error-codes'} as $error) { |
|
126 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
125 | + foreach( $response->{'error-codes'} as $error ) { |
|
126 | + glsr_log()->error( 'reCAPTCHA error: '.$error ); |
|
127 | 127 | } |
128 | 128 | return static::RECAPTCHA_INVALID; |
129 | 129 | } |
@@ -131,35 +131,35 @@ discard block |
||
131 | 131 | /** |
132 | 132 | * @return array |
133 | 133 | */ |
134 | - protected function getValidationRules(array $request) |
|
134 | + protected function getValidationRules( array $request ) |
|
135 | 135 | { |
136 | 136 | $rules = array_intersect_key( |
137 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
138 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
137 | + apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ), |
|
138 | + array_flip( $this->getOption( 'settings.submissions.required', [] ) ) |
|
139 | 139 | ); |
140 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
141 | - return array_diff_key($rules, array_flip($excluded)); |
|
140 | + $excluded = explode( ',', Arr::get( $request, 'excluded' ) ); |
|
141 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * @return bool |
146 | 146 | */ |
147 | - protected function isRequestValid(array $request) |
|
147 | + protected function isRequestValid( array $request ) |
|
148 | 148 | { |
149 | - $rules = $this->getValidationRules($request); |
|
150 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
151 | - if (empty($errors)) { |
|
149 | + $rules = $this->getValidationRules( $request ); |
|
150 | + $errors = glsr( Validator::class )->validate( $request, $rules ); |
|
151 | + if( empty($errors) ) { |
|
152 | 152 | return true; |
153 | 153 | } |
154 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
155 | - $this->setSessionValues('errors', $errors); |
|
156 | - $this->setSessionValues('values', $request); |
|
154 | + $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
|
155 | + $this->setSessionValues( 'errors', $errors ); |
|
156 | + $this->setSessionValues( 'values', $request ); |
|
157 | 157 | return false; |
158 | 158 | } |
159 | 159 | |
160 | - protected function setError($message, $loggedMessage = '') |
|
160 | + protected function setError( $message, $loggedMessage = '' ) |
|
161 | 161 | { |
162 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
162 | + $this->setSessionValues( 'errors', [], $loggedMessage ); |
|
163 | 163 | $this->error = $message; |
164 | 164 | } |
165 | 165 | |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | * @param string $loggedMessage |
170 | 170 | * @return void |
171 | 171 | */ |
172 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
172 | + protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
|
173 | 173 | { |
174 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
175 | - if (!empty($loggedMessage)) { |
|
176 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
174 | + glsr()->sessionSet( $this->form_id.$type, $value ); |
|
175 | + if( !empty($loggedMessage) ) { |
|
176 | + glsr_log()->warning( $loggedMessage )->debug( $this->request ); |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | */ |
183 | 183 | protected function validateAkismet() |
184 | 184 | { |
185 | - if (!empty($this->error)) { |
|
185 | + if( !empty($this->error) ) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | - if (glsr(Akismet::class)->isSpam($this->request)) { |
|
189 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
188 | + if( glsr( Akismet::class )->isSpam( $this->request ) ) { |
|
189 | + $this->setError( __( 'This review has been flagged as possible spam and cannot be submitted.', 'site-reviews' ), |
|
190 | 190 | 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
191 | 191 | ); |
192 | 192 | } |
@@ -197,18 +197,18 @@ discard block |
||
197 | 197 | */ |
198 | 198 | protected function validateBlacklist() |
199 | 199 | { |
200 | - if (!empty($this->error)) { |
|
200 | + if( !empty($this->error) ) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
203 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) ) { |
|
204 | 204 | return; |
205 | 205 | } |
206 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
207 | - if ('reject' != $blacklistAction) { |
|
206 | + $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
|
207 | + if( 'reject' != $blacklistAction ) { |
|
208 | 208 | $this->request['blacklisted'] = true; |
209 | 209 | return; |
210 | 210 | } |
211 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
211 | + $this->setError( __( 'Your review cannot be submitted at this time.', 'site-reviews' ), |
|
212 | 212 | 'Blacklisted submission detected:' |
213 | 213 | ); |
214 | 214 | } |
@@ -218,18 +218,18 @@ discard block |
||
218 | 218 | */ |
219 | 219 | protected function validateCustom() |
220 | 220 | { |
221 | - if (!empty($this->error)) { |
|
221 | + if( !empty($this->error) ) { |
|
222 | 222 | return; |
223 | 223 | } |
224 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
225 | - if (true === $validated) { |
|
224 | + $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
|
225 | + if( true === $validated ) { |
|
226 | 226 | return; |
227 | 227 | } |
228 | - $errorMessage = is_string($validated) |
|
228 | + $errorMessage = is_string( $validated ) |
|
229 | 229 | ? $validated |
230 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
231 | - $this->setError($errorMessage); |
|
232 | - $this->setSessionValues('values', $this->request); |
|
230 | + : __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
|
231 | + $this->setError( $errorMessage ); |
|
232 | + $this->setSessionValues( 'values', $this->request ); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -237,11 +237,11 @@ discard block |
||
237 | 237 | */ |
238 | 238 | protected function validateHoneyPot() |
239 | 239 | { |
240 | - if (!empty($this->error)) { |
|
240 | + if( !empty($this->error) ) { |
|
241 | 241 | return; |
242 | 242 | } |
243 | - if (!empty($this->request['gotcha'])) { |
|
244 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
243 | + if( !empty($this->request['gotcha']) ) { |
|
244 | + $this->setError( __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ), |
|
245 | 245 | 'The Honeypot caught a bad submission:' |
246 | 246 | ); |
247 | 247 | } |
@@ -252,11 +252,11 @@ discard block |
||
252 | 252 | */ |
253 | 253 | protected function validateReviewLimits() |
254 | 254 | { |
255 | - if (!empty($this->error)) { |
|
255 | + if( !empty($this->error) ) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | - if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
259 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
258 | + if( glsr( ReviewLimits::class )->hasReachedLimit( $this->request ) ) { |
|
259 | + $this->setError( __( 'You have already submitted a review.', 'site-reviews' ) ); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -265,33 +265,33 @@ discard block |
||
265 | 265 | */ |
266 | 266 | protected function validateRecaptcha() |
267 | 267 | { |
268 | - if (!empty($this->error)) { |
|
268 | + if( !empty($this->error) ) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | $status = $this->getRecaptchaStatus(); |
272 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
272 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) ) { |
|
273 | 273 | return; |
274 | 274 | } |
275 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
276 | - $this->setSessionValues('recaptcha', 'unset'); |
|
275 | + if( static::RECAPTCHA_EMPTY === $status ) { |
|
276 | + $this->setSessionValues( 'recaptcha', 'unset' ); |
|
277 | 277 | $this->recaptchaIsUnset = true; |
278 | 278 | return; |
279 | 279 | } |
280 | - $this->setSessionValues('recaptcha', 'reset'); |
|
280 | + $this->setSessionValues( 'recaptcha', 'reset' ); |
|
281 | 281 | $errors = [ |
282 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
283 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
282 | + static::RECAPTCHA_FAILED => __( 'The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews' ), |
|
283 | + static::RECAPTCHA_INVALID => __( 'The reCAPTCHA verification failed, please try again.', 'site-reviews' ), |
|
284 | 284 | ]; |
285 | - $this->setError($errors[$status]); |
|
285 | + $this->setError( $errors[$status] ); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
289 | 289 | * @return array |
290 | 290 | */ |
291 | - protected function validateRequest(array $request) |
|
291 | + protected function validateRequest( array $request ) |
|
292 | 292 | { |
293 | - return $this->isRequestValid($request) |
|
294 | - ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
293 | + return $this->isRequestValid( $request ) |
|
294 | + ? array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ) |
|
295 | 295 | : $request; |
296 | 296 | } |
297 | 297 | } |
@@ -41,17 +41,17 @@ discard block |
||
41 | 41 | 'setting' => 'Plugin Settings', |
42 | 42 | 'reviews' => 'Review Counts', |
43 | 43 | ]; |
44 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
45 | - $methodName = Helper::buildMethodName('get-'.$key.'-details'); |
|
46 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
44 | + $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use ($details) { |
|
45 | + $methodName = Helper::buildMethodName( 'get-'.$key.'-details' ); |
|
46 | + if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) { |
|
47 | 47 | return $carry.$this->implode( |
48 | - strtoupper($details[$key]), |
|
49 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | + strtoupper( $details[$key] ), |
|
49 | + apply_filters( 'site-reviews/system/'.$key, $systemDetails ) |
|
50 | 50 | ); |
51 | 51 | } |
52 | 52 | return $carry; |
53 | 53 | }); |
54 | - return trim($systemInfo); |
|
54 | + return trim( $systemInfo ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | public function getActivePluginDetails() |
61 | 61 | { |
62 | 62 | $plugins = get_plugins(); |
63 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
64 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
65 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
63 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
64 | + $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) ); |
|
65 | + return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function getAddonDetails() |
72 | 72 | { |
73 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
74 | - ksort($details); |
|
73 | + $details = apply_filters( 'site-reviews/addon/system-info', [] ); |
|
74 | + ksort( $details ); |
|
75 | 75 | return $details; |
76 | 76 | } |
77 | 77 | |
@@ -81,11 +81,11 @@ discard block |
||
81 | 81 | public function getBrowserDetails() |
82 | 82 | { |
83 | 83 | $browser = new Browser(); |
84 | - $name = esc_attr($browser->getName()); |
|
85 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
86 | - $version = esc_attr($browser->getVersion()); |
|
84 | + $name = esc_attr( $browser->getName() ); |
|
85 | + $userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() ); |
|
86 | + $version = esc_attr( $browser->getVersion() ); |
|
87 | 87 | return [ |
88 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
88 | + 'Browser Name' => sprintf( '%s %s', $name, $version ), |
|
89 | 89 | 'Browser UA' => $userAgent, |
90 | 90 | ]; |
91 | 91 | } |
@@ -95,12 +95,12 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function getInactivePluginDetails() |
97 | 97 | { |
98 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
99 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
99 | + $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) ); |
|
100 | 100 | $multisitePlugins = $this->getMultisitePluginDetails(); |
101 | 101 | return empty($multisitePlugins) |
102 | 102 | ? $inactivePlugins |
103 | - : array_diff($inactivePlugins, $multisitePlugins); |
|
103 | + : array_diff( $inactivePlugins, $multisitePlugins ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function getMuPluginDetails() |
110 | 110 | { |
111 | - if (empty($plugins = get_mu_plugins())) { |
|
111 | + if( empty($plugins = get_mu_plugins()) ) { |
|
112 | 112 | return []; |
113 | 113 | } |
114 | - return $this->normalizePluginList($plugins); |
|
114 | + return $this->normalizePluginList( $plugins ); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function getMultisitePluginDetails() |
121 | 121 | { |
122 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
123 | - if (!is_multisite() || empty($activePlugins)) { |
|
122 | + $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] ); |
|
123 | + if( !is_multisite() || empty($activePlugins) ) { |
|
124 | 124 | return []; |
125 | 125 | } |
126 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
126 | + return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) ); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -131,31 +131,31 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function getPhpDetails() |
133 | 133 | { |
134 | - $displayErrors = $this->getINI('display_errors', null) |
|
135 | - ? 'On ('.$this->getINI('display_errors').')' |
|
134 | + $displayErrors = $this->getINI( 'display_errors', null ) |
|
135 | + ? 'On ('.$this->getINI( 'display_errors' ).')' |
|
136 | 136 | : 'N/A'; |
137 | - $intlSupport = extension_loaded('intl') |
|
138 | - ? phpversion('intl') |
|
137 | + $intlSupport = extension_loaded( 'intl' ) |
|
138 | + ? phpversion( 'intl' ) |
|
139 | 139 | : 'false'; |
140 | 140 | return [ |
141 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
142 | - 'Default Charset' => $this->getINI('default_charset'), |
|
141 | + 'cURL' => var_export( function_exists( 'curl_init' ), true ), |
|
142 | + 'Default Charset' => $this->getINI( 'default_charset' ), |
|
143 | 143 | 'Display Errors' => $displayErrors, |
144 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
144 | + 'fsockopen' => var_export( function_exists( 'fsockopen' ), true ), |
|
145 | 145 | 'Intl' => $intlSupport, |
146 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
147 | - 'Max Execution Time' => $this->getINI('max_execution_time'), |
|
148 | - 'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'), |
|
149 | - 'Max Input Vars' => $this->getINI('max_input_vars'), |
|
150 | - 'Memory Limit' => $this->getINI('memory_limit'), |
|
151 | - 'Post Max Size' => $this->getINI('post_max_size'), |
|
152 | - 'Sendmail Path' => $this->getINI('sendmail_path'), |
|
153 | - 'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')), |
|
154 | - 'Session Name' => esc_html($this->getINI('session.name')), |
|
155 | - 'Session Save Path' => esc_html($this->getINI('session.save_path')), |
|
156 | - 'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true), |
|
157 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true), |
|
158 | - 'Upload Max Filesize' => $this->getINI('upload_max_filesize'), |
|
146 | + 'IPv6' => var_export( defined( 'AF_INET6' ), true ), |
|
147 | + 'Max Execution Time' => $this->getINI( 'max_execution_time' ), |
|
148 | + 'Max Input Nesting Level' => $this->getINI( 'max_input_nesting_level' ), |
|
149 | + 'Max Input Vars' => $this->getINI( 'max_input_vars' ), |
|
150 | + 'Memory Limit' => $this->getINI( 'memory_limit' ), |
|
151 | + 'Post Max Size' => $this->getINI( 'post_max_size' ), |
|
152 | + 'Sendmail Path' => $this->getINI( 'sendmail_path' ), |
|
153 | + 'Session Cookie Path' => esc_html( $this->getINI( 'session.cookie_path' ) ), |
|
154 | + 'Session Name' => esc_html( $this->getINI( 'session.name' ) ), |
|
155 | + 'Session Save Path' => esc_html( $this->getINI( 'session.save_path' ) ), |
|
156 | + 'Session Use Cookies' => var_export( wp_validate_boolean( $this->getINI( 'session.use_cookies', false ) ), true ), |
|
157 | + 'Session Use Only Cookies' => var_export( wp_validate_boolean( $this->getINI( 'session.use_only_cookies', false ) ), true ), |
|
158 | + 'Upload Max Filesize' => $this->getINI( 'upload_max_filesize' ), |
|
159 | 159 | ]; |
160 | 160 | } |
161 | 161 | |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function getReviewsDetails() |
166 | 166 | { |
167 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
168 | - $counts = Arr::flattenArray($counts); |
|
169 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
170 | - if (!is_array($ratings)) { |
|
167 | + $counts = glsr( CountsManager::class )->getCounts(); |
|
168 | + $counts = Arr::flattenArray( $counts ); |
|
169 | + array_walk( $counts, function( &$ratings ) use ($counts) { |
|
170 | + if( !is_array( $ratings ) ) { |
|
171 | 171 | glsr_log() |
172 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
173 | - ->debug($ratings) |
|
174 | - ->debug($counts); |
|
172 | + ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' ) |
|
173 | + ->debug( $ratings ) |
|
174 | + ->debug( $counts ); |
|
175 | 175 | return; |
176 | 176 | } |
177 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
177 | + $ratings = array_sum( $ratings ).' ('.implode( ', ', $ratings ).')'; |
|
178 | 178 | }); |
179 | - ksort($counts); |
|
179 | + ksort( $counts ); |
|
180 | 180 | return $counts; |
181 | 181 | } |
182 | 182 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | 'Host Name' => $this->getHostName(), |
191 | 191 | 'MySQL Version' => $wpdb->db_version(), |
192 | 192 | 'PHP Version' => PHP_VERSION, |
193 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
193 | + 'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ), |
|
194 | 194 | ]; |
195 | 195 | } |
196 | 196 | |
@@ -199,16 +199,16 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function getSettingDetails() |
201 | 201 | { |
202 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
203 | - $settings = Arr::flattenArray($settings, true); |
|
204 | - $settings = $this->purgeSensitiveData($settings); |
|
205 | - ksort($settings); |
|
202 | + $settings = glsr( OptionManager::class )->get( 'settings', [] ); |
|
203 | + $settings = Arr::flattenArray( $settings, true ); |
|
204 | + $settings = $this->purgeSensitiveData( $settings ); |
|
205 | + ksort( $settings ); |
|
206 | 206 | $details = []; |
207 | - foreach ($settings as $key => $value) { |
|
208 | - if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) { |
|
207 | + foreach( $settings as $key => $value ) { |
|
208 | + if( Str::startsWith( 'strings', $key ) && Str::endsWith( 'id', $key ) ) { |
|
209 | 209 | continue; |
210 | 210 | } |
211 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | + $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' ); |
|
212 | 212 | $details[$key] = $value; |
213 | 213 | } |
214 | 214 | return $details; |
@@ -220,11 +220,11 @@ discard block |
||
220 | 220 | public function getPluginDetails() |
221 | 221 | { |
222 | 222 | return [ |
223 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
224 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
225 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
223 | + 'Console level' => glsr( Console::class )->humanLevel(), |
|
224 | + 'Console size' => glsr( Console::class )->humanSize( '0' ), |
|
225 | + 'Last Rating Count' => date_i18n( 'Y-m-d H:i', glsr( OptionManager::class )->get( 'last_review_count' ) ), |
|
226 | 226 | 'Version (current)' => glsr()->version, |
227 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | + 'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ), |
|
228 | 228 | ]; |
229 | 229 | } |
230 | 230 | |
@@ -236,23 +236,23 @@ discard block |
||
236 | 236 | global $wpdb; |
237 | 237 | $theme = wp_get_theme(); |
238 | 238 | return [ |
239 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
240 | - 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
239 | + 'Active Theme' => sprintf( '%s v%s', (string)$theme->Name, (string)$theme->Version ), |
|
240 | + 'Email Domain' => substr( strrchr( glsr( OptionManager::class )->getWP( 'admin_email' ), '@' ), 1 ), |
|
241 | 241 | 'Home URL' => home_url(), |
242 | 242 | 'Language' => get_locale(), |
243 | 243 | 'Memory Limit' => WP_MEMORY_LIMIT, |
244 | - 'Multisite' => var_export(is_multisite(), true), |
|
245 | - 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
246 | - 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
247 | - 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
248 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
249 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
250 | - 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
244 | + 'Multisite' => var_export( is_multisite(), true ), |
|
245 | + 'Page For Posts ID' => glsr( OptionManager::class )->getWP( 'page_for_posts' ), |
|
246 | + 'Page On Front ID' => glsr( OptionManager::class )->getWP( 'page_on_front' ), |
|
247 | + 'Permalink Structure' => glsr( OptionManager::class )->getWP( 'permalink_structure', 'default' ), |
|
248 | + 'Post Stati' => implode( ', ', get_post_stati() ), |
|
249 | + 'Remote Post' => glsr( Cache::class )->getRemotePostTest(), |
|
250 | + 'Show On Front' => glsr( OptionManager::class )->getWP( 'show_on_front' ), |
|
251 | 251 | 'Site URL' => site_url(), |
252 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'), |
|
253 | - 'Version' => get_bloginfo('version'), |
|
254 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
255 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
252 | + 'Timezone' => glsr( OptionManager::class )->getWP( 'timezone_string', $this->getINI( 'date.timezone' ).' (PHP)' ), |
|
253 | + 'Version' => get_bloginfo( 'version' ), |
|
254 | + 'WP Debug' => var_export( defined( 'WP_DEBUG' ), true ), |
|
255 | + 'WP Max Upload Size' => size_format( wp_max_upload_size() ), |
|
256 | 256 | 'WP Memory Limit' => WP_MEMORY_LIMIT, |
257 | 257 | ]; |
258 | 258 | } |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | 'secureserver.net' => 'GoDaddy', |
283 | 283 | 'WPE_APIKEY' => 'WP Engine', |
284 | 284 | ]; |
285 | - foreach ($checks as $key => $value) { |
|
286 | - if (!$this->isWebhostCheckValid($key)) { |
|
285 | + foreach( $checks as $key => $value ) { |
|
286 | + if( !$this->isWebhostCheckValid( $key ) ) { |
|
287 | 287 | continue; |
288 | 288 | } |
289 | 289 | return $value; |
290 | 290 | } |
291 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | + return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) ); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | /** |
@@ -296,16 +296,16 @@ discard block |
||
296 | 296 | */ |
297 | 297 | protected function getHostName() |
298 | 298 | { |
299 | - return sprintf('%s (%s)', |
|
299 | + return sprintf( '%s (%s)', |
|
300 | 300 | $this->detectWebhostProvider(), |
301 | 301 | Helper::getIpAddress() |
302 | 302 | ); |
303 | 303 | } |
304 | 304 | |
305 | - protected function getINI($name, $disabledValue = 'ini_get() is disabled.') |
|
305 | + protected function getINI( $name, $disabledValue = 'ini_get() is disabled.' ) |
|
306 | 306 | { |
307 | - return function_exists('ini_get') |
|
308 | - ? ini_get($name) |
|
307 | + return function_exists( 'ini_get' ) |
|
308 | + ? ini_get( $name ) |
|
309 | 309 | : $disabledValue; |
310 | 310 | } |
311 | 311 | |
@@ -315,9 +315,9 @@ discard block |
||
315 | 315 | protected function getWordpressPlugins() |
316 | 316 | { |
317 | 317 | $plugins = get_plugins(); |
318 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
319 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
320 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
318 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
319 | + $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) ); |
|
320 | + $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
321 | 321 | return $active + $inactive; |
322 | 322 | } |
323 | 323 | |
@@ -325,48 +325,48 @@ discard block |
||
325 | 325 | * @param string $title |
326 | 326 | * @return string |
327 | 327 | */ |
328 | - protected function implode($title, array $details) |
|
328 | + protected function implode( $title, array $details ) |
|
329 | 329 | { |
330 | 330 | $strings = ['['.$title.']']; |
331 | - $padding = max(array_map('strlen', array_keys($details))); |
|
332 | - $padding = max([$padding, static::PAD]); |
|
333 | - foreach ($details as $key => $value) { |
|
334 | - $strings[] = is_string($key) |
|
335 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
331 | + $padding = max( array_map( 'strlen', array_keys( $details ) ) ); |
|
332 | + $padding = max( [$padding, static::PAD] ); |
|
333 | + foreach( $details as $key => $value ) { |
|
334 | + $strings[] = is_string( $key ) |
|
335 | + ? sprintf( '%s : %s', str_pad( $key, $padding, '.' ), $value ) |
|
336 | 336 | : ' - '.$value; |
337 | 337 | } |
338 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
338 | + return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL; |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
342 | 342 | * @param string $key |
343 | 343 | * @return bool |
344 | 344 | */ |
345 | - protected function isWebhostCheckValid($key) |
|
345 | + protected function isWebhostCheckValid( $key ) |
|
346 | 346 | { |
347 | - return defined($key) |
|
348 | - || filter_input(INPUT_SERVER, $key) |
|
349 | - || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
350 | - || Str::contains(DB_HOST, $key) |
|
351 | - || Str::contains(php_uname(), $key); |
|
347 | + return defined( $key ) |
|
348 | + || filter_input( INPUT_SERVER, $key ) |
|
349 | + || Str::contains( filter_input( INPUT_SERVER, 'SERVER_NAME' ), $key ) |
|
350 | + || Str::contains( DB_HOST, $key ) |
|
351 | + || Str::contains( php_uname(), $key ); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | 355 | * @return array |
356 | 356 | */ |
357 | - protected function normalizePluginList(array $plugins) |
|
357 | + protected function normalizePluginList( array $plugins ) |
|
358 | 358 | { |
359 | - $plugins = array_map(function ($plugin) { |
|
360 | - return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version')); |
|
361 | - }, $plugins); |
|
362 | - natcasesort($plugins); |
|
363 | - return array_flip($plugins); |
|
359 | + $plugins = array_map( function( $plugin ) { |
|
360 | + return sprintf( '%s v%s', Arr::get( $plugin, 'Name' ), Arr::get( $plugin, 'Version' ) ); |
|
361 | + }, $plugins ); |
|
362 | + natcasesort( $plugins ); |
|
363 | + return array_flip( $plugins ); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
367 | 367 | * @return array |
368 | 368 | */ |
369 | - protected function purgeSensitiveData(array $settings) |
|
369 | + protected function purgeSensitiveData( array $settings ) |
|
370 | 370 | { |
371 | 371 | $keys = [ |
372 | 372 | 'general.rebusify_serial', |
@@ -374,12 +374,12 @@ discard block |
||
374 | 374 | 'submissions.recaptcha.key', |
375 | 375 | 'submissions.recaptcha.secret', |
376 | 376 | ]; |
377 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
378 | - foreach ($keys as $key) { |
|
379 | - if (!Str::startsWith($key, $setting) || empty($value)) { |
|
377 | + array_walk( $settings, function( &$value, $setting ) use ($keys) { |
|
378 | + foreach( $keys as $key ) { |
|
379 | + if( !Str::startsWith( $key, $setting ) || empty($value) ) { |
|
380 | 380 | continue; |
381 | 381 | } |
382 | - $value = str_repeat('•', 13); |
|
382 | + $value = str_repeat( '•', 13 ); |
|
383 | 383 | return; |
384 | 384 | } |
385 | 385 | }); |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | * @param string $path |
14 | 14 | * @return string |
15 | 15 | */ |
16 | - public static function buildClassName($name, $path = '') |
|
16 | + public static function buildClassName( $name, $path = '' ) |
|
17 | 17 | { |
18 | - $className = Str::camelCase($name); |
|
19 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
18 | + $className = Str::camelCase( $name ); |
|
19 | + $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' ); |
|
20 | 20 | return !empty($path) |
21 | 21 | ? __NAMESPACE__.'\\'.$path.'\\'.$className |
22 | 22 | : $className; |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | * @param string $prefix |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - public static function buildMethodName($name, $prefix = '') |
|
30 | + public static function buildMethodName( $name, $prefix = '' ) |
|
31 | 31 | { |
32 | - return lcfirst($prefix.static::buildClassName($name)); |
|
32 | + return lcfirst( $prefix.static::buildClassName( $name ) ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @param string $name |
37 | 37 | * @return string |
38 | 38 | */ |
39 | - public static function buildPropertyName($name) |
|
39 | + public static function buildPropertyName( $name ) |
|
40 | 40 | { |
41 | - return lcfirst(static::buildClassName($name)); |
|
41 | + return lcfirst( static::buildClassName( $name ) ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -46,30 +46,30 @@ discard block |
||
46 | 46 | * @param mixed $value |
47 | 47 | * @return mixed |
48 | 48 | */ |
49 | - public static function castTo($cast = '', $value) |
|
49 | + public static function castTo( $cast = '', $value ) |
|
50 | 50 | { |
51 | - switch ($cast) { |
|
51 | + switch( $cast ) { |
|
52 | 52 | case 'array': |
53 | - return (array) $value; |
|
53 | + return (array)$value; |
|
54 | 54 | case 'bool': |
55 | 55 | case 'boolean': |
56 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
56 | + return filter_var( $value, FILTER_VALIDATE_BOOLEAN ); |
|
57 | 57 | case 'float': |
58 | - return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
58 | + return (float)filter_var( $value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND ); |
|
59 | 59 | case 'int': |
60 | 60 | case 'integer': |
61 | - return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
61 | + return (int)filter_var( $value, FILTER_VALIDATE_INT ); |
|
62 | 62 | case 'object': |
63 | - return (object) (array) $value; |
|
63 | + return (object)(array)$value; |
|
64 | 64 | case 'str': |
65 | 65 | case 'string': |
66 | - if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
67 | - return (string) $value->__toString(); |
|
66 | + if( is_object( $value ) && in_array( '__toString', get_class_methods( $value ) ) ) { |
|
67 | + return (string)$value->__toString(); |
|
68 | 68 | } |
69 | - if (is_array($value) || is_object($value)) { |
|
70 | - return serialize($value); |
|
69 | + if( is_array( $value ) || is_object( $value ) ) { |
|
70 | + return serialize( $value ); |
|
71 | 71 | } |
72 | - return (string) $value; |
|
72 | + return (string)$value; |
|
73 | 73 | default: |
74 | 74 | return $value; |
75 | 75 | } |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | * @param string $key |
80 | 80 | * @return mixed |
81 | 81 | */ |
82 | - public static function filterInput($key, array $request = []) |
|
82 | + public static function filterInput( $key, array $request = [] ) |
|
83 | 83 | { |
84 | - if (isset($request[$key])) { |
|
84 | + if( isset($request[$key]) ) { |
|
85 | 85 | return $request[$key]; |
86 | 86 | } |
87 | - $variable = filter_input(INPUT_POST, $key); |
|
88 | - if (is_null($variable) && isset($_POST[$key])) { |
|
87 | + $variable = filter_input( INPUT_POST, $key ); |
|
88 | + if( is_null( $variable ) && isset($_POST[$key]) ) { |
|
89 | 89 | $variable = $_POST[$key]; |
90 | 90 | } |
91 | 91 | return $variable; |
@@ -95,13 +95,13 @@ discard block |
||
95 | 95 | * @param string $key |
96 | 96 | * @return array |
97 | 97 | */ |
98 | - public static function filterInputArray($key) |
|
98 | + public static function filterInputArray( $key ) |
|
99 | 99 | { |
100 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
101 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
100 | + $variable = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
101 | + if( empty($variable) && !empty($_POST[$key]) && is_array( $_POST[$key] ) ) { |
|
102 | 102 | $variable = $_POST[$key]; |
103 | 103 | } |
104 | - return (array) $variable; |
|
104 | + return (array)$variable; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -110,22 +110,22 @@ discard block |
||
110 | 110 | public static function getIpAddress() |
111 | 111 | { |
112 | 112 | $whitelist = []; |
113 | - $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
114 | - if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
115 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
113 | + $isUsingCloudflare = !empty(filter_input( INPUT_SERVER, 'CF-Connecting-IP' )); |
|
114 | + if( apply_filters( 'site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare ) ) { |
|
115 | + $cloudflareIps = glsr( Cache::class )->getCloudflareIps(); |
|
116 | 116 | $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
117 | - if (defined('AF_INET6')) { |
|
117 | + if( defined( 'AF_INET6' ) ) { |
|
118 | 118 | $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
119 | 119 | } |
120 | 120 | } |
121 | - $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
122 | - $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
123 | - $whip = new Whip($methods, $whitelist); |
|
124 | - do_action_ref_array('site-reviews/whip', [$whip]); |
|
125 | - if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
126 | - return (string) $clientAddress; |
|
121 | + $whitelist = apply_filters( 'site-reviews/whip/whitelist', $whitelist ); |
|
122 | + $methods = apply_filters( 'site-reviews/whip/methods', Whip::ALL_METHODS ); |
|
123 | + $whip = new Whip( $methods, $whitelist ); |
|
124 | + do_action_ref_array( 'site-reviews/whip', [$whip] ); |
|
125 | + if( false !== ($clientAddress = $whip->getValidIpAddress()) ) { |
|
126 | + return (string)$clientAddress; |
|
127 | 127 | } |
128 | - glsr_log()->error('Unable to detect IP address.'); |
|
128 | + glsr_log()->error( 'Unable to detect IP address.' ); |
|
129 | 129 | return 'unknown'; |
130 | 130 | } |
131 | 131 | } |
@@ -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::consolidateArray($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::consolidateArray( $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::consolidateArray(glsr()->{$this->logOnceKey}); |
|
201 | + $once = Arr::consolidateArray( 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::consolidateArray(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::consolidateArray( 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 | } |
@@ -1,136 +1,136 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -defined('WPINC') || die; |
|
3 | +defined( 'WPINC' ) || die; |
|
4 | 4 | |
5 | -if (apply_filters('site-reviews/support/deprecated/v4', true)) { |
|
5 | +if( apply_filters( 'site-reviews/support/deprecated/v4', true ) ) { |
|
6 | 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)) { |
|
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 | 10 | return $data; |
11 | 11 | } |
12 | 12 | glsr()->deprecated[] = sprintf( |
13 | 13 | 'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.', |
14 | 14 | $metaKey |
15 | 15 | ); |
16 | - return get_post_meta($postId, '_'.$metaKey, $single); |
|
17 | - }, 10, 4); |
|
16 | + return get_post_meta( $postId, '_'.$metaKey, $single ); |
|
17 | + }, 10, 4 ); |
|
18 | 18 | |
19 | 19 | // Modules/Html/Template.php |
20 | - add_filter('site-reviews/interpolate/reviews', function ($context, $template) { |
|
20 | + add_filter( 'site-reviews/interpolate/reviews', function( $context, $template ) { |
|
21 | 21 | $search = '{{ navigation }}'; |
22 | - if (false !== strpos($template, $search)) { |
|
22 | + if( false !== strpos( $template, $search ) ) { |
|
23 | 23 | $context['navigation'] = $context['pagination']; |
24 | 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 | 25 | } |
26 | 26 | return $context; |
27 | - }, 10, 2); |
|
27 | + }, 10, 2 ); |
|
28 | 28 | |
29 | 29 | // Database/ReviewManager.php |
30 | - add_action('site-reviews/review/created', function ($review) { |
|
31 | - if (has_action('site-reviews/local/review/create')) { |
|
30 | + add_action( 'site-reviews/review/created', function( $review ) { |
|
31 | + if( has_action( 'site-reviews/local/review/create' ) ) { |
|
32 | 32 | glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.'; |
33 | - do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID); |
|
33 | + do_action( 'site-reviews/local/review/create', (array)get_post( $review->ID ), (array)$review, $review->ID ); |
|
34 | 34 | } |
35 | - }, 9); |
|
35 | + }, 9 ); |
|
36 | 36 | |
37 | 37 | // Handlers/CreateReview.php |
38 | - add_action('site-reviews/review/submitted', function ($review) { |
|
39 | - if (has_action('site-reviews/local/review/submitted')) { |
|
38 | + add_action( 'site-reviews/review/submitted', function( $review ) { |
|
39 | + if( has_action( 'site-reviews/local/review/submitted' ) ) { |
|
40 | 40 | glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.'; |
41 | - do_action('site-reviews/local/review/submitted', null, $review); |
|
41 | + do_action( 'site-reviews/local/review/submitted', null, $review ); |
|
42 | 42 | } |
43 | - if (has_filter('site-reviews/local/review/submitted/message')) { |
|
43 | + if( has_filter( 'site-reviews/local/review/submitted/message' ) ) { |
|
44 | 44 | glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.'; |
45 | 45 | } |
46 | - }, 9); |
|
46 | + }, 9 ); |
|
47 | 47 | |
48 | 48 | // Database/ReviewManager.php |
49 | - add_filter('site-reviews/create/review-values', function ($values, $command) { |
|
50 | - if (has_filter('site-reviews/local/review')) { |
|
49 | + add_filter( 'site-reviews/create/review-values', function( $values, $command ) { |
|
50 | + if( has_filter( 'site-reviews/local/review' ) ) { |
|
51 | 51 | glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.'; |
52 | - return apply_filters('site-reviews/local/review', $values, $command); |
|
52 | + return apply_filters( 'site-reviews/local/review', $values, $command ); |
|
53 | 53 | } |
54 | 54 | return $values; |
55 | - }, 9, 2); |
|
55 | + }, 9, 2 ); |
|
56 | 56 | |
57 | 57 | // Handlers/EnqueuePublicAssets.php |
58 | - add_filter('site-reviews/enqueue/public/localize', function ($variables) { |
|
59 | - if (has_filter('site-reviews/enqueue/localize')) { |
|
58 | + add_filter( 'site-reviews/enqueue/public/localize', function( $variables ) { |
|
59 | + if( has_filter( 'site-reviews/enqueue/localize' ) ) { |
|
60 | 60 | glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.'; |
61 | - return apply_filters('site-reviews/enqueue/localize', $variables); |
|
61 | + return apply_filters( 'site-reviews/enqueue/localize', $variables ); |
|
62 | 62 | } |
63 | 63 | return $variables; |
64 | - }, 9); |
|
64 | + }, 9 ); |
|
65 | 65 | |
66 | 66 | // Modules/Rating.php |
67 | - add_filter('site-reviews/rating/average', function ($average) { |
|
68 | - if (has_filter('site-reviews/average/rating')) { |
|
67 | + add_filter( 'site-reviews/rating/average', function( $average ) { |
|
68 | + if( has_filter( 'site-reviews/average/rating' ) ) { |
|
69 | 69 | glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.'; |
70 | 70 | } |
71 | 71 | return $average; |
72 | - }, 9); |
|
72 | + }, 9 ); |
|
73 | 73 | |
74 | 74 | // Modules/Rating.php |
75 | - add_filter('site-reviews/rating/ranking', function ($ranking) { |
|
76 | - if (has_filter('site-reviews/bayesian/ranking')) { |
|
75 | + add_filter( 'site-reviews/rating/ranking', function( $ranking ) { |
|
76 | + if( has_filter( 'site-reviews/bayesian/ranking' ) ) { |
|
77 | 77 | glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.'; |
78 | 78 | } |
79 | 79 | return $ranking; |
80 | - }, 9); |
|
80 | + }, 9 ); |
|
81 | 81 | |
82 | 82 | // Modules/Html/Partials/SiteReviews.php |
83 | - add_filter('site-reviews/review/build/after', function ($renderedFields) { |
|
84 | - if (has_filter('site-reviews/reviews/review/text')) { |
|
83 | + add_filter( 'site-reviews/review/build/after', function( $renderedFields ) { |
|
84 | + if( has_filter( 'site-reviews/reviews/review/text' ) ) { |
|
85 | 85 | glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
86 | 86 | } |
87 | - if (has_filter('site-reviews/reviews/review/title')) { |
|
87 | + if( has_filter( 'site-reviews/reviews/review/title' ) ) { |
|
88 | 88 | glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.'; |
89 | 89 | } |
90 | 90 | return $renderedFields; |
91 | - }, 9); |
|
91 | + }, 9 ); |
|
92 | 92 | |
93 | 93 | // Modules/Html/Partials/SiteReviews.php |
94 | - add_filter('site-reviews/review/build/before', function ($review) { |
|
95 | - if (has_filter('site-reviews/rendered/review')) { |
|
94 | + add_filter( 'site-reviews/review/build/before', function( $review ) { |
|
95 | + if( has_filter( 'site-reviews/rendered/review' ) ) { |
|
96 | 96 | 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.'; |
97 | 97 | } |
98 | - if (has_filter('site-reviews/rendered/review/meta/order')) { |
|
98 | + if( has_filter( 'site-reviews/rendered/review/meta/order' ) ) { |
|
99 | 99 | 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).'; |
100 | 100 | } |
101 | - if (has_filter('site-reviews/rendered/review/order')) { |
|
101 | + if( has_filter( 'site-reviews/rendered/review/order' ) ) { |
|
102 | 102 | glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).'; |
103 | 103 | } |
104 | - if (has_filter('site-reviews/rendered/review-form/login-register')) { |
|
104 | + if( has_filter( 'site-reviews/rendered/review-form/login-register' ) ) { |
|
105 | 105 | 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).'; |
106 | 106 | } |
107 | - if (has_filter('site-reviews/reviews/navigation_links')) { |
|
107 | + if( has_filter( 'site-reviews/reviews/navigation_links' ) ) { |
|
108 | 108 | glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).'; |
109 | 109 | } |
110 | 110 | return $review; |
111 | - }, 9); |
|
111 | + }, 9 ); |
|
112 | 112 | |
113 | - add_filter('site-reviews/validate/custom', function ($result, $request) { |
|
114 | - if (has_filter('site-reviews/validate/review/submission')) { |
|
115 | - glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.'); |
|
116 | - return apply_filters('site-reviews/validate/review/submission', $result, $request); |
|
113 | + add_filter( 'site-reviews/validate/custom', function( $result, $request ) { |
|
114 | + if( has_filter( 'site-reviews/validate/review/submission' ) ) { |
|
115 | + glsr_log()->warning( 'The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.' ); |
|
116 | + return apply_filters( 'site-reviews/validate/review/submission', $result, $request ); |
|
117 | 117 | } |
118 | 118 | return $result; |
119 | - }, 9, 2); |
|
119 | + }, 9, 2 ); |
|
120 | 120 | |
121 | - add_filter('site-reviews/views/file', function ($file, $view, $data) { |
|
122 | - if (has_filter('site-reviews/addon/views/file')) { |
|
121 | + add_filter( 'site-reviews/views/file', function( $file, $view, $data ) { |
|
122 | + if( has_filter( 'site-reviews/addon/views/file' ) ) { |
|
123 | 123 | glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.'; |
124 | - $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data); |
|
124 | + $file = apply_filters( 'site-reviews/addon/views/file', $file, $view, $data ); |
|
125 | 125 | } |
126 | 126 | return $file; |
127 | - }, 9, 3); |
|
127 | + }, 9, 3 ); |
|
128 | 128 | } |
129 | 129 | |
130 | -add_action('wp_footer', function () { |
|
131 | - $notices = array_keys(array_flip(glsr()->deprecated)); |
|
132 | - natsort($notices); |
|
133 | - foreach ($notices as $notice) { |
|
134 | - glsr_log()->warning($notice); |
|
130 | +add_action( 'wp_footer', function() { |
|
131 | + $notices = array_keys( array_flip( glsr()->deprecated ) ); |
|
132 | + natsort( $notices ); |
|
133 | + foreach( $notices as $notice ) { |
|
134 | + glsr_log()->warning( $notice ); |
|
135 | 135 | } |
136 | 136 | }); |
@@ -30,21 +30,21 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - public function build(array $args = []) |
|
33 | + public function build( array $args = [] ) |
|
34 | 34 | { |
35 | 35 | $this->args = $args; |
36 | - $schema = $this->buildSummary($args); |
|
36 | + $schema = $this->buildSummary( $args ); |
|
37 | 37 | $reviews = []; |
38 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
38 | + foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) { |
|
39 | 39 | // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
40 | 40 | // @see https://developers.google.com/search/docs/data-types/review |
41 | - if ('local' != $review->review_type) { |
|
41 | + if( 'local' != $review->review_type ) { |
|
42 | 42 | continue; |
43 | 43 | } |
44 | - $reviews[] = $this->buildReview($review); |
|
44 | + $reviews[] = $this->buildReview( $review ); |
|
45 | 45 | } |
46 | - if (!empty($reviews)) { |
|
47 | - array_walk($reviews, function (&$review) { |
|
46 | + if( !empty($reviews) ) { |
|
47 | + array_walk( $reviews, function( &$review ) { |
|
48 | 48 | unset($review['@context']); |
49 | 49 | unset($review['itemReviewed']); |
50 | 50 | }); |
@@ -57,27 +57,27 @@ discard block |
||
57 | 57 | * @param array|null $args |
58 | 58 | * @return array |
59 | 59 | */ |
60 | - public function buildSummary($args = null) |
|
60 | + public function buildSummary( $args = null ) |
|
61 | 61 | { |
62 | - if (is_array($args)) { |
|
62 | + if( is_array( $args ) ) { |
|
63 | 63 | $this->args = $args; |
64 | 64 | } |
65 | - $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
66 | - $count = array_sum($this->getRatingCounts()); |
|
67 | - $schema = method_exists($this, $buildSummary) |
|
65 | + $buildSummary = Helper::buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
|
66 | + $count = array_sum( $this->getRatingCounts() ); |
|
67 | + $schema = method_exists( $this, $buildSummary ) |
|
68 | 68 | ? $this->$buildSummary() |
69 | 69 | : $this->buildSummaryForCustom(); |
70 | - if (!empty($count)) { |
|
70 | + if( !empty($count) ) { |
|
71 | 71 | $schema->aggregateRating( |
72 | - $this->getSchemaType('AggregateRating') |
|
73 | - ->ratingValue($this->getRatingValue()) |
|
74 | - ->reviewCount($count) |
|
75 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
76 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
72 | + $this->getSchemaType( 'AggregateRating' ) |
|
73 | + ->ratingValue( $this->getRatingValue() ) |
|
74 | + ->reviewCount( $count ) |
|
75 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
76 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
77 | 77 | ); |
78 | 78 | } |
79 | 79 | $schema = $schema->toArray(); |
80 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
80 | + return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -85,64 +85,64 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function render() |
87 | 87 | { |
88 | - if (empty(glsr()->schemas)) { |
|
88 | + if( empty(glsr()->schemas) ) { |
|
89 | 89 | return; |
90 | 90 | } |
91 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
92 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
91 | + printf( '<script type="application/ld+json">%s</script>', json_encode( |
|
92 | + apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
|
93 | 93 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
94 | - )); |
|
94 | + ) ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
98 | 98 | * @return void |
99 | 99 | */ |
100 | - public function store(array $schema) |
|
100 | + public function store( array $schema ) |
|
101 | 101 | { |
102 | 102 | $schemas = glsr()->schemas; |
103 | 103 | $schemas[] = $schema; |
104 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
104 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @param Review $review |
109 | 109 | * @return array |
110 | 110 | */ |
111 | - protected function buildReview($review) |
|
111 | + protected function buildReview( $review ) |
|
112 | 112 | { |
113 | - $schema = $this->getSchemaType('Review') |
|
114 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
115 | - $schema->name($review->title); |
|
113 | + $schema = $this->getSchemaType( 'Review' ) |
|
114 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) { |
|
115 | + $schema->name( $review->title ); |
|
116 | 116 | }) |
117 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
118 | - $schema->reviewBody($review->content); |
|
117 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) { |
|
118 | + $schema->reviewBody( $review->content ); |
|
119 | 119 | }) |
120 | - ->datePublished((new DateTime($review->date))) |
|
121 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
122 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
123 | - if (!empty($review->rating)) { |
|
120 | + ->datePublished( (new DateTime( $review->date )) ) |
|
121 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
122 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
123 | + if( !empty($review->rating) ) { |
|
124 | 124 | $schema->reviewRating( |
125 | - $this->getSchemaType('Rating') |
|
126 | - ->ratingValue($review->rating) |
|
127 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
128 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
125 | + $this->getSchemaType( 'Rating' ) |
|
126 | + ->ratingValue( $review->rating ) |
|
127 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
128 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
129 | 129 | ); |
130 | 130 | } |
131 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
131 | + return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @param mixed $schema |
136 | 136 | * @return mixed |
137 | 137 | */ |
138 | - protected function buildSchemaValues($schema, array $values = []) |
|
138 | + protected function buildSchemaValues( $schema, array $values = [] ) |
|
139 | 139 | { |
140 | - foreach ($values as $value) { |
|
141 | - $option = $this->getSchemaOptionValue($value); |
|
142 | - if (empty($option)) { |
|
140 | + foreach( $values as $value ) { |
|
141 | + $option = $this->getSchemaOptionValue( $value ); |
|
142 | + if( empty($option) ) { |
|
143 | 143 | continue; |
144 | 144 | } |
145 | - $schema->$value($option); |
|
145 | + $schema->$value( $option ); |
|
146 | 146 | } |
147 | 147 | return $schema; |
148 | 148 | } |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | */ |
153 | 153 | protected function buildSummaryForCustom() |
154 | 154 | { |
155 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
155 | + return $this->buildSchemaValues( $this->getSchemaType(), [ |
|
156 | 156 | 'description', 'image', 'name', 'url', |
157 | - ]); |
|
157 | + ] ); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | */ |
163 | 163 | protected function buildSummaryForLocalBusiness() |
164 | 164 | { |
165 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
165 | + return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
|
166 | 166 | 'address', 'priceRange', 'telephone', |
167 | - ]); |
|
167 | + ] ); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | */ |
173 | 173 | protected function buildSummaryForProduct() |
174 | 174 | { |
175 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
176 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
175 | + $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' ); |
|
176 | + $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [ |
|
177 | 177 | 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
178 | - ]); |
|
178 | + ] ); |
|
179 | 179 | return $this->buildSummaryForCustom() |
180 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
181 | - $schema->offers($offers); |
|
180 | + ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) { |
|
181 | + $schema->offers( $offers ); |
|
182 | 182 | }) |
183 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
183 | + ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function getRatingCounts() |
190 | 190 | { |
191 | - if (!isset($this->ratingCounts)) { |
|
192 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
191 | + if( !isset($this->ratingCounts) ) { |
|
192 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args ); |
|
193 | 193 | } |
194 | 194 | return $this->ratingCounts; |
195 | 195 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function getRatingValue() |
201 | 201 | { |
202 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
202 | + return glsr( Rating::class )->getAverage( $this->getRatingCounts() ); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -207,15 +207,15 @@ discard block |
||
207 | 207 | * @param string $fallback |
208 | 208 | * @return string |
209 | 209 | */ |
210 | - protected function getSchemaOption($option, $fallback) |
|
210 | + protected function getSchemaOption( $option, $fallback ) |
|
211 | 211 | { |
212 | - $option = strtolower($option); |
|
213 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
212 | + $option = strtolower( $option ); |
|
213 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
214 | 214 | return $schemaOption; |
215 | 215 | } |
216 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
217 | - if (is_array($setting)) { |
|
218 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
216 | + $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
|
217 | + if( is_array( $setting ) ) { |
|
218 | + return $this->getSchemaOptionDefault( $setting, $fallback ); |
|
219 | 219 | } |
220 | 220 | return !empty($setting) |
221 | 221 | ? $setting |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | * @param string $fallback |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
229 | + protected function getSchemaOptionDefault( array $setting, $fallback ) |
|
230 | 230 | { |
231 | - $setting = wp_parse_args($setting, [ |
|
231 | + $setting = wp_parse_args( $setting, [ |
|
232 | 232 | 'custom' => '', |
233 | 233 | 'default' => $fallback, |
234 | - ]); |
|
234 | + ] ); |
|
235 | 235 | return 'custom' != $setting['default'] |
236 | 236 | ? $setting['default'] |
237 | 237 | : $setting['custom']; |
@@ -242,21 +242,21 @@ discard block |
||
242 | 242 | * @param string $fallback |
243 | 243 | * @return void|string |
244 | 244 | */ |
245 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
245 | + protected function getSchemaOptionValue( $option, $fallback = 'post' ) |
|
246 | 246 | { |
247 | - if (array_key_exists($option, $this->keyValues)) { |
|
247 | + if( array_key_exists( $option, $this->keyValues ) ) { |
|
248 | 248 | return $this->keyValues[$option]; |
249 | 249 | } |
250 | - $value = $this->getSchemaOption($option, $fallback); |
|
251 | - if ($value != $fallback) { |
|
252 | - return $this->setAndGetKeyValue($option, $value); |
|
250 | + $value = $this->getSchemaOption( $option, $fallback ); |
|
251 | + if( $value != $fallback ) { |
|
252 | + return $this->setAndGetKeyValue( $option, $value ); |
|
253 | 253 | } |
254 | - if (!is_single() && !is_page()) { |
|
254 | + if( !is_single() && !is_page() ) { |
|
255 | 255 | return; |
256 | 256 | } |
257 | - $method = Helper::buildMethodName($option, 'getThing'); |
|
258 | - if (method_exists($this, $method)) { |
|
259 | - return $this->setAndGetKeyValue($option, $this->$method()); |
|
257 | + $method = Helper::buildMethodName( $option, 'getThing' ); |
|
258 | + if( method_exists( $this, $method ) ) { |
|
259 | + return $this->setAndGetKeyValue( $option, $this->$method() ); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -264,15 +264,15 @@ discard block |
||
264 | 264 | * @param string|null $type |
265 | 265 | * @return mixed |
266 | 266 | */ |
267 | - protected function getSchemaType($type = null) |
|
267 | + protected function getSchemaType( $type = null ) |
|
268 | 268 | { |
269 | - if (!is_string($type)) { |
|
270 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
269 | + if( !is_string( $type ) ) { |
|
270 | + $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
|
271 | 271 | } |
272 | - $className = Helper::buildClassName($type, 'Modules\Schema'); |
|
273 | - return class_exists($className) |
|
272 | + $className = Helper::buildClassName( $type, 'Modules\Schema' ); |
|
273 | + return class_exists( $className ) |
|
274 | 274 | ? new $className() |
275 | - : new UnknownType($type); |
|
275 | + : new UnknownType( $type ); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -281,19 +281,19 @@ discard block |
||
281 | 281 | protected function getThingDescription() |
282 | 282 | { |
283 | 283 | $post = get_post(); |
284 | - $text = Arr::get($post, 'post_excerpt'); |
|
285 | - if (empty($text)) { |
|
286 | - $text = Arr::get($post, 'post_content'); |
|
284 | + $text = Arr::get( $post, 'post_excerpt' ); |
|
285 | + if( empty($text) ) { |
|
286 | + $text = Arr::get( $post, 'post_content' ); |
|
287 | 287 | } |
288 | - if (function_exists('excerpt_remove_blocks')) { |
|
289 | - $text = excerpt_remove_blocks($text); |
|
288 | + if( function_exists( 'excerpt_remove_blocks' ) ) { |
|
289 | + $text = excerpt_remove_blocks( $text ); |
|
290 | 290 | } |
291 | - $text = strip_shortcodes($text); |
|
292 | - $text = wpautop($text); |
|
293 | - $text = wptexturize($text); |
|
294 | - $text = wp_strip_all_tags($text); |
|
295 | - $text = str_replace(']]>', ']]>', $text); |
|
296 | - return wp_trim_words($text, apply_filters('excerpt_length', 55)); |
|
291 | + $text = strip_shortcodes( $text ); |
|
292 | + $text = wpautop( $text ); |
|
293 | + $text = wptexturize( $text ); |
|
294 | + $text = wp_strip_all_tags( $text ); |
|
295 | + $text = str_replace( ']]>', ']]>', $text ); |
|
296 | + return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) ); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | */ |
302 | 302 | protected function getThingImage() |
303 | 303 | { |
304 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
304 | + return (string)get_the_post_thumbnail_url( null, 'large' ); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | */ |
318 | 318 | protected function getThingUrl() |
319 | 319 | { |
320 | - return (string) get_the_permalink(); |
|
320 | + return (string)get_the_permalink(); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @param string $value |
326 | 326 | * @return string |
327 | 327 | */ |
328 | - protected function setAndGetKeyValue($option, $value) |
|
328 | + protected function setAndGetKeyValue( $option, $value ) |
|
329 | 329 | { |
330 | 330 | $this->keyValues[$option] = $value; |
331 | 331 | return $value; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public function enqueueAssets() |
28 | 28 | { |
29 | - if (apply_filters('site-reviews/assets/css', true)) { |
|
29 | + if( apply_filters( 'site-reviews/assets/css', true ) ) { |
|
30 | 30 | wp_enqueue_style( |
31 | 31 | Application::ID, |
32 | 32 | $this->getStylesheet(), |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | glsr()->version |
35 | 35 | ); |
36 | 36 | } |
37 | - if (apply_filters('site-reviews/assets/js', true)) { |
|
38 | - $dependencies = apply_filters('site-reviews/assets/polyfill', true) |
|
37 | + if( apply_filters( 'site-reviews/assets/js', true ) ) { |
|
38 | + $dependencies = apply_filters( 'site-reviews/assets/polyfill', true ) |
|
39 | 39 | ? [Application::ID.'/polyfill'] |
40 | 40 | : []; |
41 | - $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies); |
|
41 | + $dependencies = apply_filters( 'site-reviews/enqueue/public/dependencies', $dependencies ); |
|
42 | 42 | wp_enqueue_script( |
43 | 43 | Application::ID, |
44 | - glsr()->url('assets/scripts/'.Application::ID.'.js'), |
|
44 | + glsr()->url( 'assets/scripts/'.Application::ID.'.js' ), |
|
45 | 45 | $dependencies, |
46 | 46 | glsr()->version, |
47 | 47 | true |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function enqueuePolyfillService() |
56 | 56 | { |
57 | - if (!apply_filters('site-reviews/assets/polyfill', true)) { |
|
57 | + if( !apply_filters( 'site-reviews/assets/polyfill', true ) ) { |
|
58 | 58 | return; |
59 | 59 | } |
60 | - wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([ |
|
60 | + wp_enqueue_script( Application::ID.'/polyfill', add_query_arg( [ |
|
61 | 61 | 'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver', |
62 | 62 | 'flags' => 'gated', |
63 | - ], 'https://polyfill.io/v3/polyfill.min.js')); |
|
63 | + ], 'https://polyfill.io/v3/polyfill.min.js' ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | // wpforms-recaptcha |
72 | 72 | // google-recaptcha |
73 | 73 | // nf-google-recaptcha |
74 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
74 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
75 | 75 | return; |
76 | 76 | } |
77 | - $language = apply_filters('site-reviews/recaptcha/language', get_locale()); |
|
78 | - wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([ |
|
77 | + $language = apply_filters( 'site-reviews/recaptcha/language', get_locale() ); |
|
78 | + wp_enqueue_script( Application::ID.'/google-recaptcha', add_query_arg( [ |
|
79 | 79 | 'hl' => $language, |
80 | 80 | 'render' => 'explicit', |
81 | - ], 'https://www.google.com/recaptcha/api.js')); |
|
81 | + ], 'https://www.google.com/recaptcha/api.js' ) ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | $variables = [ |
90 | 90 | 'action' => Application::PREFIX.'action', |
91 | 91 | 'ajaxpagination' => $this->getFixedSelectorsForPagination(), |
92 | - 'ajaxurl' => admin_url('admin-ajax.php'), |
|
92 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
93 | 93 | 'nameprefix' => Application::ID, |
94 | - 'validationconfig' => glsr(Style::class)->validation, |
|
95 | - 'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(), |
|
94 | + 'validationconfig' => glsr( Style::class )->validation, |
|
95 | + 'validationstrings' => glsr( ValidationStringsDefaults::class )->defaults(), |
|
96 | 96 | ]; |
97 | - $variables = apply_filters('site-reviews/enqueue/public/localize', $variables); |
|
98 | - wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before'); |
|
97 | + $variables = apply_filters( 'site-reviews/enqueue/public/localize', $variables ); |
|
98 | + wp_add_inline_script( Application::ID, $this->buildInlineScript( $variables ), 'before' ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,35 +103,35 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function inlineStyles() |
105 | 105 | { |
106 | - $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css'); |
|
107 | - if (!apply_filters('site-reviews/assets/css', true)) { |
|
106 | + $inlineStylesheetPath = glsr()->path( 'assets/styles/inline-styles.css' ); |
|
107 | + if( !apply_filters( 'site-reviews/assets/css', true ) ) { |
|
108 | 108 | return; |
109 | 109 | } |
110 | - if (!file_exists($inlineStylesheetPath)) { |
|
111 | - glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath); |
|
110 | + if( !file_exists( $inlineStylesheetPath ) ) { |
|
111 | + glsr_log()->error( 'Inline stylesheet is missing: '.$inlineStylesheetPath ); |
|
112 | 112 | return; |
113 | 113 | } |
114 | - $inlineStylesheetValues = glsr()->config('inline-styles'); |
|
114 | + $inlineStylesheetValues = glsr()->config( 'inline-styles' ); |
|
115 | 115 | $stylesheet = str_replace( |
116 | - array_keys($inlineStylesheetValues), |
|
117 | - array_values($inlineStylesheetValues), |
|
118 | - file_get_contents($inlineStylesheetPath) |
|
116 | + array_keys( $inlineStylesheetValues ), |
|
117 | + array_values( $inlineStylesheetValues ), |
|
118 | + file_get_contents( $inlineStylesheetPath ) |
|
119 | 119 | ); |
120 | - wp_add_inline_style(Application::ID, $stylesheet); |
|
120 | + wp_add_inline_style( Application::ID, $stylesheet ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
124 | 124 | * @return string |
125 | 125 | */ |
126 | - protected function buildInlineScript(array $variables) |
|
126 | + protected function buildInlineScript( array $variables ) |
|
127 | 127 | { |
128 | 128 | $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});'; |
129 | - foreach ($variables as $key => $value) { |
|
130 | - $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); |
|
129 | + foreach( $variables as $key => $value ) { |
|
130 | + $script .= sprintf( 'GLSR.%s=%s;', $key, json_encode( $value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) ); |
|
131 | 131 | } |
132 | 132 | $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys |
133 | - $optimizedScript = preg_replace($pattern, '$1$2', $script); |
|
134 | - return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables); |
|
133 | + $optimizedScript = preg_replace( $pattern, '$1$2', $script ); |
|
134 | + return apply_filters( 'site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | protected function getFixedSelectorsForPagination() |
141 | 141 | { |
142 | 142 | $selectors = ['#wpadminbar', '.site-navigation-fixed']; |
143 | - return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors); |
|
143 | + return apply_filters( 'site-reviews/enqueue/public/localize/ajax-pagination', $selectors ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | */ |
149 | 149 | protected function getStylesheet() |
150 | 150 | { |
151 | - $currentStyle = glsr(Style::class)->style; |
|
152 | - return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css')) |
|
153 | - ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css') |
|
154 | - : glsr()->url('assets/styles/'.Application::ID.'.css'); |
|
151 | + $currentStyle = glsr( Style::class )->style; |
|
152 | + return file_exists( glsr()->path( 'assets/styles/custom/'.$currentStyle.'.css' ) ) |
|
153 | + ? glsr()->url( 'assets/styles/custom/'.$currentStyle.'.css' ) |
|
154 | + : glsr()->url( 'assets/styles/'.Application::ID.'.css' ); |
|
155 | 155 | } |
156 | 156 | } |