@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function customizePostStatusLabels() |
27 | 27 | { |
28 | - glsr(Labels::class)->customizePostStatusLabels(); |
|
28 | + glsr( Labels::class )->customizePostStatusLabels(); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | * @return array |
34 | 34 | * @filter wp_editor_settings |
35 | 35 | */ |
36 | - public function filterEditorSettings($settings) |
|
36 | + public function filterEditorSettings( $settings ) |
|
37 | 37 | { |
38 | - return glsr(Customization::class)->filterEditorSettings( |
|
39 | - glsr(Helper::class)->consolidateArray($settings) |
|
38 | + return glsr( Customization::class )->filterEditorSettings( |
|
39 | + glsr( Helper::class )->consolidateArray( $settings ) |
|
40 | 40 | ); |
41 | 41 | } |
42 | 42 | |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * @return string |
47 | 47 | * @filter the_editor |
48 | 48 | */ |
49 | - public function filterEditorTextarea($html) |
|
49 | + public function filterEditorTextarea( $html ) |
|
50 | 50 | { |
51 | - return glsr(Customization::class)->filterEditorTextarea($html); |
|
51 | + return glsr( Customization::class )->filterEditorTextarea( $html ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | * @return bool |
59 | 59 | * @filter is_protected_meta |
60 | 60 | */ |
61 | - public function filterIsProtectedMeta($protected, $metaKey, $metaType) |
|
61 | + public function filterIsProtectedMeta( $protected, $metaKey, $metaType ) |
|
62 | 62 | { |
63 | - if ('post' == $metaType && Application::POST_TYPE == get_post_type()) { |
|
64 | - $values = glsr(CreateReviewDefaults::class)->unguarded(); |
|
65 | - $values = glsr(Helper::class)->prefixArrayKeys($values); |
|
66 | - if (array_key_exists($metaKey, $values)) { |
|
63 | + if( 'post' == $metaType && Application::POST_TYPE == get_post_type() ) { |
|
64 | + $values = glsr( CreateReviewDefaults::class )->unguarded(); |
|
65 | + $values = glsr( Helper::class )->prefixArrayKeys( $values ); |
|
66 | + if( array_key_exists( $metaKey, $values ) ) { |
|
67 | 67 | $protected = false; |
68 | 68 | } |
69 | 69 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @return string |
78 | 78 | * @filter gettext |
79 | 79 | */ |
80 | - public function filterPostStatusLabels($translation, $text, $domain) |
|
80 | + public function filterPostStatusLabels( $translation, $text, $domain ) |
|
81 | 81 | { |
82 | - return glsr(Labels::class)->filterPostStatusLabels($translation, $text, $domain); |
|
82 | + return glsr( Labels::class )->filterPostStatusLabels( $translation, $text, $domain ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | * @return string |
90 | 90 | * @filter gettext_with_context |
91 | 91 | */ |
92 | - public function filterPostStatusLabelsWithContext($translation, $text, $context, $domain) |
|
92 | + public function filterPostStatusLabelsWithContext( $translation, $text, $context, $domain ) |
|
93 | 93 | { |
94 | - return glsr(Labels::class)->filterPostStatusLabels($translation, $text, $domain); |
|
94 | + return glsr( Labels::class )->filterPostStatusLabels( $translation, $text, $domain ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | * @return array |
100 | 100 | * @filter post_updated_messages |
101 | 101 | */ |
102 | - public function filterUpdateMessages($messages) |
|
102 | + public function filterUpdateMessages( $messages ) |
|
103 | 103 | { |
104 | - return glsr(Labels::class)->filterUpdateMessages( |
|
105 | - glsr(Helper::class)->consolidateArray($messages) |
|
104 | + return glsr( Labels::class )->filterUpdateMessages( |
|
105 | + glsr( Helper::class )->consolidateArray( $messages ) |
|
106 | 106 | ); |
107 | 107 | } |
108 | 108 | |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | * @return void |
111 | 111 | * @action add_meta_boxes_{Application::POST_TYPE} |
112 | 112 | */ |
113 | - public function registerMetaBoxes($post) |
|
113 | + public function registerMetaBoxes( $post ) |
|
114 | 114 | { |
115 | - add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
116 | - add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
117 | - if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) { |
|
115 | + add_meta_box( Application::ID.'_assigned_to', __( 'Assigned To', 'site-reviews' ), [$this, 'renderAssignedToMetabox'], null, 'side' ); |
|
116 | + add_meta_box( Application::ID.'_review', __( 'Details', 'site-reviews' ), [$this, 'renderDetailsMetaBox'], null, 'side' ); |
|
117 | + if( 'local' != glsr( Database::class )->get( $post->ID, 'review_type' ) ) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | - add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
120 | + add_meta_box( Application::ID.'_response', __( 'Respond Publicly', 'site-reviews' ), [$this, 'renderResponseMetaBox'], null, 'normal' ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function removeAutosave() |
128 | 128 | { |
129 | - glsr(Customization::class)->removeAutosave(); |
|
129 | + glsr( Customization::class )->removeAutosave(); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function removeMetaBoxes() |
137 | 137 | { |
138 | - glsr(Customization::class)->removeMetaBoxes(); |
|
138 | + glsr( Customization::class )->removeMetaBoxes(); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function removePostTypeSupport() |
145 | 145 | { |
146 | - glsr(Customization::class)->removePostTypeSupport(); |
|
146 | + glsr( Customization::class )->removePostTypeSupport(); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,17 +151,17 @@ discard block |
||
151 | 151 | * @return void |
152 | 152 | * @callback add_meta_box |
153 | 153 | */ |
154 | - public function renderAssignedToMetabox($post) |
|
154 | + public function renderAssignedToMetabox( $post ) |
|
155 | 155 | { |
156 | - if (!$this->isReviewPostType($post)) { |
|
156 | + if( !$this->isReviewPostType( $post ) ) { |
|
157 | 157 | return; |
158 | 158 | } |
159 | - $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to'); |
|
160 | - wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
161 | - glsr()->render('partials/editor/metabox-assigned-to', [ |
|
159 | + $assignedTo = (string)glsr( Database::class )->get( $post->ID, 'assigned_to' ); |
|
160 | + wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false ); |
|
161 | + glsr()->render( 'partials/editor/metabox-assigned-to', [ |
|
162 | 162 | 'id' => $assignedTo, |
163 | - 'template' => $this->buildAssignedToTemplate($assignedTo, $post), |
|
164 | - ]); |
|
163 | + 'template' => $this->buildAssignedToTemplate( $assignedTo, $post ), |
|
164 | + ] ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -169,16 +169,16 @@ discard block |
||
169 | 169 | * @return void |
170 | 170 | * @callback add_meta_box |
171 | 171 | */ |
172 | - public function renderDetailsMetaBox($post) |
|
172 | + public function renderDetailsMetaBox( $post ) |
|
173 | 173 | { |
174 | - if (!$this->isReviewPostType($post)) { |
|
174 | + if( !$this->isReviewPostType( $post ) ) { |
|
175 | 175 | return; |
176 | 176 | } |
177 | - $review = glsr_get_review($post); |
|
178 | - glsr()->render('partials/editor/metabox-details', [ |
|
179 | - 'button' => $this->buildDetailsMetaBoxRevertButton($review, $post), |
|
180 | - 'metabox' => $this->normalizeDetailsMetaBox($review), |
|
181 | - ]); |
|
177 | + $review = glsr_get_review( $post ); |
|
178 | + glsr()->render( 'partials/editor/metabox-details', [ |
|
179 | + 'button' => $this->buildDetailsMetaBoxRevertButton( $review, $post ), |
|
180 | + 'metabox' => $this->normalizeDetailsMetaBox( $review ), |
|
181 | + ] ); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -187,16 +187,16 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function renderPinnedInPublishMetaBox() |
189 | 189 | { |
190 | - if (!$this->isReviewPostType(get_post())) { |
|
190 | + if( !$this->isReviewPostType( get_post() ) ) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | - glsr(Template::class)->render('partials/editor/pinned', [ |
|
193 | + glsr( Template::class )->render( 'partials/editor/pinned', [ |
|
194 | 194 | 'context' => [ |
195 | - 'no' => __('No', 'site-reviews'), |
|
196 | - 'yes' => __('Yes', 'site-reviews'), |
|
195 | + 'no' => __( 'No', 'site-reviews' ), |
|
196 | + 'yes' => __( 'Yes', 'site-reviews' ), |
|
197 | 197 | ], |
198 | - 'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')), |
|
199 | - ]); |
|
198 | + 'pinned' => wp_validate_boolean( glsr( Database::class )->get( get_the_ID(), 'pinned' ) ), |
|
199 | + ] ); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -204,15 +204,15 @@ discard block |
||
204 | 204 | * @return void |
205 | 205 | * @callback add_meta_box |
206 | 206 | */ |
207 | - public function renderResponseMetaBox($post) |
|
207 | + public function renderResponseMetaBox( $post ) |
|
208 | 208 | { |
209 | - if (!$this->isReviewPostType($post)) { |
|
209 | + if( !$this->isReviewPostType( $post ) ) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | - wp_nonce_field('response', '_nonce-response', false); |
|
213 | - glsr()->render('partials/editor/metabox-response', [ |
|
214 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
215 | - ]); |
|
212 | + wp_nonce_field( 'response', '_nonce-response', false ); |
|
213 | + glsr()->render( 'partials/editor/metabox-response', [ |
|
214 | + 'response' => glsr( Database::class )->get( $post->ID, 'response' ), |
|
215 | + ] ); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -220,15 +220,15 @@ discard block |
||
220 | 220 | * @return void |
221 | 221 | * @action edit_form_after_title |
222 | 222 | */ |
223 | - public function renderReviewEditor($post) |
|
223 | + public function renderReviewEditor( $post ) |
|
224 | 224 | { |
225 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
225 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) ) { |
|
226 | 226 | return; |
227 | 227 | } |
228 | - glsr()->render('partials/editor/review', [ |
|
228 | + glsr()->render( 'partials/editor/review', [ |
|
229 | 229 | 'post' => $post, |
230 | - 'response' => glsr(Database::class)->get($post->ID, 'response'), |
|
231 | - ]); |
|
230 | + 'response' => glsr( Database::class )->get( $post->ID, 'response' ), |
|
231 | + ] ); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -238,11 +238,11 @@ discard block |
||
238 | 238 | public function renderReviewFields() |
239 | 239 | { |
240 | 240 | $screen = glsr_current_screen(); |
241 | - if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) { |
|
241 | + if( 'post' != $screen->base || Application::POST_TYPE != $screen->post_type ) { |
|
242 | 242 | return; |
243 | 243 | } |
244 | - add_action('edit_form_after_title', [$this, 'renderReviewEditor']); |
|
245 | - add_action('edit_form_top', [$this, 'renderReviewNotice']); |
|
244 | + add_action( 'edit_form_after_title', [$this, 'renderReviewEditor'] ); |
|
245 | + add_action( 'edit_form_top', [$this, 'renderReviewNotice'] ); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -250,20 +250,20 @@ discard block |
||
250 | 250 | * @return void |
251 | 251 | * @action edit_form_top |
252 | 252 | */ |
253 | - public function renderReviewNotice($post) |
|
253 | + public function renderReviewNotice( $post ) |
|
254 | 254 | { |
255 | - if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) { |
|
255 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) ) { |
|
256 | 256 | return; |
257 | 257 | } |
258 | - glsr(Notice::class)->addWarning(sprintf( |
|
259 | - __('%s reviews are read-only.', 'site-reviews'), |
|
260 | - glsr(Columns::class)->buildColumnReviewType($post->ID) |
|
261 | - )); |
|
262 | - glsr(Template::class)->render('partials/editor/notice', [ |
|
258 | + glsr( Notice::class )->addWarning( sprintf( |
|
259 | + __( '%s reviews are read-only.', 'site-reviews' ), |
|
260 | + glsr( Columns::class )->buildColumnReviewType( $post->ID ) |
|
261 | + ) ); |
|
262 | + glsr( Template::class )->render( 'partials/editor/notice', [ |
|
263 | 263 | 'context' => [ |
264 | - 'notices' => glsr(Notice::class)->get(), |
|
264 | + 'notices' => glsr( Notice::class )->get(), |
|
265 | 265 | ], |
266 | - ]); |
|
266 | + ] ); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -272,16 +272,16 @@ discard block |
||
272 | 272 | * @see glsr_categories_meta_box() |
273 | 273 | * @callback register_taxonomy |
274 | 274 | */ |
275 | - public function renderTaxonomyMetabox($post) |
|
275 | + public function renderTaxonomyMetabox( $post ) |
|
276 | 276 | { |
277 | - if (!$this->isReviewPostType($post)) { |
|
277 | + if( !$this->isReviewPostType( $post ) ) { |
|
278 | 278 | return; |
279 | 279 | } |
280 | - glsr()->render('partials/editor/metabox-categories', [ |
|
280 | + glsr()->render( 'partials/editor/metabox-categories', [ |
|
281 | 281 | 'post' => $post, |
282 | 282 | 'tax_name' => Application::TAXONOMY, |
283 | - 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
284 | - ]); |
|
283 | + 'taxonomy' => get_taxonomy( Application::TAXONOMY ), |
|
284 | + ] ); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function revertReview() |
293 | 293 | { |
294 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
294 | + if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) { |
|
295 | 295 | return; |
296 | 296 | } |
297 | - check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
298 | - glsr(ReviewManager::class)->revert($postId); |
|
299 | - $this->redirect($postId, 52); |
|
297 | + check_admin_referer( 'revert-review_'.($postId = $this->getPostId()) ); |
|
298 | + glsr( ReviewManager::class )->revert( $postId ); |
|
299 | + $this->redirect( $postId, 52 ); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -304,79 +304,79 @@ discard block |
||
304 | 304 | * @return void |
305 | 305 | * @action save_post_.Application::POST_TYPE |
306 | 306 | */ |
307 | - public function saveMetaboxes($postId) |
|
307 | + public function saveMetaboxes( $postId ) |
|
308 | 308 | { |
309 | - glsr(Metaboxes::class)->saveAssignedToMetabox($postId); |
|
310 | - glsr(Metaboxes::class)->saveResponseMetabox($postId); |
|
311 | - do_action('site-reviews/review/saved', glsr_get_review($postId)); |
|
309 | + glsr( Metaboxes::class )->saveAssignedToMetabox( $postId ); |
|
310 | + glsr( Metaboxes::class )->saveResponseMetabox( $postId ); |
|
311 | + do_action( 'site-reviews/review/saved', glsr_get_review( $postId ) ); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
315 | 315 | * @param string $assignedTo |
316 | 316 | * @return string |
317 | 317 | */ |
318 | - protected function buildAssignedToTemplate($assignedTo, WP_Post $post) |
|
318 | + protected function buildAssignedToTemplate( $assignedTo, WP_Post $post ) |
|
319 | 319 | { |
320 | - $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo); |
|
321 | - if (!($assignedPost instanceof WP_Post)) { |
|
320 | + $assignedPost = glsr( Database::class )->getAssignedToPost( $post->ID, $assignedTo ); |
|
321 | + if( !($assignedPost instanceof WP_Post) ) { |
|
322 | 322 | return; |
323 | 323 | } |
324 | - return glsr(Template::class)->build('partials/editor/assigned-post', [ |
|
324 | + return glsr( Template::class )->build( 'partials/editor/assigned-post', [ |
|
325 | 325 | 'context' => [ |
326 | - 'data.url' => (string) get_permalink($assignedPost), |
|
327 | - 'data.title' => get_the_title($assignedPost), |
|
326 | + 'data.url' => (string)get_permalink( $assignedPost ), |
|
327 | + 'data.title' => get_the_title( $assignedPost ), |
|
328 | 328 | ], |
329 | - ]); |
|
329 | + ] ); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
333 | 333 | * @return string |
334 | 334 | */ |
335 | - protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post) |
|
335 | + protected function buildDetailsMetaBoxRevertButton( Review $review, WP_Post $post ) |
|
336 | 336 | { |
337 | - $isModified = !glsr(Helper::class)->compareArrays( |
|
337 | + $isModified = !glsr( Helper::class )->compareArrays( |
|
338 | 338 | [$review->title, $review->content, $review->date], |
339 | 339 | [ |
340 | - glsr(Database::class)->get($post->ID, 'title'), |
|
341 | - glsr(Database::class)->get($post->ID, 'content'), |
|
342 | - glsr(Database::class)->get($post->ID, 'date'), |
|
340 | + glsr( Database::class )->get( $post->ID, 'title' ), |
|
341 | + glsr( Database::class )->get( $post->ID, 'content' ), |
|
342 | + glsr( Database::class )->get( $post->ID, 'date' ), |
|
343 | 343 | ] |
344 | 344 | ); |
345 | - if ($isModified) { |
|
345 | + if( $isModified ) { |
|
346 | 346 | $revertUrl = wp_nonce_url( |
347 | - admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID), |
|
347 | + admin_url( 'post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID ), |
|
348 | 348 | 'revert-review_'.$post->ID |
349 | 349 | ); |
350 | - return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [ |
|
350 | + return glsr( Builder::class )->a( __( 'Revert Changes', 'site-reviews' ), [ |
|
351 | 351 | 'class' => 'button button-large', |
352 | 352 | 'href' => $revertUrl, |
353 | 353 | 'id' => 'revert', |
354 | - ]); |
|
354 | + ] ); |
|
355 | 355 | } |
356 | - return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [ |
|
356 | + return glsr( Builder::class )->button( __( 'Nothing to Revert', 'site-reviews' ), [ |
|
357 | 357 | 'class' => 'button-large', |
358 | 358 | 'disabled' => true, |
359 | 359 | 'id' => 'revert', |
360 | - ]); |
|
360 | + ] ); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
364 | 364 | * @param object $review |
365 | 365 | * @return string|void |
366 | 366 | */ |
367 | - protected function getReviewType($review) |
|
367 | + protected function getReviewType( $review ) |
|
368 | 368 | { |
369 | - if (count(glsr()->reviewTypes) < 2) { |
|
369 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
370 | 370 | return; |
371 | 371 | } |
372 | - $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes) |
|
372 | + $reviewType = array_key_exists( $review->review_type, glsr()->reviewTypes ) |
|
373 | 373 | ? glsr()->reviewTypes[$review->review_type] |
374 | - : __('Unknown', 'site-reviews'); |
|
375 | - if (!empty($review->url)) { |
|
376 | - $reviewType = glsr(Builder::class)->a($reviewType, [ |
|
374 | + : __( 'Unknown', 'site-reviews' ); |
|
375 | + if( !empty($review->url) ) { |
|
376 | + $reviewType = glsr( Builder::class )->a( $reviewType, [ |
|
377 | 377 | 'href' => $review->url, |
378 | 378 | 'target' => '_blank', |
379 | - ]); |
|
379 | + ] ); |
|
380 | 380 | } |
381 | 381 | return $reviewType; |
382 | 382 | } |
@@ -384,18 +384,18 @@ discard block |
||
384 | 384 | /** |
385 | 385 | * @return bool |
386 | 386 | */ |
387 | - protected function isReviewEditable($post) |
|
387 | + protected function isReviewEditable( $post ) |
|
388 | 388 | { |
389 | - return $this->isReviewPostType($post) |
|
390 | - && post_type_supports(Application::POST_TYPE, 'title') |
|
391 | - && 'local' == glsr(Database::class)->get($post->ID, 'review_type'); |
|
389 | + return $this->isReviewPostType( $post ) |
|
390 | + && post_type_supports( Application::POST_TYPE, 'title' ) |
|
391 | + && 'local' == glsr( Database::class )->get( $post->ID, 'review_type' ); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | 395 | * @param mixed $post |
396 | 396 | * @return bool |
397 | 397 | */ |
398 | - protected function isReviewPostType($post) |
|
398 | + protected function isReviewPostType( $post ) |
|
399 | 399 | { |
400 | 400 | return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type; |
401 | 401 | } |
@@ -403,29 +403,29 @@ discard block |
||
403 | 403 | /** |
404 | 404 | * @return array |
405 | 405 | */ |
406 | - protected function normalizeDetailsMetaBox(Review $review) |
|
406 | + protected function normalizeDetailsMetaBox( Review $review ) |
|
407 | 407 | { |
408 | 408 | $user = empty($review->user_id) |
409 | - ? __('Unregistered user', 'site-reviews') |
|
410 | - : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [ |
|
411 | - 'href' => get_author_posts_url($review->user_id), |
|
412 | - ]); |
|
409 | + ? __( 'Unregistered user', 'site-reviews' ) |
|
410 | + : glsr( Builder::class )->a( get_the_author_meta( 'display_name', $review->user_id ), [ |
|
411 | + 'href' => get_author_posts_url( $review->user_id ), |
|
412 | + ] ); |
|
413 | 413 | $email = empty($review->email) |
414 | 414 | ? '—' |
415 | - : glsr(Builder::class)->a($review->email, [ |
|
416 | - 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
417 | - ]); |
|
415 | + : glsr( Builder::class )->a( $review->email, [ |
|
416 | + 'href' => 'mailto:'.$review->email.'?subject='.esc_attr( __( 'RE:', 'site-reviews' ).' '.$review->title ), |
|
417 | + ] ); |
|
418 | 418 | $metabox = [ |
419 | - __('Rating', 'site-reviews') => glsr_star_rating($review->rating), |
|
420 | - __('Type', 'site-reviews') => $this->getReviewType($review), |
|
421 | - __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
422 | - __('Name', 'site-reviews') => $review->author, |
|
423 | - __('Email', 'site-reviews') => $email, |
|
424 | - __('User', 'site-reviews') => $user, |
|
425 | - __('IP Address', 'site-reviews') => $review->ip_address, |
|
426 | - __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
419 | + __( 'Rating', 'site-reviews' ) => glsr_star_rating( $review->rating ), |
|
420 | + __( 'Type', 'site-reviews' ) => $this->getReviewType( $review ), |
|
421 | + __( 'Date', 'site-reviews' ) => get_date_from_gmt( $review->date, 'F j, Y' ), |
|
422 | + __( 'Name', 'site-reviews' ) => $review->author, |
|
423 | + __( 'Email', 'site-reviews' ) => $email, |
|
424 | + __( 'User', 'site-reviews' ) => $user, |
|
425 | + __( 'IP Address', 'site-reviews' ) => $review->ip_address, |
|
426 | + __( 'Avatar', 'site-reviews' ) => sprintf( '<img src="%s" width="96">', $review->avatar ), |
|
427 | 427 | ]; |
428 | - return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review)); |
|
428 | + return array_filter( apply_filters( 'site-reviews/metabox/details', $metabox, $review ) ); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
@@ -433,16 +433,16 @@ discard block |
||
433 | 433 | * @param int $messageIndex |
434 | 434 | * @return void |
435 | 435 | */ |
436 | - protected function redirect($postId, $messageIndex) |
|
436 | + protected function redirect( $postId, $messageIndex ) |
|
437 | 437 | { |
438 | 438 | $referer = wp_get_referer(); |
439 | 439 | $hasReferer = !$referer |
440 | - || false !== strpos($referer, 'post.php') |
|
441 | - || false !== strpos($referer, 'post-new.php'); |
|
440 | + || false !== strpos( $referer, 'post.php' ) |
|
441 | + || false !== strpos( $referer, 'post-new.php' ); |
|
442 | 442 | $redirectUri = $hasReferer |
443 | - ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
444 | - : get_edit_post_link($postId); |
|
445 | - wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
443 | + ? remove_query_arg( ['deleted', 'ids', 'trashed', 'untrashed'], $referer ) |
|
444 | + : get_edit_post_link( $postId ); |
|
445 | + wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri ) ); |
|
446 | 446 | exit; |
447 | 447 | } |
448 | 448 | } |
@@ -11,28 +11,28 @@ discard block |
||
11 | 11 | /** |
12 | 12 | * @return void|array |
13 | 13 | */ |
14 | - public function sendReview(Review $review) |
|
14 | + public function sendReview( Review $review ) |
|
15 | 15 | { |
16 | - return $this->send('index.php', [ |
|
17 | - 'body' => $this->getBodyForReview($review), |
|
16 | + return $this->send( 'index.php', [ |
|
17 | + 'body' => $this->getBodyForReview( $review ), |
|
18 | 18 | 'timeout' => 120, |
19 | - ]); |
|
19 | + ] ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @return void|array |
24 | 24 | */ |
25 | - public function sendReviewResponse(Review $review) |
|
25 | + public function sendReviewResponse( Review $review ) |
|
26 | 26 | { |
27 | - return $this->send('fetch_customer_reply.php', [ |
|
28 | - 'body' => $this->getBodyForResponse($review), |
|
29 | - ]); |
|
27 | + return $this->send( 'fetch_customer_reply.php', [ |
|
28 | + 'body' => $this->getBodyForResponse( $review ), |
|
29 | + ] ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @return array |
34 | 34 | */ |
35 | - protected function getBodyForResponse(Review $review) |
|
35 | + protected function getBodyForResponse( Review $review ) |
|
36 | 36 | { |
37 | 37 | $rebusifyResponse = [ |
38 | 38 | 'reply' => $review->response, // what is the 300 character limit for? |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | 'review_transaction_id' => '', // @todo |
41 | 41 | 'type' => 'M', |
42 | 42 | ]; |
43 | - return apply_filters('site-reviews/rebusify/response', $rebusifyResponse, $review); |
|
43 | + return apply_filters( 'site-reviews/rebusify/response', $rebusifyResponse, $review ); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @return array |
48 | 48 | */ |
49 | - protected function getBodyForReview(Review $review) |
|
49 | + protected function getBodyForReview( Review $review ) |
|
50 | 50 | { |
51 | 51 | $rebusifyReview = [ |
52 | 52 | 'domain' => get_site_url(), |
@@ -57,30 +57,30 @@ discard block |
||
57 | 57 | 'title' => $review->title, // what is the 35 character limit for? |
58 | 58 | 'transaction' => '', // @todo |
59 | 59 | ]; |
60 | - return apply_filters('site-reviews/rebusify/review', $rebusifyReview, $review); |
|
60 | + return apply_filters( 'site-reviews/rebusify/review', $rebusifyReview, $review ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @return void|array |
65 | 65 | */ |
66 | - protected function send($endpoint, $args) |
|
66 | + protected function send( $endpoint, $args ) |
|
67 | 67 | { |
68 | - $args = wp_parse_args($args, [ |
|
68 | + $args = wp_parse_args( $args, [ |
|
69 | 69 | 'blocking' => false, |
70 | 70 | 'body' => [], |
71 | 71 | 'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], |
72 | 72 | 'redirection' => 5, |
73 | 73 | 'sslverify' => false, |
74 | 74 | 'timeout' => 5, |
75 | - ]); |
|
76 | - $response = wp_remote_post(trailingslashit(static::API_URL).$endpoint, $args); |
|
77 | - if (is_wp_error($response)) { |
|
78 | - glsr_log()->error('REBUSIFY: '.$response->get_error_message()); |
|
75 | + ] ); |
|
76 | + $response = wp_remote_post( trailingslashit( static::API_URL ).$endpoint, $args ); |
|
77 | + if( is_wp_error( $response ) ) { |
|
78 | + glsr_log()->error( 'REBUSIFY: '.$response->get_error_message() ); |
|
79 | 79 | return; |
80 | 80 | } |
81 | - if (200 === wp_remote_retrieve_response_code($response)) { |
|
82 | - $responsedata = wp_remote_retrieve_body($response); |
|
83 | - return json_decode($responsedata, true); |
|
81 | + if( 200 === wp_remote_retrieve_response_code( $response ) ) { |
|
82 | + $responsedata = wp_remote_retrieve_body( $response ); |
|
83 | + return json_decode( $responsedata, true ); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | } |
@@ -8,12 +8,12 @@ |
||
8 | 8 | * @param int|string $postId |
9 | 9 | * @return \WP_Post|void|null |
10 | 10 | */ |
11 | - public function getPost($postId); |
|
11 | + public function getPost( $postId ); |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @return array |
15 | 15 | */ |
16 | - public function getPostIds(array $postIds); |
|
16 | + public function getPostIds( array $postIds ); |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @return bool |
@@ -25,17 +25,17 @@ discard block |
||
25 | 25 | * @param string $type |
26 | 26 | * @return string |
27 | 27 | */ |
28 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
28 | + public function build( $atts, array $args = [], $type = 'shortcode' ) |
|
29 | 29 | { |
30 | 30 | $this->partialName = $this->getShortcodePartialName(); |
31 | 31 | $this->shortcodeName = $this->getShortcodeName(); |
32 | - $args = $this->normalizeArgs($args, $type); |
|
33 | - $atts = $this->normalizeAtts($atts, $type); |
|
34 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
32 | + $args = $this->normalizeArgs( $args, $type ); |
|
33 | + $atts = $this->normalizeAtts( $atts, $type ); |
|
34 | + $partial = glsr( Partial::class )->build( $this->partialName, $atts ); |
|
35 | 35 | $title = !empty($atts['title']) |
36 | 36 | ? $args['before_title'].$atts['title'].$args['after_title'] |
37 | 37 | : ''; |
38 | - $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
38 | + $debug = sprintf( '<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json'] ); |
|
39 | 39 | return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
40 | 40 | } |
41 | 41 | |
@@ -43,17 +43,17 @@ discard block |
||
43 | 43 | * @param string|array $atts |
44 | 44 | * @return string |
45 | 45 | */ |
46 | - public function buildShortcode($atts = []) |
|
46 | + public function buildShortcode( $atts = [] ) |
|
47 | 47 | { |
48 | - return $this->build($atts); |
|
48 | + return $this->build( $atts ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public function getDefaults($atts) |
|
54 | + public function getDefaults( $atts ) |
|
55 | 55 | { |
56 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
56 | + return glsr( $this->getShortcodeDefaultsClassName() )->restrict( wp_parse_args( $atts ) ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,15 +62,15 @@ discard block |
||
62 | 62 | public function getHideOptions() |
63 | 63 | { |
64 | 64 | $options = $this->hideOptions(); |
65 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
65 | + return apply_filters( 'site-reviews/shortcode/hide-options', $options, $this->shortcodeName ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @return string |
70 | 70 | */ |
71 | - public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
71 | + public function getShortcodeClassName( $replace = '', $search = 'Shortcode' ) |
|
72 | 72 | { |
73 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
73 | + return str_replace( $search, $replace, (new ReflectionClass( $this ))->getShortName() ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function getShortcodeDefaultsClassName() |
80 | 80 | { |
81 | - return glsr(Helper::class)->buildClassName( |
|
82 | - $this->getShortcodeClassName('Defaults'), |
|
81 | + return glsr( Helper::class )->buildClassName( |
|
82 | + $this->getShortcodeClassName( 'Defaults' ), |
|
83 | 83 | 'Defaults' |
84 | 84 | ); |
85 | 85 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function getShortcodeName() |
91 | 91 | { |
92 | - return glsr(Helper::class)->snakeCase($this->getShortcodeClassName()); |
|
92 | + return glsr( Helper::class )->snakeCase( $this->getShortcodeClassName() ); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function getShortcodePartialName() |
99 | 99 | { |
100 | - return glsr(Helper::class)->dashCase($this->getShortcodeClassName()); |
|
100 | + return glsr( Helper::class )->dashCase( $this->getShortcodeClassName() ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,15 +105,15 @@ discard block |
||
105 | 105 | * @param string $type |
106 | 106 | * @return array |
107 | 107 | */ |
108 | - public function normalizeArgs($args, $type = 'shortcode') |
|
108 | + public function normalizeArgs( $args, $type = 'shortcode' ) |
|
109 | 109 | { |
110 | - $args = wp_parse_args($args, [ |
|
110 | + $args = wp_parse_args( $args, [ |
|
111 | 111 | 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
112 | 112 | 'after_widget' => '</div>', |
113 | 113 | 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
114 | 114 | 'after_title' => '</h3>', |
115 | - ]); |
|
116 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
115 | + ] ); |
|
116 | + return apply_filters( 'site-reviews/shortcode/args', $args, $type, $this->partialName ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
@@ -121,16 +121,16 @@ discard block |
||
121 | 121 | * @param string $type |
122 | 122 | * @return array |
123 | 123 | */ |
124 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
124 | + public function normalizeAtts( $atts, $type = 'shortcode' ) |
|
125 | 125 | { |
126 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
127 | - $atts = $this->getDefaults($atts); |
|
128 | - array_walk($atts, function (&$value, $key) { |
|
129 | - $methodName = glsr(Helper::class)->buildMethodName($key, 'normalize'); |
|
130 | - if (!method_exists($this, $methodName)) { |
|
126 | + $atts = apply_filters( 'site-reviews/shortcode/atts', $atts, $type, $this->partialName ); |
|
127 | + $atts = $this->getDefaults( $atts ); |
|
128 | + array_walk( $atts, function( &$value, $key ) { |
|
129 | + $methodName = glsr( Helper::class )->buildMethodName( $key, 'normalize' ); |
|
130 | + if( !method_exists( $this, $methodName ) ) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | - $value = $this->$methodName($value); |
|
133 | + $value = $this->$methodName( $value ); |
|
134 | 134 | }); |
135 | 135 | return $atts; |
136 | 136 | } |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | * @param string $postId |
145 | 145 | * @return int|string |
146 | 146 | */ |
147 | - protected function normalizeAssignedTo($postId) |
|
147 | + protected function normalizeAssignedTo( $postId ) |
|
148 | 148 | { |
149 | - if ('parent_id' == $postId) { |
|
150 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
151 | - } elseif ('post_id' == $postId) { |
|
152 | - $postId = intval(get_the_ID()); |
|
149 | + if( 'parent_id' == $postId ) { |
|
150 | + $postId = intval( wp_get_post_parent_id( intval( get_the_ID() ) ) ); |
|
151 | + } elseif( 'post_id' == $postId ) { |
|
152 | + $postId = intval( get_the_ID() ); |
|
153 | 153 | } |
154 | 154 | return $postId; |
155 | 155 | } |
@@ -158,23 +158,23 @@ discard block |
||
158 | 158 | * @param string $postId |
159 | 159 | * @return int|string |
160 | 160 | */ |
161 | - protected function normalizeAssignTo($postId) |
|
161 | + protected function normalizeAssignTo( $postId ) |
|
162 | 162 | { |
163 | - return $this->normalizeAssignedTo($postId); |
|
163 | + return $this->normalizeAssignedTo( $postId ); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | 167 | * @param string|array $hide |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - protected function normalizeHide($hide) |
|
170 | + protected function normalizeHide( $hide ) |
|
171 | 171 | { |
172 | - if (is_string($hide)) { |
|
173 | - $hide = explode(',', $hide); |
|
172 | + if( is_string( $hide ) ) { |
|
173 | + $hide = explode( ',', $hide ); |
|
174 | 174 | } |
175 | - $hideKeys = array_keys($this->getHideOptions()); |
|
176 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
177 | - return in_array($value, $hideKeys); |
|
175 | + $hideKeys = array_keys( $this->getHideOptions() ); |
|
176 | + return array_filter( array_map( 'trim', $hide ), function( $value ) use ($hideKeys) { |
|
177 | + return in_array( $value, $hideKeys ); |
|
178 | 178 | }); |
179 | 179 | } |
180 | 180 | |
@@ -182,51 +182,51 @@ discard block |
||
182 | 182 | * @param string $id |
183 | 183 | * @return string |
184 | 184 | */ |
185 | - protected function normalizeId($id) |
|
185 | + protected function normalizeId( $id ) |
|
186 | 186 | { |
187 | - return sanitize_title($id); |
|
187 | + return sanitize_title( $id ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * @param string $labels |
192 | 192 | * @return array |
193 | 193 | */ |
194 | - protected function normalizeLabels($labels) |
|
194 | + protected function normalizeLabels( $labels ) |
|
195 | 195 | { |
196 | 196 | $defaults = [ |
197 | - __('Excellent', 'site-reviews'), |
|
198 | - __('Very good', 'site-reviews'), |
|
199 | - __('Average', 'site-reviews'), |
|
200 | - __('Poor', 'site-reviews'), |
|
201 | - __('Terrible', 'site-reviews'), |
|
197 | + __( 'Excellent', 'site-reviews' ), |
|
198 | + __( 'Very good', 'site-reviews' ), |
|
199 | + __( 'Average', 'site-reviews' ), |
|
200 | + __( 'Poor', 'site-reviews' ), |
|
201 | + __( 'Terrible', 'site-reviews' ), |
|
202 | 202 | ]; |
203 | - $maxRating = glsr()->constant('MAX_RATING', Rating::class); |
|
204 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
205 | - $labels = array_map('trim', explode(',', $labels)); |
|
206 | - foreach ($defaults as $i => $label) { |
|
207 | - if (empty($labels[$i])) { |
|
203 | + $maxRating = glsr()->constant( 'MAX_RATING', Rating::class ); |
|
204 | + $defaults = array_pad( array_slice( $defaults, 0, $maxRating ), $maxRating, '' ); |
|
205 | + $labels = array_map( 'trim', explode( ',', $labels ) ); |
|
206 | + foreach( $defaults as $i => $label ) { |
|
207 | + if( empty($labels[$i]) ) { |
|
208 | 208 | continue; |
209 | 209 | } |
210 | 210 | $defaults[$i] = $labels[$i]; |
211 | 211 | } |
212 | - return array_combine(range($maxRating, 1), $defaults); |
|
212 | + return array_combine( range( $maxRating, 1 ), $defaults ); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
216 | 216 | * @param string $schema |
217 | 217 | * @return bool |
218 | 218 | */ |
219 | - protected function normalizeSchema($schema) |
|
219 | + protected function normalizeSchema( $schema ) |
|
220 | 220 | { |
221 | - return wp_validate_boolean($schema); |
|
221 | + return wp_validate_boolean( $schema ); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
225 | 225 | * @param string $text |
226 | 226 | * @return string |
227 | 227 | */ |
228 | - protected function normalizeText($text) |
|
228 | + protected function normalizeText( $text ) |
|
229 | 229 | { |
230 | - return trim($text); |
|
230 | + return trim( $text ); |
|
231 | 231 | } |
232 | 232 | } |
@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | * @param Reviews|null $reviews |
44 | 44 | * @return ReviewsHtml |
45 | 45 | */ |
46 | - public function build(array $args = [], $reviews = null) |
|
46 | + public function build( array $args = [], $reviews = null ) |
|
47 | 47 | { |
48 | - $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
49 | - $this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()); |
|
48 | + $this->args = glsr( SiteReviewsDefaults::class )->merge( $args ); |
|
49 | + $this->options = glsr( Helper::class )->flattenArray( glsr( OptionManager::class )->all() ); |
|
50 | 50 | $this->reviews = $reviews instanceof Reviews |
51 | 51 | ? $reviews |
52 | - : glsr(ReviewManager::class)->get($args); |
|
52 | + : glsr( ReviewManager::class )->get( $args ); |
|
53 | 53 | $this->generateSchema(); |
54 | 54 | return $this->buildReviews(); |
55 | 55 | } |
@@ -57,26 +57,26 @@ discard block |
||
57 | 57 | /** |
58 | 58 | * @return ReviewHtml |
59 | 59 | */ |
60 | - public function buildReview(Review $review) |
|
60 | + public function buildReview( Review $review ) |
|
61 | 61 | { |
62 | - $review = apply_filters('site-reviews/review/build/before', $review); |
|
62 | + $review = apply_filters( 'site-reviews/review/build/before', $review ); |
|
63 | 63 | $this->current = $review; |
64 | 64 | $renderedFields = []; |
65 | - foreach ($review as $key => $value) { |
|
66 | - $method = glsr(Helper::class)->buildMethodName($key, 'buildOption'); |
|
67 | - $field = method_exists($this, $method) |
|
68 | - ? $this->$method($key, $value) |
|
65 | + foreach( $review as $key => $value ) { |
|
66 | + $method = glsr( Helper::class )->buildMethodName( $key, 'buildOption' ); |
|
67 | + $field = method_exists( $this, $method ) |
|
68 | + ? $this->$method( $key, $value ) |
|
69 | 69 | : false; |
70 | - $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $this, $review); |
|
71 | - if (false === $field) { |
|
70 | + $field = apply_filters( 'site-reviews/review/build/'.$key, $field, $value, $this, $review ); |
|
71 | + if( false === $field ) { |
|
72 | 72 | continue; |
73 | 73 | } |
74 | 74 | $renderedFields[$key] = $field; |
75 | 75 | } |
76 | - $this->wrap($renderedFields, $review); |
|
77 | - $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this); |
|
76 | + $this->wrap( $renderedFields, $review ); |
|
77 | + $renderedFields = apply_filters( 'site-reviews/review/build/after', $renderedFields, $review, $this ); |
|
78 | 78 | $this->current = null; |
79 | - return new ReviewHtml($review, (array) $renderedFields); |
|
79 | + return new ReviewHtml( $review, (array)$renderedFields ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -85,10 +85,10 @@ discard block |
||
85 | 85 | public function buildReviews() |
86 | 86 | { |
87 | 87 | $renderedReviews = []; |
88 | - foreach ($this->reviews as $index => $review) { |
|
89 | - $renderedReviews[] = $this->buildReview($review); |
|
88 | + foreach( $this->reviews as $index => $review ) { |
|
89 | + $renderedReviews[] = $this->buildReview( $review ); |
|
90 | 90 | } |
91 | - return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
91 | + return new ReviewsHtml( $renderedReviews, $this->reviews->max_num_pages, $this->args ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | */ |
97 | 97 | public function generateSchema() |
98 | 98 | { |
99 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
99 | + if( !wp_validate_boolean( $this->args['schema'] ) ) { |
|
100 | 100 | return; |
101 | 101 | } |
102 | - glsr(Schema::class)->store( |
|
103 | - glsr(Schema::class)->build($this->args) |
|
102 | + glsr( Schema::class )->store( |
|
103 | + glsr( Schema::class )->build( $this->args ) |
|
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | * @param string $path |
110 | 110 | * @return bool |
111 | 111 | */ |
112 | - public function isHidden($key, $path = '') |
|
112 | + public function isHidden( $key, $path = '' ) |
|
113 | 113 | { |
114 | 114 | $isOptionEnabled = !empty($path) |
115 | - ? $this->isOptionEnabled($path) |
|
115 | + ? $this->isOptionEnabled( $path ) |
|
116 | 116 | : true; |
117 | - return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
117 | + return in_array( $key, $this->args['hide'] ) || !$isOptionEnabled; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -122,19 +122,19 @@ discard block |
||
122 | 122 | * @param string $value |
123 | 123 | * @return void|string |
124 | 124 | */ |
125 | - protected function buildOptionAssignedTo($key, $value) |
|
125 | + protected function buildOptionAssignedTo( $key, $value ) |
|
126 | 126 | { |
127 | - if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
127 | + if( $this->isHidden( $key, 'settings.reviews.assigned_links' ) ) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | - $post = glsr(Polylang::class)->getPost($value); |
|
131 | - if (!($post instanceof WP_Post)) { |
|
130 | + $post = glsr( Polylang::class )->getPost( $value ); |
|
131 | + if( !($post instanceof WP_Post) ) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | - $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
135 | - 'href' => get_the_permalink($post->ID), |
|
136 | - ]); |
|
137 | - $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
134 | + $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [ |
|
135 | + 'href' => get_the_permalink( $post->ID ), |
|
136 | + ] ); |
|
137 | + $assignedTo = sprintf( __( 'Review of %s', 'site-reviews' ), $permalink ); |
|
138 | 138 | return '<span>'.$assignedTo.'</span>'; |
139 | 139 | } |
140 | 140 | |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | * @param string $value |
144 | 144 | * @return void|string |
145 | 145 | */ |
146 | - protected function buildOptionAuthor($key, $value) |
|
146 | + protected function buildOptionAuthor( $key, $value ) |
|
147 | 147 | { |
148 | - if (!$this->isHidden($key)) { |
|
148 | + if( !$this->isHidden( $key ) ) { |
|
149 | 149 | return '<span>'.$value.'</span>'; |
150 | 150 | } |
151 | 151 | } |
@@ -155,18 +155,18 @@ discard block |
||
155 | 155 | * @param string $value |
156 | 156 | * @return void|string |
157 | 157 | */ |
158 | - protected function buildOptionAvatar($key, $value) |
|
158 | + protected function buildOptionAvatar( $key, $value ) |
|
159 | 159 | { |
160 | - if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
160 | + if( $this->isHidden( $key, 'settings.reviews.avatars' ) ) { |
|
161 | 161 | return; |
162 | 162 | } |
163 | - $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
164 | - return glsr(Builder::class)->img([ |
|
163 | + $size = $this->getOption( 'settings.reviews.avatars_size', 40 ); |
|
164 | + return glsr( Builder::class )->img( [ |
|
165 | 165 | 'height' => $size, |
166 | - 'src' => $this->generateAvatar($value), |
|
167 | - 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
166 | + 'src' => $this->generateAvatar( $value ), |
|
167 | + 'style' => sprintf( 'width:%1$spx; height:%1$spx;', $size ), |
|
168 | 168 | 'width' => $size, |
169 | - ]); |
|
169 | + ] ); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | * @param string $value |
175 | 175 | * @return void|string |
176 | 176 | */ |
177 | - protected function buildOptionContent($key, $value) |
|
177 | + protected function buildOptionContent( $key, $value ) |
|
178 | 178 | { |
179 | - $text = $this->normalizeText($value); |
|
180 | - if (!$this->isHiddenOrEmpty($key, $text)) { |
|
179 | + $text = $this->normalizeText( $value ); |
|
180 | + if( !$this->isHiddenOrEmpty( $key, $text ) ) { |
|
181 | 181 | return '<p>'.$text.'</p>'; |
182 | 182 | } |
183 | 183 | } |
@@ -187,19 +187,19 @@ discard block |
||
187 | 187 | * @param string $value |
188 | 188 | * @return void|string |
189 | 189 | */ |
190 | - protected function buildOptionDate($key, $value) |
|
190 | + protected function buildOptionDate( $key, $value ) |
|
191 | 191 | { |
192 | - if ($this->isHidden($key)) { |
|
192 | + if( $this->isHidden( $key ) ) { |
|
193 | 193 | return; |
194 | 194 | } |
195 | - $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
196 | - if ('relative' == $dateFormat) { |
|
197 | - $date = glsr(Date::class)->relative($value); |
|
195 | + $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' ); |
|
196 | + if( 'relative' == $dateFormat ) { |
|
197 | + $date = glsr( Date::class )->relative( $value ); |
|
198 | 198 | } else { |
199 | 199 | $format = 'custom' == $dateFormat |
200 | - ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
201 | - : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
202 | - $date = date_i18n($format, strtotime($value)); |
|
200 | + ? $this->getOption( 'settings.reviews.date.custom', 'M j, Y' ) |
|
201 | + : glsr( OptionManager::class )->getWP( 'date_format', 'F j, Y' ); |
|
202 | + $date = date_i18n( $format, strtotime( $value ) ); |
|
203 | 203 | } |
204 | 204 | return '<span>'.$date.'</span>'; |
205 | 205 | } |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | * @param string $value |
210 | 210 | * @return void|string |
211 | 211 | */ |
212 | - protected function buildOptionRating($key, $value) |
|
212 | + protected function buildOptionRating( $key, $value ) |
|
213 | 213 | { |
214 | - if (!$this->isHiddenOrEmpty($key, $value)) { |
|
215 | - return glsr_star_rating($value); |
|
214 | + if( !$this->isHiddenOrEmpty( $key, $value ) ) { |
|
215 | + return glsr_star_rating( $value ); |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
@@ -221,16 +221,16 @@ discard block |
||
221 | 221 | * @param string $value |
222 | 222 | * @return void|string |
223 | 223 | */ |
224 | - protected function buildOptionResponse($key, $value) |
|
224 | + protected function buildOptionResponse( $key, $value ) |
|
225 | 225 | { |
226 | - if ($this->isHiddenOrEmpty($key, $value)) { |
|
226 | + if( $this->isHiddenOrEmpty( $key, $value ) ) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | - $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
230 | - $text = $this->normalizeText($value); |
|
229 | + $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' ) ); |
|
230 | + $text = $this->normalizeText( $value ); |
|
231 | 231 | $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
232 | - $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
233 | - $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
232 | + $response = glsr( Builder::class )->div( $text, ['class' => 'glsr-review-response-inner'] ); |
|
233 | + $background = glsr( Builder::class )->div( ['class' => 'glsr-review-response-background'] ); |
|
234 | 234 | return $response.$background; |
235 | 235 | } |
236 | 236 | |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | * @param string $value |
240 | 240 | * @return void|string |
241 | 241 | */ |
242 | - protected function buildOptionTitle($key, $value) |
|
242 | + protected function buildOptionTitle( $key, $value ) |
|
243 | 243 | { |
244 | - if ($this->isHidden($key)) { |
|
244 | + if( $this->isHidden( $key ) ) { |
|
245 | 245 | return; |
246 | 246 | } |
247 | - if (empty($value)) { |
|
248 | - $value = __('No Title', 'site-reviews'); |
|
247 | + if( empty($value) ) { |
|
248 | + $value = __( 'No Title', 'site-reviews' ); |
|
249 | 249 | } |
250 | 250 | return '<h3>'.$value.'</h3>'; |
251 | 251 | } |
@@ -254,16 +254,16 @@ discard block |
||
254 | 254 | * @param string $avatarUrl |
255 | 255 | * @return string |
256 | 256 | */ |
257 | - protected function generateAvatar($avatarUrl) |
|
257 | + protected function generateAvatar( $avatarUrl ) |
|
258 | 258 | { |
259 | - if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
259 | + if( !$this->isOptionEnabled( 'settings.reviews.avatars_regenerate' ) || 'local' != $this->current->review_type ) { |
|
260 | 260 | return $avatarUrl; |
261 | 261 | } |
262 | - $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
263 | - if (empty($authorIdOrEmail)) { |
|
262 | + $authorIdOrEmail = get_the_author_meta( 'ID', $this->current->user_id ); |
|
263 | + if( empty($authorIdOrEmail) ) { |
|
264 | 264 | $authorIdOrEmail = $this->current->email; |
265 | 265 | } |
266 | - if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
266 | + if( $newAvatar = get_avatar_url( $authorIdOrEmail ) ) { |
|
267 | 267 | return $newAvatar; |
268 | 268 | } |
269 | 269 | return $avatarUrl; |
@@ -273,20 +273,20 @@ discard block |
||
273 | 273 | * @param string $text |
274 | 274 | * @return string |
275 | 275 | */ |
276 | - protected function getExcerpt($text) |
|
276 | + protected function getExcerpt( $text ) |
|
277 | 277 | { |
278 | - $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
279 | - $split = extension_loaded('intl') |
|
280 | - ? $this->getExcerptIntlSplit($text, $limit) |
|
281 | - : $this->getExcerptSplit($text, $limit); |
|
282 | - $hiddenText = substr($text, $split); |
|
283 | - if (!empty($hiddenText)) { |
|
284 | - $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
278 | + $limit = intval( $this->getOption( 'settings.reviews.excerpts_length', 55 ) ); |
|
279 | + $split = extension_loaded( 'intl' ) |
|
280 | + ? $this->getExcerptIntlSplit( $text, $limit ) |
|
281 | + : $this->getExcerptSplit( $text, $limit ); |
|
282 | + $hiddenText = substr( $text, $split ); |
|
283 | + if( !empty($hiddenText) ) { |
|
284 | + $showMore = glsr( Builder::class )->span( $hiddenText, [ |
|
285 | 285 | 'class' => 'glsr-hidden glsr-hidden-text', |
286 | - 'data-show-less' => __('Show less', 'site-reviews'), |
|
287 | - 'data-show-more' => __('Show more', 'site-reviews'), |
|
288 | - ]); |
|
289 | - $text = ltrim(substr($text, 0, $split)).$showMore; |
|
286 | + 'data-show-less' => __( 'Show less', 'site-reviews' ), |
|
287 | + 'data-show-more' => __( 'Show more', 'site-reviews' ), |
|
288 | + ] ); |
|
289 | + $text = ltrim( substr( $text, 0, $split ) ).$showMore; |
|
290 | 290 | } |
291 | 291 | return $text; |
292 | 292 | } |
@@ -296,22 +296,22 @@ discard block |
||
296 | 296 | * @param int $limit |
297 | 297 | * @return int |
298 | 298 | */ |
299 | - protected function getExcerptIntlSplit($text, $limit) |
|
299 | + protected function getExcerptIntlSplit( $text, $limit ) |
|
300 | 300 | { |
301 | - $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
302 | - $words->setText($text); |
|
301 | + $words = IntlRuleBasedBreakIterator::createWordInstance( '' ); |
|
302 | + $words->setText( $text ); |
|
303 | 303 | $count = 0; |
304 | - foreach ($words as $offset) { |
|
305 | - if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
304 | + foreach( $words as $offset ) { |
|
305 | + if( IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus() ) { |
|
306 | 306 | continue; |
307 | 307 | } |
308 | 308 | ++$count; |
309 | - if ($count != $limit) { |
|
309 | + if( $count != $limit ) { |
|
310 | 310 | continue; |
311 | 311 | } |
312 | 312 | return $offset; |
313 | 313 | } |
314 | - return strlen($text); |
|
314 | + return strlen( $text ); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -319,13 +319,13 @@ discard block |
||
319 | 319 | * @param int $limit |
320 | 320 | * @return int |
321 | 321 | */ |
322 | - protected function getExcerptSplit($text, $limit) |
|
322 | + protected function getExcerptSplit( $text, $limit ) |
|
323 | 323 | { |
324 | - if (str_word_count($text, 0) > $limit) { |
|
325 | - $words = array_keys(str_word_count($text, 2)); |
|
324 | + if( str_word_count( $text, 0 ) > $limit ) { |
|
325 | + $words = array_keys( str_word_count( $text, 2 ) ); |
|
326 | 326 | return $words[$limit]; |
327 | 327 | } |
328 | - return strlen($text); |
|
328 | + return strlen( $text ); |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -333,9 +333,9 @@ discard block |
||
333 | 333 | * @param mixed $fallback |
334 | 334 | * @return mixed |
335 | 335 | */ |
336 | - protected function getOption($path, $fallback = '') |
|
336 | + protected function getOption( $path, $fallback = '' ) |
|
337 | 337 | { |
338 | - if (array_key_exists($path, $this->options)) { |
|
338 | + if( array_key_exists( $path, $this->options ) ) { |
|
339 | 339 | return $this->options[$path]; |
340 | 340 | } |
341 | 341 | return $fallback; |
@@ -346,50 +346,50 @@ discard block |
||
346 | 346 | * @param string $value |
347 | 347 | * @return bool |
348 | 348 | */ |
349 | - protected function isHiddenOrEmpty($key, $value) |
|
349 | + protected function isHiddenOrEmpty( $key, $value ) |
|
350 | 350 | { |
351 | - return $this->isHidden($key) || empty($value); |
|
351 | + return $this->isHidden( $key ) || empty($value); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | 355 | * @param string $path |
356 | 356 | * @return bool |
357 | 357 | */ |
358 | - protected function isOptionEnabled($path) |
|
358 | + protected function isOptionEnabled( $path ) |
|
359 | 359 | { |
360 | - return 'yes' == $this->getOption($path); |
|
360 | + return 'yes' == $this->getOption( $path ); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
364 | 364 | * @param string $text |
365 | 365 | * @return string |
366 | 366 | */ |
367 | - protected function normalizeText($text) |
|
367 | + protected function normalizeText( $text ) |
|
368 | 368 | { |
369 | - $text = wp_kses($text, wp_kses_allowed_html()); |
|
370 | - $text = convert_smilies(strip_shortcodes($text)); |
|
371 | - $text = str_replace(']]>', ']]>', $text); |
|
372 | - $text = preg_replace('/(\R){2,}/', '$1', $text); |
|
373 | - if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
374 | - $text = $this->getExcerpt($text); |
|
369 | + $text = wp_kses( $text, wp_kses_allowed_html() ); |
|
370 | + $text = convert_smilies( strip_shortcodes( $text ) ); |
|
371 | + $text = str_replace( ']]>', ']]>', $text ); |
|
372 | + $text = preg_replace( '/(\R){2,}/', '$1', $text ); |
|
373 | + if( $this->isOptionEnabled( 'settings.reviews.excerpts' ) ) { |
|
374 | + $text = $this->getExcerpt( $text ); |
|
375 | 375 | } |
376 | - return wptexturize(nl2br($text)); |
|
376 | + return wptexturize( nl2br( $text ) ); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | /** |
380 | 380 | * @return void |
381 | 381 | */ |
382 | - protected function wrap(array &$renderedFields, Review $review) |
|
382 | + protected function wrap( array &$renderedFields, Review $review ) |
|
383 | 383 | { |
384 | - $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this); |
|
385 | - array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
386 | - $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
387 | - if (empty($value)) { |
|
384 | + $renderedFields = apply_filters( 'site-reviews/review/wrap', $renderedFields, $review, $this ); |
|
385 | + array_walk( $renderedFields, function( &$value, $key ) use ($review) { |
|
386 | + $value = apply_filters( 'site-reviews/review/wrap/'.$key, $value, $review ); |
|
387 | + if( empty($value) ) { |
|
388 | 388 | return; |
389 | 389 | } |
390 | - $value = glsr(Builder::class)->div($value, [ |
|
390 | + $value = glsr( Builder::class )->div( $value, [ |
|
391 | 391 | 'class' => 'glsr-review-'.$key, |
392 | - ]); |
|
392 | + ] ); |
|
393 | 393 | }); |
394 | 394 | } |
395 | 395 | } |
@@ -39,17 +39,17 @@ discard block |
||
39 | 39 | 'setting' => 'Plugin Settings', |
40 | 40 | 'reviews' => 'Review Counts', |
41 | 41 | ]; |
42 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
43 | - $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details'); |
|
44 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
42 | + $systemInfo = array_reduce( array_keys( $details ), function( $carry, $key ) use ($details) { |
|
43 | + $methodName = glsr( Helper::class )->buildMethodName( 'get-'.$key.'-details' ); |
|
44 | + if( method_exists( $this, $methodName ) && $systemDetails = $this->$methodName() ) { |
|
45 | 45 | return $carry.$this->implode( |
46 | - strtoupper($details[$key]), |
|
47 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
46 | + strtoupper( $details[$key] ), |
|
47 | + apply_filters( 'site-reviews/system/'.$key, $systemDetails ) |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | return $carry; |
51 | 51 | }); |
52 | - return trim($systemInfo); |
|
52 | + return trim( $systemInfo ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | public function getActivePluginDetails() |
59 | 59 | { |
60 | 60 | $plugins = get_plugins(); |
61 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
62 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
63 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
61 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
62 | + $inactive = array_diff_key( $plugins, array_flip( $activePlugins ) ); |
|
63 | + return $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function getAddonDetails() |
70 | 70 | { |
71 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
72 | - ksort($details); |
|
71 | + $details = apply_filters( 'site-reviews/addon/system-info', [] ); |
|
72 | + ksort( $details ); |
|
73 | 73 | return $details; |
74 | 74 | } |
75 | 75 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | public function getBrowserDetails() |
80 | 80 | { |
81 | 81 | $browser = new Browser(); |
82 | - $name = esc_attr($browser->getName()); |
|
83 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
84 | - $version = esc_attr($browser->getVersion()); |
|
82 | + $name = esc_attr( $browser->getName() ); |
|
83 | + $userAgent = esc_attr( $browser->getUserAgent()->getUserAgentString() ); |
|
84 | + $version = esc_attr( $browser->getVersion() ); |
|
85 | 85 | return [ |
86 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
86 | + 'Browser Name' => sprintf( '%s %s', $name, $version ), |
|
87 | 87 | 'Browser UA' => $userAgent, |
88 | 88 | ]; |
89 | 89 | } |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getInactivePluginDetails() |
95 | 95 | { |
96 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
97 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
96 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
97 | + $inactivePlugins = $this->normalizePluginList( array_diff_key( get_plugins(), array_flip( $activePlugins ) ) ); |
|
98 | 98 | $multisitePlugins = $this->getMultisitePluginDetails(); |
99 | 99 | return empty($multisitePlugins) |
100 | 100 | ? $inactivePlugins |
101 | - : array_diff($inactivePlugins, $multisitePlugins); |
|
101 | + : array_diff( $inactivePlugins, $multisitePlugins ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,10 +106,10 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function getMuPluginDetails() |
108 | 108 | { |
109 | - if (empty($plugins = get_mu_plugins())) { |
|
109 | + if( empty($plugins = get_mu_plugins()) ) { |
|
110 | 110 | return []; |
111 | 111 | } |
112 | - return $this->normalizePluginList($plugins); |
|
112 | + return $this->normalizePluginList( $plugins ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function getMultisitePluginDetails() |
119 | 119 | { |
120 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
121 | - if (!is_multisite() || empty($activePlugins)) { |
|
120 | + $activePlugins = (array)get_site_option( 'active_sitewide_plugins', [] ); |
|
121 | + if( !is_multisite() || empty($activePlugins) ) { |
|
122 | 122 | return []; |
123 | 123 | } |
124 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
124 | + return $this->normalizePluginList( array_intersect_key( get_plugins(), $activePlugins ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -129,31 +129,31 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function getPhpDetails() |
131 | 131 | { |
132 | - $displayErrors = ini_get('display_errors') |
|
133 | - ? 'On ('.ini_get('display_errors').')' |
|
132 | + $displayErrors = ini_get( 'display_errors' ) |
|
133 | + ? 'On ('.ini_get( 'display_errors' ).')' |
|
134 | 134 | : 'N/A'; |
135 | - $intlSupport = extension_loaded('intl') |
|
136 | - ? phpversion('intl') |
|
135 | + $intlSupport = extension_loaded( 'intl' ) |
|
136 | + ? phpversion( 'intl' ) |
|
137 | 137 | : 'false'; |
138 | 138 | return [ |
139 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
140 | - 'Default Charset' => ini_get('default_charset'), |
|
139 | + 'cURL' => var_export( function_exists( 'curl_init' ), true ), |
|
140 | + 'Default Charset' => ini_get( 'default_charset' ), |
|
141 | 141 | 'Display Errors' => $displayErrors, |
142 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
142 | + 'fsockopen' => var_export( function_exists( 'fsockopen' ), true ), |
|
143 | 143 | 'Intl' => $intlSupport, |
144 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
145 | - 'Max Execution Time' => ini_get('max_execution_time'), |
|
146 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
147 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
148 | - 'Memory Limit' => ini_get('memory_limit'), |
|
149 | - 'Post Max Size' => ini_get('post_max_size'), |
|
150 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
151 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
152 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
153 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
154 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
155 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
156 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
144 | + 'IPv6' => var_export( defined( 'AF_INET6' ), true ), |
|
145 | + 'Max Execution Time' => ini_get( 'max_execution_time' ), |
|
146 | + 'Max Input Nesting Level' => ini_get( 'max_input_nesting_level' ), |
|
147 | + 'Max Input Vars' => ini_get( 'max_input_vars' ), |
|
148 | + 'Memory Limit' => ini_get( 'memory_limit' ), |
|
149 | + 'Post Max Size' => ini_get( 'post_max_size' ), |
|
150 | + 'Sendmail Path' => ini_get( 'sendmail_path' ), |
|
151 | + 'Session Cookie Path' => esc_html( ini_get( 'session.cookie_path' ) ), |
|
152 | + 'Session Name' => esc_html( ini_get( 'session.name' ) ), |
|
153 | + 'Session Save Path' => esc_html( ini_get( 'session.save_path' ) ), |
|
154 | + 'Session Use Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_cookies' ) ), true ), |
|
155 | + 'Session Use Only Cookies' => var_export( wp_validate_boolean( ini_get( 'session.use_only_cookies' ) ), true ), |
|
156 | + 'Upload Max Filesize' => ini_get( 'upload_max_filesize' ), |
|
157 | 157 | ]; |
158 | 158 | } |
159 | 159 | |
@@ -162,19 +162,19 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function getReviewsDetails() |
164 | 164 | { |
165 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
166 | - $counts = glsr(Helper::class)->flattenArray($counts); |
|
167 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
168 | - if (!is_array($ratings)) { |
|
165 | + $counts = glsr( CountsManager::class )->getCounts(); |
|
166 | + $counts = glsr( Helper::class )->flattenArray( $counts ); |
|
167 | + array_walk( $counts, function( &$ratings ) use ($counts) { |
|
168 | + if( !is_array( $ratings ) ) { |
|
169 | 169 | glsr_log() |
170 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
171 | - ->debug($ratings) |
|
172 | - ->debug($counts); |
|
170 | + ->error( '$ratings is not an array, possibly due to incorrectly imported reviews.' ) |
|
171 | + ->debug( $ratings ) |
|
172 | + ->debug( $counts ); |
|
173 | 173 | return; |
174 | 174 | } |
175 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
175 | + $ratings = array_sum( $ratings ).' ('.implode( ', ', $ratings ).')'; |
|
176 | 176 | }); |
177 | - ksort($counts); |
|
177 | + ksort( $counts ); |
|
178 | 178 | return $counts; |
179 | 179 | } |
180 | 180 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | 'Host Name' => $this->getHostName(), |
189 | 189 | 'MySQL Version' => $wpdb->db_version(), |
190 | 190 | 'PHP Version' => PHP_VERSION, |
191 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
191 | + 'Server Software' => filter_input( INPUT_SERVER, 'SERVER_SOFTWARE' ), |
|
192 | 192 | ]; |
193 | 193 | } |
194 | 194 | |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function getSettingDetails() |
199 | 199 | { |
200 | - $helper = glsr(Helper::class); |
|
201 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
202 | - $settings = $helper->flattenArray($settings, true); |
|
203 | - $settings = $this->purgeSensitiveData($settings); |
|
204 | - ksort($settings); |
|
200 | + $helper = glsr( Helper::class ); |
|
201 | + $settings = glsr( OptionManager::class )->get( 'settings', [] ); |
|
202 | + $settings = $helper->flattenArray( $settings, true ); |
|
203 | + $settings = $this->purgeSensitiveData( $settings ); |
|
204 | + ksort( $settings ); |
|
205 | 205 | $details = []; |
206 | - foreach ($settings as $key => $value) { |
|
207 | - if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) { |
|
206 | + foreach( $settings as $key => $value ) { |
|
207 | + if( $helper->startsWith( 'strings', $key ) && $helper->endsWith( 'id', $key ) ) { |
|
208 | 208 | continue; |
209 | 209 | } |
210 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
210 | + $value = htmlspecialchars( trim( preg_replace( '/\s\s+/', '\\n', $value ) ), ENT_QUOTES, 'UTF-8' ); |
|
211 | 211 | $details[$key] = $value; |
212 | 212 | } |
213 | 213 | return $details; |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | public function getPluginDetails() |
220 | 220 | { |
221 | 221 | return [ |
222 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
223 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
224 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
222 | + 'Console level' => glsr( Console::class )->humanLevel(), |
|
223 | + 'Console size' => glsr( Console::class )->humanSize( '0' ), |
|
224 | + 'Last Rating Count' => date_i18n( 'Y-m-d H:i', glsr( OptionManager::class )->get( 'last_review_count' ) ), |
|
225 | 225 | 'Version (current)' => glsr()->version, |
226 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
226 | + 'Version (previous)' => glsr( OptionManager::class )->get( 'version_upgraded_from' ), |
|
227 | 227 | ]; |
228 | 228 | } |
229 | 229 | |
@@ -235,23 +235,23 @@ discard block |
||
235 | 235 | global $wpdb; |
236 | 236 | $theme = wp_get_theme(); |
237 | 237 | return [ |
238 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
239 | - 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
238 | + 'Active Theme' => sprintf( '%s v%s', (string)$theme->Name, (string)$theme->Version ), |
|
239 | + 'Email Domain' => substr( strrchr( glsr( OptionManager::class )->getWP( 'admin_email' ), '@' ), 1 ), |
|
240 | 240 | 'Home URL' => home_url(), |
241 | 241 | 'Language' => get_locale(), |
242 | 242 | 'Memory Limit' => WP_MEMORY_LIMIT, |
243 | - 'Multisite' => var_export(is_multisite(), true), |
|
244 | - 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
245 | - 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
246 | - 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
247 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
248 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
249 | - 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
243 | + 'Multisite' => var_export( is_multisite(), true ), |
|
244 | + 'Page For Posts ID' => glsr( OptionManager::class )->getWP( 'page_for_posts' ), |
|
245 | + 'Page On Front ID' => glsr( OptionManager::class )->getWP( 'page_on_front' ), |
|
246 | + 'Permalink Structure' => glsr( OptionManager::class )->getWP( 'permalink_structure', 'default' ), |
|
247 | + 'Post Stati' => implode( ', ', get_post_stati() ), |
|
248 | + 'Remote Post' => glsr( Cache::class )->getRemotePostTest(), |
|
249 | + 'Show On Front' => glsr( OptionManager::class )->getWP( 'show_on_front' ), |
|
250 | 250 | 'Site URL' => site_url(), |
251 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
252 | - 'Version' => get_bloginfo('version'), |
|
253 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
254 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
251 | + 'Timezone' => glsr( OptionManager::class )->getWP( 'timezone_string', ini_get( 'date.timezone' ).' (PHP)' ), |
|
252 | + 'Version' => get_bloginfo( 'version' ), |
|
253 | + 'WP Debug' => var_export( defined( 'WP_DEBUG' ), true ), |
|
254 | + 'WP Max Upload Size' => size_format( wp_max_upload_size() ), |
|
255 | 255 | 'WP Memory Limit' => WP_MEMORY_LIMIT, |
256 | 256 | ]; |
257 | 257 | } |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | 'secureserver.net' => 'GoDaddy', |
282 | 282 | 'WPE_APIKEY' => 'WP Engine', |
283 | 283 | ]; |
284 | - foreach ($checks as $key => $value) { |
|
285 | - if (!$this->isWebhostCheckValid($key)) { |
|
284 | + foreach( $checks as $key => $value ) { |
|
285 | + if( !$this->isWebhostCheckValid( $key ) ) { |
|
286 | 286 | continue; |
287 | 287 | } |
288 | 288 | return $value; |
289 | 289 | } |
290 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
290 | + return implode( ',', array_filter( [DB_HOST, filter_input( INPUT_SERVER, 'SERVER_NAME' )] ) ); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | */ |
296 | 296 | protected function getHostName() |
297 | 297 | { |
298 | - return sprintf('%s (%s)', |
|
298 | + return sprintf( '%s (%s)', |
|
299 | 299 | $this->detectWebhostProvider(), |
300 | - glsr(Helper::class)->getIpAddress() |
|
300 | + glsr( Helper::class )->getIpAddress() |
|
301 | 301 | ); |
302 | 302 | } |
303 | 303 | |
@@ -307,9 +307,9 @@ discard block |
||
307 | 307 | protected function getWordpressPlugins() |
308 | 308 | { |
309 | 309 | $plugins = get_plugins(); |
310 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
311 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
312 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
310 | + $activePlugins = glsr( OptionManager::class )->getWP( 'active_plugins', [], 'array' ); |
|
311 | + $inactive = $this->normalizePluginList( array_diff_key( $plugins, array_flip( $activePlugins ) ) ); |
|
312 | + $active = $this->normalizePluginList( array_diff_key( $plugins, $inactive ) ); |
|
313 | 313 | return $active + $inactive; |
314 | 314 | } |
315 | 315 | |
@@ -317,58 +317,58 @@ discard block |
||
317 | 317 | * @param string $title |
318 | 318 | * @return string |
319 | 319 | */ |
320 | - protected function implode($title, array $details) |
|
320 | + protected function implode( $title, array $details ) |
|
321 | 321 | { |
322 | 322 | $strings = ['['.$title.']']; |
323 | - $padding = max(array_map('strlen', array_keys($details))); |
|
324 | - $padding = max([$padding, static::PAD]); |
|
325 | - foreach ($details as $key => $value) { |
|
326 | - $strings[] = is_string($key) |
|
327 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
323 | + $padding = max( array_map( 'strlen', array_keys( $details ) ) ); |
|
324 | + $padding = max( [$padding, static::PAD] ); |
|
325 | + foreach( $details as $key => $value ) { |
|
326 | + $strings[] = is_string( $key ) |
|
327 | + ? sprintf( '%s : %s', str_pad( $key, $padding, '.' ), $value ) |
|
328 | 328 | : ' - '.$value; |
329 | 329 | } |
330 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
330 | + return implode( PHP_EOL, $strings ).PHP_EOL.PHP_EOL; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
334 | 334 | * @param string $key |
335 | 335 | * @return bool |
336 | 336 | */ |
337 | - protected function isWebhostCheckValid($key) |
|
337 | + protected function isWebhostCheckValid( $key ) |
|
338 | 338 | { |
339 | - return defined($key) |
|
340 | - || filter_input(INPUT_SERVER, $key) |
|
341 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
342 | - || false !== strpos(DB_HOST, $key) |
|
343 | - || false !== strpos(php_uname(), $key); |
|
339 | + return defined( $key ) |
|
340 | + || filter_input( INPUT_SERVER, $key ) |
|
341 | + || false !== strpos( filter_input( INPUT_SERVER, 'SERVER_NAME' ), $key ) |
|
342 | + || false !== strpos( DB_HOST, $key ) |
|
343 | + || false !== strpos( php_uname(), $key ); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
347 | 347 | * @return array |
348 | 348 | */ |
349 | - protected function normalizePluginList(array $plugins) |
|
349 | + protected function normalizePluginList( array $plugins ) |
|
350 | 350 | { |
351 | - $plugins = array_map(function ($plugin) { |
|
352 | - return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version')); |
|
353 | - }, $plugins); |
|
354 | - natcasesort($plugins); |
|
355 | - return array_flip($plugins); |
|
351 | + $plugins = array_map( function( $plugin ) { |
|
352 | + return sprintf( '%s v%s', glsr_get( $plugin, 'Name' ), glsr_get( $plugin, 'Version' ) ); |
|
353 | + }, $plugins ); |
|
354 | + natcasesort( $plugins ); |
|
355 | + return array_flip( $plugins ); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
359 | 359 | * @return array |
360 | 360 | */ |
361 | - protected function purgeSensitiveData(array $settings) |
|
361 | + protected function purgeSensitiveData( array $settings ) |
|
362 | 362 | { |
363 | 363 | $keys = [ |
364 | 364 | 'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret', |
365 | 365 | ]; |
366 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
367 | - foreach ($keys as $key) { |
|
368 | - if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) { |
|
366 | + array_walk( $settings, function( &$value, $setting ) use ($keys) { |
|
367 | + foreach( $keys as $key ) { |
|
368 | + if( !glsr( Helper::class )->startsWith( $key, $setting ) || empty($value) ) { |
|
369 | 369 | continue; |
370 | 370 | } |
371 | - $value = str_repeat('•', 13); |
|
371 | + $value = str_repeat( '•', 13 ); |
|
372 | 372 | return; |
373 | 373 | } |
374 | 374 | }); |
@@ -25,21 +25,21 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * @return array |
27 | 27 | */ |
28 | - public function build(array $args = []) |
|
28 | + public function build( array $args = [] ) |
|
29 | 29 | { |
30 | 30 | $this->args = $args; |
31 | - $schema = $this->buildSummary($args); |
|
31 | + $schema = $this->buildSummary( $args ); |
|
32 | 32 | $reviews = []; |
33 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
33 | + foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) { |
|
34 | 34 | // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
35 | 35 | // @see https://developers.google.com/search/docs/data-types/review |
36 | - if ('local' != $review->review_type) { |
|
36 | + if( 'local' != $review->review_type ) { |
|
37 | 37 | continue; |
38 | 38 | } |
39 | - $reviews[] = $this->buildReview($review); |
|
39 | + $reviews[] = $this->buildReview( $review ); |
|
40 | 40 | } |
41 | - if (!empty($reviews)) { |
|
42 | - array_walk($reviews, function (&$review) { |
|
41 | + if( !empty($reviews) ) { |
|
42 | + array_walk( $reviews, function( &$review ) { |
|
43 | 43 | unset($review['@context']); |
44 | 44 | unset($review['itemReviewed']); |
45 | 45 | }); |
@@ -52,27 +52,27 @@ discard block |
||
52 | 52 | * @param array|null $args |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - public function buildSummary($args = null) |
|
55 | + public function buildSummary( $args = null ) |
|
56 | 56 | { |
57 | - if (is_array($args)) { |
|
57 | + if( is_array( $args ) ) { |
|
58 | 58 | $this->args = $args; |
59 | 59 | } |
60 | - $buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
61 | - $count = array_sum($this->getRatingCounts()); |
|
62 | - $schema = method_exists($this, $buildSummary) |
|
60 | + $buildSummary = glsr( Helper::class )->buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
|
61 | + $count = array_sum( $this->getRatingCounts() ); |
|
62 | + $schema = method_exists( $this, $buildSummary ) |
|
63 | 63 | ? $this->$buildSummary() |
64 | 64 | : $this->buildSummaryForCustom(); |
65 | - if (!empty($count)) { |
|
65 | + if( !empty($count) ) { |
|
66 | 66 | $schema->aggregateRating( |
67 | - $this->getSchemaType('AggregateRating') |
|
68 | - ->ratingValue($this->getRatingValue()) |
|
69 | - ->reviewCount($count) |
|
70 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
71 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
67 | + $this->getSchemaType( 'AggregateRating' ) |
|
68 | + ->ratingValue( $this->getRatingValue() ) |
|
69 | + ->reviewCount( $count ) |
|
70 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
71 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | $schema = $schema->toArray(); |
75 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
75 | + return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,64 +80,64 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function render() |
82 | 82 | { |
83 | - if (empty(glsr()->schemas)) { |
|
83 | + if( empty(glsr()->schemas) ) { |
|
84 | 84 | return; |
85 | 85 | } |
86 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
87 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
86 | + printf( '<script type="application/ld+json">%s</script>', json_encode( |
|
87 | + apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
|
88 | 88 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
89 | - )); |
|
89 | + ) ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * @return void |
94 | 94 | */ |
95 | - public function store(array $schema) |
|
95 | + public function store( array $schema ) |
|
96 | 96 | { |
97 | 97 | $schemas = glsr()->schemas; |
98 | 98 | $schemas[] = $schema; |
99 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
99 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @param Review $review |
104 | 104 | * @return array |
105 | 105 | */ |
106 | - protected function buildReview($review) |
|
106 | + protected function buildReview( $review ) |
|
107 | 107 | { |
108 | - $schema = $this->getSchemaType('Review') |
|
109 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
110 | - $schema->name($review->title); |
|
108 | + $schema = $this->getSchemaType( 'Review' ) |
|
109 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) { |
|
110 | + $schema->name( $review->title ); |
|
111 | 111 | }) |
112 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
113 | - $schema->reviewBody($review->content); |
|
112 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) { |
|
113 | + $schema->reviewBody( $review->content ); |
|
114 | 114 | }) |
115 | - ->datePublished((new DateTime($review->date))) |
|
116 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
117 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
118 | - if (!empty($review->rating)) { |
|
115 | + ->datePublished( (new DateTime( $review->date )) ) |
|
116 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
117 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
118 | + if( !empty($review->rating) ) { |
|
119 | 119 | $schema->reviewRating( |
120 | - $this->getSchemaType('Rating') |
|
121 | - ->ratingValue($review->rating) |
|
122 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
123 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
120 | + $this->getSchemaType( 'Rating' ) |
|
121 | + ->ratingValue( $review->rating ) |
|
122 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
123 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
124 | 124 | ); |
125 | 125 | } |
126 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
126 | + return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args ); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | 130 | * @param mixed $schema |
131 | 131 | * @return mixed |
132 | 132 | */ |
133 | - protected function buildSchemaValues($schema, array $values = []) |
|
133 | + protected function buildSchemaValues( $schema, array $values = [] ) |
|
134 | 134 | { |
135 | - foreach ($values as $value) { |
|
136 | - $option = $this->getSchemaOptionValue($value); |
|
137 | - if (empty($option)) { |
|
135 | + foreach( $values as $value ) { |
|
136 | + $option = $this->getSchemaOptionValue( $value ); |
|
137 | + if( empty($option) ) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | - $schema->$value($option); |
|
140 | + $schema->$value( $option ); |
|
141 | 141 | } |
142 | 142 | return $schema; |
143 | 143 | } |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected function buildSummaryForCustom() |
149 | 149 | { |
150 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
150 | + return $this->buildSchemaValues( $this->getSchemaType(), [ |
|
151 | 151 | 'description', 'image', 'name', 'url', |
152 | - ]); |
|
152 | + ] ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | */ |
158 | 158 | protected function buildSummaryForLocalBusiness() |
159 | 159 | { |
160 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
160 | + return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
|
161 | 161 | 'address', 'priceRange', 'telephone', |
162 | - ]); |
|
162 | + ] ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | */ |
168 | 168 | protected function buildSummaryForProduct() |
169 | 169 | { |
170 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
171 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
170 | + $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' ); |
|
171 | + $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [ |
|
172 | 172 | 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
173 | - ]); |
|
173 | + ] ); |
|
174 | 174 | return $this->buildSummaryForCustom() |
175 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
176 | - $schema->offers($offers); |
|
175 | + ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) { |
|
176 | + $schema->offers( $offers ); |
|
177 | 177 | }) |
178 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
178 | + ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' ); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function getRatingCounts() |
185 | 185 | { |
186 | - if (!isset($this->ratingCounts)) { |
|
187 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
186 | + if( !isset($this->ratingCounts) ) { |
|
187 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args ); |
|
188 | 188 | } |
189 | 189 | return $this->ratingCounts; |
190 | 190 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | protected function getRatingValue() |
196 | 196 | { |
197 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
197 | + return glsr( Rating::class )->getAverage( $this->getRatingCounts() ); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -202,15 +202,15 @@ discard block |
||
202 | 202 | * @param string $fallback |
203 | 203 | * @return string |
204 | 204 | */ |
205 | - protected function getSchemaOption($option, $fallback) |
|
205 | + protected function getSchemaOption( $option, $fallback ) |
|
206 | 206 | { |
207 | - $option = strtolower($option); |
|
208 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
207 | + $option = strtolower( $option ); |
|
208 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
209 | 209 | return $schemaOption; |
210 | 210 | } |
211 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
212 | - if (is_array($setting)) { |
|
213 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
211 | + $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
|
212 | + if( is_array( $setting ) ) { |
|
213 | + return $this->getSchemaOptionDefault( $setting, $fallback ); |
|
214 | 214 | } |
215 | 215 | return !empty($setting) |
216 | 216 | ? $setting |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | * @param string $fallback |
222 | 222 | * @return string |
223 | 223 | */ |
224 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
224 | + protected function getSchemaOptionDefault( array $setting, $fallback ) |
|
225 | 225 | { |
226 | - $setting = wp_parse_args($setting, [ |
|
226 | + $setting = wp_parse_args( $setting, [ |
|
227 | 227 | 'custom' => '', |
228 | 228 | 'default' => $fallback, |
229 | - ]); |
|
229 | + ] ); |
|
230 | 230 | return 'custom' != $setting['default'] |
231 | 231 | ? $setting['default'] |
232 | 232 | : $setting['custom']; |
@@ -237,17 +237,17 @@ discard block |
||
237 | 237 | * @param string $fallback |
238 | 238 | * @return void|string |
239 | 239 | */ |
240 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
240 | + protected function getSchemaOptionValue( $option, $fallback = 'post' ) |
|
241 | 241 | { |
242 | - $value = $this->getSchemaOption($option, $fallback); |
|
243 | - if ($value != $fallback) { |
|
242 | + $value = $this->getSchemaOption( $option, $fallback ); |
|
243 | + if( $value != $fallback ) { |
|
244 | 244 | return $value; |
245 | 245 | } |
246 | - if (!is_single() && !is_page()) { |
|
246 | + if( !is_single() && !is_page() ) { |
|
247 | 247 | return; |
248 | 248 | } |
249 | - $method = glsr(Helper::class)->buildMethodName($option, 'getThing'); |
|
250 | - if (method_exists($this, $method)) { |
|
249 | + $method = glsr( Helper::class )->buildMethodName( $option, 'getThing' ); |
|
250 | + if( method_exists( $this, $method ) ) { |
|
251 | 251 | return $this->$method(); |
252 | 252 | } |
253 | 253 | } |
@@ -256,15 +256,15 @@ discard block |
||
256 | 256 | * @param string|null $type |
257 | 257 | * @return mixed |
258 | 258 | */ |
259 | - protected function getSchemaType($type = null) |
|
259 | + protected function getSchemaType( $type = null ) |
|
260 | 260 | { |
261 | - if (!is_string($type)) { |
|
262 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
261 | + if( !is_string( $type ) ) { |
|
262 | + $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
|
263 | 263 | } |
264 | - $className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema'); |
|
265 | - return class_exists($className) |
|
264 | + $className = glsr( Helper::class )->buildClassName( $type, 'Modules\Schema' ); |
|
265 | + return class_exists( $className ) |
|
266 | 266 | ? new $className() |
267 | - : new UnknownType($type); |
|
267 | + : new UnknownType( $type ); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -272,8 +272,8 @@ discard block |
||
272 | 272 | */ |
273 | 273 | protected function getThingDescription() |
274 | 274 | { |
275 | - $description = strip_shortcodes(wp_strip_all_tags(get_the_excerpt())); |
|
276 | - return wp_trim_words($description, apply_filters('excerpt_length', 55)); |
|
275 | + $description = strip_shortcodes( wp_strip_all_tags( get_the_excerpt() ) ); |
|
276 | + return wp_trim_words( $description, apply_filters( 'excerpt_length', 55 ) ); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | */ |
282 | 282 | protected function getThingImage() |
283 | 283 | { |
284 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
284 | + return (string)get_the_post_thumbnail_url( null, 'large' ); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -297,6 +297,6 @@ discard block |
||
297 | 297 | */ |
298 | 298 | protected function getThingUrl() |
299 | 299 | { |
300 | - return (string) get_the_permalink(); |
|
300 | + return (string)get_the_permalink(); |
|
301 | 301 | } |
302 | 302 | } |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | * @param bool $single |
18 | 18 | * @return mixed |
19 | 19 | */ |
20 | - public function get($postId, $key, $single = true) |
|
20 | + public function get( $postId, $key, $single = true ) |
|
21 | 21 | { |
22 | - $key = glsr(Helper::class)->prefix('_', $key); |
|
23 | - return get_post_meta(intval($postId), $key, $single); |
|
22 | + $key = glsr( Helper::class )->prefix( '_', $key ); |
|
23 | + return get_post_meta( intval( $postId ), $key, $single ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | * @param string $assignedTo |
29 | 29 | * @return void|WP_Post |
30 | 30 | */ |
31 | - public function getAssignedToPost($postId, $assignedTo = '') |
|
31 | + public function getAssignedToPost( $postId, $assignedTo = '' ) |
|
32 | 32 | { |
33 | - if (empty($assignedTo)) { |
|
34 | - $assignedTo = $this->get($postId, 'assigned_to'); |
|
33 | + if( empty($assignedTo) ) { |
|
34 | + $assignedTo = $this->get( $postId, 'assigned_to' ); |
|
35 | 35 | } |
36 | - if (empty($assignedTo)) { |
|
36 | + if( empty($assignedTo) ) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | - $assignedPost = get_post($assignedTo); |
|
40 | - if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) { |
|
39 | + $assignedPost = get_post( $assignedTo ); |
|
40 | + if( $assignedPost instanceof WP_Post && $assignedPost->ID != $postId ) { |
|
41 | 41 | return $assignedPost; |
42 | 42 | } |
43 | 43 | } |
@@ -47,25 +47,25 @@ discard block |
||
47 | 47 | * @param string $metaValue |
48 | 48 | * @return array|int |
49 | 49 | */ |
50 | - public function getReviewCount($metaKey = '', $metaValue = '') |
|
50 | + public function getReviewCount( $metaKey = '', $metaValue = '' ) |
|
51 | 51 | { |
52 | - if (!$metaKey) { |
|
53 | - return (array) wp_count_posts(Application::POST_TYPE); |
|
52 | + if( !$metaKey ) { |
|
53 | + return (array)wp_count_posts( Application::POST_TYPE ); |
|
54 | 54 | } |
55 | - $counts = glsr(Cache::class)->getReviewCountsFor($metaKey); |
|
56 | - if (!$metaValue) { |
|
55 | + $counts = glsr( Cache::class )->getReviewCountsFor( $metaKey ); |
|
56 | + if( !$metaValue ) { |
|
57 | 57 | return $counts; |
58 | 58 | } |
59 | - return glsr_get($counts, $metaValue, 0); |
|
59 | + return glsr_get( $counts, $metaValue, 0 ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @param string $metaReviewType |
64 | 64 | * @return array |
65 | 65 | */ |
66 | - public function getReviewIdsByType($metaReviewType) |
|
66 | + public function getReviewIdsByType( $metaReviewType ) |
|
67 | 67 | { |
68 | - return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType); |
|
68 | + return glsr( SqlQueries::class )->getReviewIdsByType( $metaReviewType ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -73,24 +73,24 @@ discard block |
||
73 | 73 | * @param string $status |
74 | 74 | * @return array |
75 | 75 | */ |
76 | - public function getReviewsMeta($key, $status = 'publish') |
|
76 | + public function getReviewsMeta( $key, $status = 'publish' ) |
|
77 | 77 | { |
78 | - if ('all' == $status || empty($status)) { |
|
79 | - $status = get_post_stati(['exclude_from_search' => false]); |
|
78 | + if( 'all' == $status || empty($status) ) { |
|
79 | + $status = get_post_stati( ['exclude_from_search' => false] ); |
|
80 | 80 | } |
81 | - return glsr(SqlQueries::class)->getReviewsMeta($key, $status); |
|
81 | + return glsr( SqlQueries::class )->getReviewsMeta( $key, $status ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @param string $field |
86 | 86 | * @return array |
87 | 87 | */ |
88 | - public function getTermIds(array $values, $field) |
|
88 | + public function getTermIds( array $values, $field ) |
|
89 | 89 | { |
90 | 90 | $termIds = []; |
91 | - foreach ($values as $value) { |
|
92 | - $term = get_term_by($field, $value, Application::TAXONOMY); |
|
93 | - if (!isset($term->term_id)) { |
|
91 | + foreach( $values as $value ) { |
|
92 | + $term = get_term_by( $field, $value, Application::TAXONOMY ); |
|
93 | + if( !isset($term->term_id) ) { |
|
94 | 94 | continue; |
95 | 95 | } |
96 | 96 | $termIds[] = $term->term_id; |
@@ -101,17 +101,17 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * @return array |
103 | 103 | */ |
104 | - public function getTerms(array $args = []) |
|
104 | + public function getTerms( array $args = [] ) |
|
105 | 105 | { |
106 | - $args = wp_parse_args($args, [ |
|
106 | + $args = wp_parse_args( $args, [ |
|
107 | 107 | 'count' => false, |
108 | 108 | 'fields' => 'id=>name', |
109 | 109 | 'hide_empty' => false, |
110 | 110 | 'taxonomy' => Application::TAXONOMY, |
111 | - ]); |
|
112 | - $terms = get_terms($args); |
|
113 | - if (is_wp_error($terms)) { |
|
114 | - glsr_log()->error($terms->get_error_message()); |
|
111 | + ] ); |
|
112 | + $terms = get_terms( $args ); |
|
113 | + if( is_wp_error( $terms ) ) { |
|
114 | + glsr_log()->error( $terms->get_error_message() ); |
|
115 | 115 | return []; |
116 | 116 | } |
117 | 117 | return $terms; |
@@ -121,36 +121,36 @@ discard block |
||
121 | 121 | * @param string $searchTerm |
122 | 122 | * @return void|string |
123 | 123 | */ |
124 | - public function searchPosts($searchTerm) |
|
124 | + public function searchPosts( $searchTerm ) |
|
125 | 125 | { |
126 | 126 | $args = [ |
127 | 127 | 'post_status' => 'publish', |
128 | 128 | 'post_type' => 'any', |
129 | 129 | ]; |
130 | - if (is_numeric($searchTerm)) { |
|
130 | + if( is_numeric( $searchTerm ) ) { |
|
131 | 131 | $args['post__in'] = [$searchTerm]; |
132 | 132 | } else { |
133 | 133 | $args['orderby'] = 'relevance'; |
134 | 134 | $args['posts_per_page'] = 10; |
135 | 135 | $args['s'] = $searchTerm; |
136 | 136 | } |
137 | - $queryBuilder = glsr(QueryBuilder::class); |
|
138 | - add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2); |
|
139 | - $search = new WP_Query($args); |
|
140 | - remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500); |
|
141 | - if (!$search->have_posts()) { |
|
137 | + $queryBuilder = glsr( QueryBuilder::class ); |
|
138 | + add_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2 ); |
|
139 | + $search = new WP_Query( $args ); |
|
140 | + remove_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500 ); |
|
141 | + if( !$search->have_posts() ) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | $results = ''; |
145 | - while ($search->have_posts()) { |
|
145 | + while( $search->have_posts() ) { |
|
146 | 146 | $search->the_post(); |
147 | 147 | ob_start(); |
148 | - glsr()->render('partials/editor/search-result', [ |
|
148 | + glsr()->render( 'partials/editor/search-result', [ |
|
149 | 149 | 'ID' => get_the_ID(), |
150 | - 'permalink' => esc_url((string) get_permalink()), |
|
151 | - 'title' => esc_attr(get_the_title()), |
|
152 | - ]); |
|
153 | - $results.= ob_get_clean(); |
|
150 | + 'permalink' => esc_url( (string)get_permalink() ), |
|
151 | + 'title' => esc_attr( get_the_title() ), |
|
152 | + ] ); |
|
153 | + $results .= ob_get_clean(); |
|
154 | 154 | } |
155 | 155 | wp_reset_postdata(); |
156 | 156 | return $results; |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | * @param mixed $value |
163 | 163 | * @return int|bool |
164 | 164 | */ |
165 | - public function update($postId, $key, $value) |
|
165 | + public function update( $postId, $key, $value ) |
|
166 | 166 | { |
167 | - $key = glsr(Helper::class)->prefix('_', $key); |
|
168 | - return update_post_meta($postId, $key, $value); |
|
167 | + $key = glsr( Helper::class )->prefix( '_', $key ); |
|
168 | + return update_post_meta( $postId, $key, $value ); |
|
169 | 169 | } |
170 | 170 | } |
@@ -18,31 +18,31 @@ discard block |
||
18 | 18 | * @param string $id |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public function buildFields($id) |
|
21 | + public function buildFields( $id ) |
|
22 | 22 | { |
23 | - $this->settings = glsr(DefaultsManager::class)->settings(); |
|
24 | - $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor'); |
|
25 | - $data = !method_exists($this, $method) |
|
26 | - ? $this->getTemplateData($id) |
|
27 | - : $this->$method($id); |
|
28 | - return glsr(Template::class)->build('pages/settings/'.$id, $data); |
|
23 | + $this->settings = glsr( DefaultsManager::class )->settings(); |
|
24 | + $method = glsr( Helper::class )->buildMethodName( $id, 'getTemplateDataFor' ); |
|
25 | + $data = !method_exists( $this, $method ) |
|
26 | + ? $this->getTemplateData( $id ) |
|
27 | + : $this->$method( $id ); |
|
28 | + return glsr( Template::class )->build( 'pages/settings/'.$id, $data ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @return string |
33 | 33 | */ |
34 | - protected function getFieldDefault(array $field) |
|
34 | + protected function getFieldDefault( array $field ) |
|
35 | 35 | { |
36 | - return glsr_get($field, 'default'); |
|
36 | + return glsr_get( $field, 'default' ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @return string |
41 | 41 | */ |
42 | - protected function getFieldNameForDependsOn($path) |
|
42 | + protected function getFieldNameForDependsOn( $path ) |
|
43 | 43 | { |
44 | - $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey()); |
|
45 | - return $this->isMultiDependency($path) |
|
44 | + $fieldName = glsr( Helper::class )->convertPathToName( $path, OptionManager::databaseKey() ); |
|
45 | + return $this->isMultiDependency( $path ) |
|
46 | 46 | ? $fieldName.'[]' |
47 | 47 | : $fieldName; |
48 | 48 | } |
@@ -50,25 +50,25 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * @return array |
52 | 52 | */ |
53 | - protected function getSettingFields($path) |
|
53 | + protected function getSettingFields( $path ) |
|
54 | 54 | { |
55 | - return array_filter($this->settings, function ($key) use ($path) { |
|
56 | - return glsr(Helper::class)->startsWith($path, $key); |
|
57 | - }, ARRAY_FILTER_USE_KEY); |
|
55 | + return array_filter( $this->settings, function( $key ) use ($path) { |
|
56 | + return glsr( Helper::class )->startsWith( $path, $key ); |
|
57 | + }, ARRAY_FILTER_USE_KEY ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @return string |
62 | 62 | */ |
63 | - protected function getSettingRows(array $fields) |
|
63 | + protected function getSettingRows( array $fields ) |
|
64 | 64 | { |
65 | 65 | $rows = ''; |
66 | - foreach ($fields as $name => $field) { |
|
67 | - $field = wp_parse_args($field, [ |
|
66 | + foreach( $fields as $name => $field ) { |
|
67 | + $field = wp_parse_args( $field, [ |
|
68 | 68 | 'is_setting' => true, |
69 | 69 | 'name' => $name, |
70 | - ]); |
|
71 | - $rows.= new Field($this->normalize($field)); |
|
70 | + ] ); |
|
71 | + $rows .= new Field( $this->normalize( $field ) ); |
|
72 | 72 | } |
73 | 73 | return $rows; |
74 | 74 | } |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | * @param string $id |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - protected function getTemplateData($id) |
|
80 | + protected function getTemplateData( $id ) |
|
81 | 81 | { |
82 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
82 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
83 | 83 | return [ |
84 | 84 | 'context' => [ |
85 | - 'rows' => $this->getSettingRows($fields), |
|
85 | + 'rows' => $this->getSettingRows( $fields ), |
|
86 | 86 | ], |
87 | 87 | ]; |
88 | 88 | } |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | * @param string $id |
92 | 92 | * @return array |
93 | 93 | */ |
94 | - protected function getTemplateDataForAddons($id) |
|
94 | + protected function getTemplateDataForAddons( $id ) |
|
95 | 95 | { |
96 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
97 | - $settings = glsr(Helper::class)->convertDotNotationArray($fields); |
|
98 | - $settingKeys = array_keys($settings['settings']['addons']); |
|
96 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
97 | + $settings = glsr( Helper::class )->convertDotNotationArray( $fields ); |
|
98 | + $settingKeys = array_keys( $settings['settings']['addons'] ); |
|
99 | 99 | $results = []; |
100 | - foreach ($settingKeys as $key) { |
|
101 | - $addonFields = array_filter($fields, function ($path) use ($key) { |
|
102 | - return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path); |
|
103 | - }, ARRAY_FILTER_USE_KEY); |
|
104 | - $results[$key] = $this->getSettingRows($addonFields); |
|
100 | + foreach( $settingKeys as $key ) { |
|
101 | + $addonFields = array_filter( $fields, function( $path ) use ($key) { |
|
102 | + return glsr( Helper::class )->startsWith( 'settings.addons.'.$key, $path ); |
|
103 | + }, ARRAY_FILTER_USE_KEY ); |
|
104 | + $results[$key] = $this->getSettingRows( $addonFields ); |
|
105 | 105 | } |
106 | - ksort($results); |
|
106 | + ksort( $results ); |
|
107 | 107 | return [ |
108 | 108 | 'settings' => $results, |
109 | 109 | ]; |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | * @param string $id |
114 | 114 | * @return array |
115 | 115 | */ |
116 | - protected function getTemplateDataForLicenses($id) |
|
116 | + protected function getTemplateDataForLicenses( $id ) |
|
117 | 117 | { |
118 | - $fields = $this->getSettingFields($this->normalizeSettingPath($id)); |
|
119 | - ksort($fields); |
|
118 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
119 | + ksort( $fields ); |
|
120 | 120 | return [ |
121 | 121 | 'context' => [ |
122 | - 'rows' => $this->getSettingRows($fields), |
|
122 | + 'rows' => $this->getSettingRows( $fields ), |
|
123 | 123 | ], |
124 | 124 | ]; |
125 | 125 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | protected function getTemplateDataForTranslations() |
131 | 131 | { |
132 | - $translations = glsr(Translation::class)->renderAll(); |
|
132 | + $translations = glsr( Translation::class )->renderAll(); |
|
133 | 133 | $class = empty($translations) |
134 | 134 | ? 'glsr-hidden' |
135 | 135 | : ''; |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | * @param string|array $expectedValue |
148 | 148 | * @return bool |
149 | 149 | */ |
150 | - protected function isFieldHidden($path, $expectedValue) |
|
150 | + protected function isFieldHidden( $path, $expectedValue ) |
|
151 | 151 | { |
152 | - $optionValue = glsr(OptionManager::class)->get( |
|
152 | + $optionValue = glsr( OptionManager::class )->get( |
|
153 | 153 | $path, |
154 | - glsr(Helper::class)->dataGet(glsr()->defaults, $path) |
|
154 | + glsr( Helper::class )->dataGet( glsr()->defaults, $path ) |
|
155 | 155 | ); |
156 | - if (is_array($expectedValue)) { |
|
157 | - return is_array($optionValue) |
|
158 | - ? 0 === count(array_intersect($optionValue, $expectedValue)) |
|
159 | - : !in_array($optionValue, $expectedValue); |
|
156 | + if( is_array( $expectedValue ) ) { |
|
157 | + return is_array( $optionValue ) |
|
158 | + ? 0 === count( array_intersect( $optionValue, $expectedValue ) ) |
|
159 | + : !in_array( $optionValue, $expectedValue ); |
|
160 | 160 | } |
161 | 161 | return $optionValue != $expectedValue; |
162 | 162 | } |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | /** |
165 | 165 | * @return bool |
166 | 166 | */ |
167 | - protected function isMultiDependency($path) |
|
167 | + protected function isMultiDependency( $path ) |
|
168 | 168 | { |
169 | - if (isset($this->settings[$path])) { |
|
169 | + if( isset($this->settings[$path]) ) { |
|
170 | 170 | $field = $this->settings[$path]; |
171 | 171 | return ('checkbox' == $field['type'] && !empty($field['options'])) |
172 | 172 | || !empty($field['multiple']); |
@@ -177,32 +177,32 @@ discard block |
||
177 | 177 | /** |
178 | 178 | * @return array |
179 | 179 | */ |
180 | - protected function normalize(array $field) |
|
180 | + protected function normalize( array $field ) |
|
181 | 181 | { |
182 | - $field = $this->normalizeDependsOn($field); |
|
183 | - $field = $this->normalizeLabelAndLegend($field); |
|
184 | - $field = $this->normalizeValue($field); |
|
182 | + $field = $this->normalizeDependsOn( $field ); |
|
183 | + $field = $this->normalizeLabelAndLegend( $field ); |
|
184 | + $field = $this->normalizeValue( $field ); |
|
185 | 185 | return $field; |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - protected function normalizeDependsOn(array $field) |
|
191 | + protected function normalizeDependsOn( array $field ) |
|
192 | 192 | { |
193 | - if (!empty($field['depends_on']) && is_array($field['depends_on'])) { |
|
193 | + if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) { |
|
194 | 194 | $isFieldHidden = false; |
195 | 195 | $conditions = []; |
196 | - foreach ($field['depends_on'] as $path => $value) { |
|
196 | + foreach( $field['depends_on'] as $path => $value ) { |
|
197 | 197 | $conditions[] = [ |
198 | - 'name' => $this->getFieldNameForDependsOn($path), |
|
198 | + 'name' => $this->getFieldNameForDependsOn( $path ), |
|
199 | 199 | 'value' => $value, |
200 | 200 | ]; |
201 | - if ($this->isFieldHidden($path, $value)) { |
|
201 | + if( $this->isFieldHidden( $path, $value ) ) { |
|
202 | 202 | $isFieldHidden = true; |
203 | 203 | } |
204 | 204 | } |
205 | - $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT); |
|
205 | + $field['data-depends'] = json_encode( $conditions, JSON_HEX_APOS | JSON_HEX_QUOT ); |
|
206 | 206 | $field['is_hidden'] = $isFieldHidden; |
207 | 207 | } |
208 | 208 | return $field; |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | /** |
212 | 212 | * @return array |
213 | 213 | */ |
214 | - protected function normalizeLabelAndLegend(array $field) |
|
214 | + protected function normalizeLabelAndLegend( array $field ) |
|
215 | 215 | { |
216 | - if (!empty($field['label'])) { |
|
216 | + if( !empty($field['label']) ) { |
|
217 | 217 | $field['legend'] = $field['label']; |
218 | 218 | unset($field['label']); |
219 | 219 | } else { |
220 | 220 | $field['is_valid'] = false; |
221 | - glsr_log()->warning('Setting field is missing a label')->debug($field); |
|
221 | + glsr_log()->warning( 'Setting field is missing a label' )->debug( $field ); |
|
222 | 222 | } |
223 | 223 | return $field; |
224 | 224 | } |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | /** |
227 | 227 | * @return array |
228 | 228 | */ |
229 | - protected function normalizeValue(array $field) |
|
229 | + protected function normalizeValue( array $field ) |
|
230 | 230 | { |
231 | - if (!isset($field['value'])) { |
|
232 | - $field['value'] = glsr(OptionManager::class)->get( |
|
231 | + if( !isset($field['value']) ) { |
|
232 | + $field['value'] = glsr( OptionManager::class )->get( |
|
233 | 233 | $field['name'], |
234 | - $this->getFieldDefault($field) |
|
234 | + $this->getFieldDefault( $field ) |
|
235 | 235 | ); |
236 | 236 | } |
237 | 237 | return $field; |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | /** |
241 | 241 | * @return string |
242 | 242 | */ |
243 | - protected function normalizeSettingPath($path) |
|
243 | + protected function normalizeSettingPath( $path ) |
|
244 | 244 | { |
245 | - return glsr(Helper::class)->prefix('settings.', rtrim($path, '.')); |
|
245 | + return glsr( Helper::class )->prefix( 'settings.', rtrim( $path, '.' ) ); |
|
246 | 246 | } |
247 | 247 | } |