@@ -19,27 +19,27 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function registerPostType() |
21 | 21 | { |
22 | - if( !glsr()->hasPermission() )return; |
|
22 | + if (!glsr()->hasPermission())return; |
|
23 | 23 | $command = new RegisterPostType([ |
24 | 24 | 'capabilities'=> ['create_posts' => 'create_'.Application::POST_TYPE], |
25 | 25 | 'columns' => [ |
26 | 26 | 'title' => '', |
27 | 27 | 'category' => '', |
28 | - 'assigned_to' => __( 'Assigned To', 'site-reviews' ), |
|
29 | - 'reviewer' => __( 'Author', 'site-reviews' ), |
|
30 | - 'review_type' => __( 'Type', 'site-reviews' ), |
|
31 | - 'rating' => __( 'Rating', 'site-reviews' ), |
|
32 | - 'pinned' => __( 'Pinned', 'site-reviews' ), |
|
28 | + 'assigned_to' => __('Assigned To', 'site-reviews'), |
|
29 | + 'reviewer' => __('Author', 'site-reviews'), |
|
30 | + 'review_type' => __('Type', 'site-reviews'), |
|
31 | + 'rating' => __('Rating', 'site-reviews'), |
|
32 | + 'pinned' => __('Pinned', 'site-reviews'), |
|
33 | 33 | 'date' => '', |
34 | 34 | ], |
35 | 35 | 'menu_icon' => 'dashicons-star-half', |
36 | 36 | 'menu_name' => glsr()->name, |
37 | 37 | 'map_meta_cap' => true, |
38 | - 'plural' => __( 'Reviews', 'site-reviews' ), |
|
38 | + 'plural' => __('Reviews', 'site-reviews'), |
|
39 | 39 | 'post_type' => Application::POST_TYPE, |
40 | - 'single' => __( 'Review', 'site-reviews' ), |
|
40 | + 'single' => __('Review', 'site-reviews'), |
|
41 | 41 | ]); |
42 | - $this->execute( $command ); |
|
42 | + $this->execute($command); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | 'site_reviews_form', |
54 | 54 | 'site_reviews_summary', |
55 | 55 | ]); |
56 | - $this->execute( $command ); |
|
56 | + $this->execute($command); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | 'show_admin_column' => true, |
70 | 70 | 'show_ui' => true, |
71 | 71 | ]); |
72 | - $this->execute( $command ); |
|
72 | + $this->execute($command); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -81,21 +81,21 @@ discard block |
||
81 | 81 | $command = new RegisterWidgets([ |
82 | 82 | 'site-reviews' => [ |
83 | 83 | 'class' => 'glsr-widget glsr-widget-site-reviews', |
84 | - 'description' => __( 'Your site’s most recent reviews.', 'site-reviews' ), |
|
85 | - 'title' => __( 'Recent Reviews', 'site-reviews' ), |
|
84 | + 'description' => __('Your site’s most recent reviews.', 'site-reviews'), |
|
85 | + 'title' => __('Recent Reviews', 'site-reviews'), |
|
86 | 86 | ], |
87 | 87 | 'site-reviews-form' => [ |
88 | 88 | 'class' => 'glsr-widget glsr-widget-site-reviews-form', |
89 | - 'description' => __( 'A "submit a review" form for your site.', 'site-reviews' ), |
|
90 | - 'title' => __( 'Submit a Review', 'site-reviews' ), |
|
89 | + 'description' => __('A "submit a review" form for your site.', 'site-reviews'), |
|
90 | + 'title' => __('Submit a Review', 'site-reviews'), |
|
91 | 91 | ], |
92 | 92 | 'site-reviews-summary' => [ |
93 | 93 | 'class' => 'glsr-widget glsr-widget-site-reviews-summary', |
94 | - 'description' => __( 'A summary of your site’s reviews.', 'site-reviews' ), |
|
95 | - 'title' => __( 'Summary of Reviews', 'site-reviews' ), |
|
94 | + 'description' => __('A summary of your site’s reviews.', 'site-reviews'), |
|
95 | + 'title' => __('Summary of Reviews', 'site-reviews'), |
|
96 | 96 | ], |
97 | 97 | ]); |
98 | - $this->execute( $command ); |
|
98 | + $this->execute($command); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -104,6 +104,6 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function renderSchema() |
106 | 106 | { |
107 | - glsr( Schema::class )->render(); |
|
107 | + glsr(Schema::class)->render(); |
|
108 | 108 | } |
109 | 109 | } |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function approve() |
23 | 23 | { |
24 | - check_admin_referer( 'approve-review_'.( $postId = $this->getPostId() )); |
|
24 | + check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
25 | 25 | wp_update_post([ |
26 | 26 | 'ID' => $postId, |
27 | 27 | 'post_status' => 'publish', |
28 | 28 | ]); |
29 | - wp_safe_redirect( wp_get_referer() ); |
|
29 | + wp_safe_redirect(wp_get_referer()); |
|
30 | 30 | exit; |
31 | 31 | } |
32 | 32 | |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | * @return array |
35 | 35 | * @filter bulk_post_updated_messages |
36 | 36 | */ |
37 | - public function filterBulkUpdateMessages( array $messages, array $counts ) |
|
37 | + public function filterBulkUpdateMessages(array $messages, array $counts) |
|
38 | 38 | { |
39 | 39 | $messages[Application::POST_TYPE] = [ |
40 | - 'updated' => _n( '%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews' ), |
|
41 | - 'locked' => _n( '%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews' ), |
|
42 | - 'deleted' => _n( '%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews' ), |
|
43 | - 'trashed' => _n( '%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews' ), |
|
44 | - 'untrashed' => _n( '%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews' ), |
|
40 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
41 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
42 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
43 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
44 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
45 | 45 | ]; |
46 | 46 | return $messages; |
47 | 47 | } |
@@ -50,26 +50,26 @@ discard block |
||
50 | 50 | * @return array |
51 | 51 | * @filter manage_.Application::POST_TYPE._posts_columns |
52 | 52 | */ |
53 | - public function filterColumnsForPostType( array $columns ) |
|
53 | + public function filterColumnsForPostType(array $columns) |
|
54 | 54 | { |
55 | 55 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
56 | - foreach( $postTypeColumns as $key => &$value ) { |
|
57 | - if( !array_key_exists( $key, $columns ) || !empty( $value ))continue; |
|
56 | + foreach ($postTypeColumns as $key => &$value) { |
|
57 | + if (!array_key_exists($key, $columns) || !empty($value))continue; |
|
58 | 58 | $value = $columns[$key]; |
59 | 59 | } |
60 | - if( count( glsr( Database::class )->getReviewsMeta( 'type' )) < 2 ) { |
|
61 | - unset( $postTypeColumns['review_type'] ); |
|
60 | + if (count(glsr(Database::class)->getReviewsMeta('type')) < 2) { |
|
61 | + unset($postTypeColumns['review_type']); |
|
62 | 62 | } |
63 | - return array_filter( $postTypeColumns, 'strlen' ); |
|
63 | + return array_filter($postTypeColumns, 'strlen'); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @return array |
68 | 68 | * @filter default_hidden_columns |
69 | 69 | */ |
70 | - public function filterDefaultHiddenColumns( array $hidden, WP_Screen $screen ) |
|
70 | + public function filterDefaultHiddenColumns(array $hidden, WP_Screen $screen) |
|
71 | 71 | { |
72 | - if( $screen->id == 'edit-'.Application::POST_TYPE ) { |
|
72 | + if ($screen->id == 'edit-'.Application::POST_TYPE) { |
|
73 | 73 | $hidden = ['reviewer']; |
74 | 74 | } |
75 | 75 | return $hidden; |
@@ -79,22 +79,22 @@ discard block |
||
79 | 79 | * @return array |
80 | 80 | * @filter post_row_actions |
81 | 81 | */ |
82 | - public function filterRowActions( array $actions, WP_Post $post ) |
|
82 | + public function filterRowActions(array $actions, WP_Post $post) |
|
83 | 83 | { |
84 | - if( $post->post_type != Application::POST_TYPE || $post->post_status == 'trash' ) { |
|
84 | + if ($post->post_type != Application::POST_TYPE || $post->post_status == 'trash') { |
|
85 | 85 | return $actions; |
86 | 86 | } |
87 | - unset( $actions['inline hide-if-no-js'] ); //Remove Quick-edit |
|
87 | + unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
88 | 88 | $rowActions = [ |
89 | - 'approve' => esc_attr__( 'Approve', 'site-reviews' ), |
|
90 | - 'unapprove' => esc_attr__( 'Unapprove', 'site-reviews' ), |
|
89 | + 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
90 | + 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
91 | 91 | ]; |
92 | - foreach( $rowActions as $key => $text ) { |
|
93 | - $actions[$key] = glsr( Builder::class )->a( $text, [ |
|
94 | - 'aria-label' => sprintf( esc_attr_x( '%s this review', 'Approve the review', 'site-reviews' ), text ), |
|
92 | + foreach ($rowActions as $key => $text) { |
|
93 | + $actions[$key] = glsr(Builder::class)->a($text, [ |
|
94 | + 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), text), |
|
95 | 95 | 'class' => 'change-'.Application::POST_TYPE.'-status', |
96 | 96 | 'href' => wp_nonce_url( |
97 | - admin_url( 'post.php?post='.$post->ID.'&action='.$key ), |
|
97 | + admin_url('post.php?post='.$post->ID.'&action='.$key), |
|
98 | 98 | $key.'-review_'.$post->ID |
99 | 99 | ), |
100 | 100 | ]); |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | * @return array |
107 | 107 | * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
108 | 108 | */ |
109 | - public function filterSortableColumns( array $columns ) |
|
109 | + public function filterSortableColumns(array $columns) |
|
110 | 110 | { |
111 | 111 | $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
112 | - unset( $postTypeColumns['cb'] ); |
|
113 | - foreach( $postTypeColumns as $key => $value ) { |
|
114 | - if( glsr( Helper::class )->startsWith( 'taxonomy', $key ))continue; |
|
112 | + unset($postTypeColumns['cb']); |
|
113 | + foreach ($postTypeColumns as $key => $value) { |
|
114 | + if (glsr(Helper::class)->startsWith('taxonomy', $key))continue; |
|
115 | 115 | $columns[$key] = $key; |
116 | 116 | } |
117 | 117 | return $columns; |
@@ -127,19 +127,19 @@ discard block |
||
127 | 127 | * @return string |
128 | 128 | * @filter ngettext |
129 | 129 | */ |
130 | - public function filterStatusText( $translation, $single, $plural, $number, $domain ) |
|
130 | + public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
131 | 131 | { |
132 | - if( $this->canModifyTranslation( $domain )) { |
|
132 | + if ($this->canModifyTranslation($domain)) { |
|
133 | 133 | $strings = [ |
134 | - 'Published' => __( 'Approved', 'site-reviews' ), |
|
135 | - 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
134 | + 'Published' => __('Approved', 'site-reviews'), |
|
135 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
136 | 136 | ]; |
137 | - foreach( $strings as $search => $replace ) { |
|
138 | - if( strpos( $single, $search ) === false )continue; |
|
137 | + foreach ($strings as $search => $replace) { |
|
138 | + if (strpos($single, $search) === false)continue; |
|
139 | 139 | $translation = $this->getTranslation([ |
140 | 140 | 'number' => $number, |
141 | - 'plural' => str_replace( $search, $replace, $plural ), |
|
142 | - 'single' => str_replace( $search, $replace, $single ), |
|
141 | + 'plural' => str_replace($search, $replace, $plural), |
|
142 | + 'single' => str_replace($search, $replace, $single), |
|
143 | 143 | ]); |
144 | 144 | } |
145 | 145 | } |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * @return void |
153 | 153 | * @action bulk_edit_custom_box |
154 | 154 | */ |
155 | - public function renderBulkEditFields( $columnName, $postType ) |
|
155 | + public function renderBulkEditFields($columnName, $postType) |
|
156 | 156 | { |
157 | - if( $columnName == 'assigned_to' && $postType == Application::POST_TYPE ) { |
|
158 | - $this->render( 'edit/bulk-edit-assigned-to' ); |
|
157 | + if ($columnName == 'assigned_to' && $postType == Application::POST_TYPE) { |
|
158 | + $this->render('edit/bulk-edit-assigned-to'); |
|
159 | 159 | }; |
160 | 160 | } |
161 | 161 | |
@@ -164,16 +164,16 @@ discard block |
||
164 | 164 | * @return void |
165 | 165 | * @action restrict_manage_posts |
166 | 166 | */ |
167 | - public function renderColumnFilters( $post_type ) |
|
167 | + public function renderColumnFilters($post_type) |
|
168 | 168 | { |
169 | - if( $post_type !== Application::POST_TYPE )return; |
|
170 | - if( !( $status = filter_input( INPUT_GET, 'post_status' ))) { |
|
169 | + if ($post_type !== Application::POST_TYPE)return; |
|
170 | + if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
171 | 171 | $status = 'publish'; |
172 | 172 | } |
173 | - $ratings = glsr( Database::class )->getReviewsMeta( 'rating', $status ); |
|
174 | - $types = glsr( Database::class )->getReviewsMeta( 'type', $status ); |
|
175 | - $this->renderFilterRatings( $ratings ); |
|
176 | - $this->renderFilterTypes( $types ); |
|
173 | + $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
174 | + $types = glsr(Database::class)->getReviewsMeta('type', $status); |
|
175 | + $this->renderFilterRatings($ratings); |
|
176 | + $this->renderFilterTypes($types); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | * @return void |
182 | 182 | * @action manage_posts_custom_column |
183 | 183 | */ |
184 | - public function renderColumnValues( $column, $postId ) |
|
184 | + public function renderColumnValues($column, $postId) |
|
185 | 185 | { |
186 | - if( glsr_current_screen()->id != Application::POST_TYPE )return; |
|
186 | + if (glsr_current_screen()->id != Application::POST_TYPE)return; |
|
187 | 187 | global $wp_version; |
188 | - $method = glsr( Helper::class )->buildMethodName( $column, 'buildColumn' ); |
|
189 | - echo method_exists( $this, $method ) |
|
190 | - ? call_user_func( [$this, $method], $postId ) |
|
191 | - : apply_filters( 'site-reviews/columns/'.$column, '', $postId ); |
|
188 | + $method = glsr(Helper::class)->buildMethodName($column, 'buildColumn'); |
|
189 | + echo method_exists($this, $method) |
|
190 | + ? call_user_func([$this, $method], $postId) |
|
191 | + : apply_filters('site-reviews/columns/'.$column, '', $postId); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | * @return void |
197 | 197 | * @action save_post_.Application::POST_TYPE |
198 | 198 | */ |
199 | - public function saveBulkEditFields( $postId ) |
|
199 | + public function saveBulkEditFields($postId) |
|
200 | 200 | { |
201 | - if( !current_user_can( 'edit_posts' ))return; |
|
202 | - if( $assignedTo = filter_input( INPUT_GET, 'assigned_to' ) && get_post( $assignedTo )) { |
|
203 | - update_post_meta( $postId, 'assigned_to', $assignedTo ); |
|
201 | + if (!current_user_can('edit_posts'))return; |
|
202 | + if ($assignedTo = filter_input(INPUT_GET, 'assigned_to') && get_post($assignedTo)) { |
|
203 | + update_post_meta($postId, 'assigned_to', $assignedTo); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -208,13 +208,13 @@ discard block |
||
208 | 208 | * @return void |
209 | 209 | * @action pre_get_posts |
210 | 210 | */ |
211 | - public function setQueryForColumn( WP_Query $query ) |
|
211 | + public function setQueryForColumn(WP_Query $query) |
|
212 | 212 | { |
213 | - if( !$this->hasPermission( $query ))return; |
|
214 | - $this->setMetaQuery( $query, [ |
|
213 | + if (!$this->hasPermission($query))return; |
|
214 | + $this->setMetaQuery($query, [ |
|
215 | 215 | 'rating', 'review_type', |
216 | 216 | ]); |
217 | - $this->setOrderby( $query ); |
|
217 | + $this->setOrderby($query); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function unapprove() |
225 | 225 | { |
226 | - check_admin_referer( 'unapprove-review_'.( $postId = $this->getPostId() )); |
|
226 | + check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
227 | 227 | wp_update_post([ |
228 | 228 | 'ID' => $postId, |
229 | 229 | 'post_status' => 'pending', |
230 | 230 | ]); |
231 | - wp_safe_redirect( wp_get_referer() ); |
|
231 | + wp_safe_redirect(wp_get_referer()); |
|
232 | 232 | exit; |
233 | 233 | } |
234 | 234 | |
@@ -236,14 +236,14 @@ discard block |
||
236 | 236 | * @param int $postId |
237 | 237 | * @return string |
238 | 238 | */ |
239 | - protected function buildColumnAssignedTo( $postId ) |
|
239 | + protected function buildColumnAssignedTo($postId) |
|
240 | 240 | { |
241 | - $post = get_post( glsr( Database::class )->getReviewMeta( $postId )->assigned_to ); |
|
242 | - if( !( $post instanceof WP_Post ) || $post->post_status != 'publish' ) { |
|
241 | + $post = get_post(glsr(Database::class)->getReviewMeta($postId)->assigned_to); |
|
242 | + if (!($post instanceof WP_Post) || $post->post_status != 'publish') { |
|
243 | 243 | return '—'; |
244 | 244 | } |
245 | - return glsr( Builder::class )->a( get_the_title( $post->ID ), [ |
|
246 | - 'href' => (string)get_the_permalink( $post->ID ), |
|
245 | + return glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
246 | + 'href' => (string)get_the_permalink($post->ID), |
|
247 | 247 | ]); |
248 | 248 | } |
249 | 249 | |
@@ -251,19 +251,19 @@ discard block |
||
251 | 251 | * @param int $postId |
252 | 252 | * @return string |
253 | 253 | */ |
254 | - protected function buildColumnReviewer( $postId ) |
|
254 | + protected function buildColumnReviewer($postId) |
|
255 | 255 | { |
256 | - return glsr( Database::class )->getReviewMeta( $postId )->author; |
|
256 | + return glsr(Database::class)->getReviewMeta($postId)->author; |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | 260 | * @param int $postId |
261 | 261 | * @return string |
262 | 262 | */ |
263 | - protected function buildColumnStars( $postId ) |
|
263 | + protected function buildColumnStars($postId) |
|
264 | 264 | { |
265 | - return glsr( Html::class )->buildPartial( 'star-rating', [ |
|
266 | - 'rating' => glsr( Database::class )->getReviewMeta( $postId )->rating, |
|
265 | + return glsr(Html::class)->buildPartial('star-rating', [ |
|
266 | + 'rating' => glsr(Database::class)->getReviewMeta($postId)->rating, |
|
267 | 267 | ]); |
268 | 268 | } |
269 | 269 | |
@@ -271,13 +271,13 @@ discard block |
||
271 | 271 | * @param int $postId |
272 | 272 | * @return string |
273 | 273 | */ |
274 | - protected function buildColumnSticky( $postId ) |
|
274 | + protected function buildColumnSticky($postId) |
|
275 | 275 | { |
276 | - $pinned = glsr( Database::class )->getReviewMeta( $postId )->pinned |
|
276 | + $pinned = glsr(Database::class)->getReviewMeta($postId)->pinned |
|
277 | 277 | ? ' pinned' |
278 | 278 | : ''; |
279 | - return glsr( Builder::class )->i([ |
|
280 | - 'class' => trim( 'dashicons dashicons-sticky '.$pinned ), |
|
279 | + return glsr(Builder::class)->i([ |
|
280 | + 'class' => trim('dashicons dashicons-sticky '.$pinned), |
|
281 | 281 | 'data-id' => $postId, |
282 | 282 | ]); |
283 | 283 | } |
@@ -286,10 +286,10 @@ discard block |
||
286 | 286 | * @param int $postId |
287 | 287 | * @return string |
288 | 288 | */ |
289 | - protected function buildColumnType( $postId ) |
|
289 | + protected function buildColumnType($postId) |
|
290 | 290 | { |
291 | - $reviewMeta = glsr( Database::class )->getReviewMeta( $postId ); |
|
292 | - return isset( glsr()->reviewTypes[$reviewMeta->review_type] ) |
|
291 | + $reviewMeta = glsr(Database::class)->getReviewMeta($postId); |
|
292 | + return isset(glsr()->reviewTypes[$reviewMeta->review_type]) |
|
293 | 293 | ? glsr()->reviewTypes[$reviewMeta->review_type] |
294 | 294 | : $reviewMeta->review_type; |
295 | 295 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @param string $domain |
300 | 300 | * @return bool |
301 | 301 | */ |
302 | - protected function canModifyTranslation( $domain = 'default' ) |
|
302 | + protected function canModifyTranslation($domain = 'default') |
|
303 | 303 | { |
304 | 304 | return $domain == 'default' |
305 | 305 | && glsr_current_screen()->base == 'edit' |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | * Get the modified translation string |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - protected function getTranslation( array $args ) |
|
313 | + protected function getTranslation(array $args) |
|
314 | 314 | { |
315 | 315 | $defaults = [ |
316 | 316 | 'number' => 0, |
@@ -318,22 +318,22 @@ discard block |
||
318 | 318 | 'single' => '', |
319 | 319 | 'text' => '', |
320 | 320 | ]; |
321 | - $args = (object) wp_parse_args( $args, $defaults ); |
|
322 | - $translations = get_translations_for_domain( Application::ID ); |
|
321 | + $args = (object)wp_parse_args($args, $defaults); |
|
322 | + $translations = get_translations_for_domain(Application::ID); |
|
323 | 323 | return $args->text |
324 | - ? $translations->translate( $args->text ) |
|
325 | - : $translations->translate_plural( $args->single, $args->plural, $args->number ); |
|
324 | + ? $translations->translate($args->text) |
|
325 | + : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
329 | 329 | * @return bool |
330 | 330 | */ |
331 | - protected function hasPermission( WP_Query $query ) |
|
331 | + protected function hasPermission(WP_Query $query) |
|
332 | 332 | { |
333 | 333 | global $pagenow; |
334 | 334 | return is_admin() |
335 | 335 | && $query->is_main_query() |
336 | - && $query->get( 'post_type' ) == Application::POST_TYPE |
|
336 | + && $query->get('post_type') == Application::POST_TYPE |
|
337 | 337 | && $pagenow == 'edit.php'; |
338 | 338 | } |
339 | 339 | |
@@ -341,19 +341,19 @@ discard block |
||
341 | 341 | * @param array $ratings |
342 | 342 | * @return void |
343 | 343 | */ |
344 | - protected function renderFilterRatings( $ratings ) |
|
344 | + protected function renderFilterRatings($ratings) |
|
345 | 345 | { |
346 | - if( empty( $ratings ) |
|
347 | - || apply_filters( 'site-reviews/disable/filter/ratings', false ) |
|
346 | + if (empty($ratings) |
|
347 | + || apply_filters('site-reviews/disable/filter/ratings', false) |
|
348 | 348 | )return; |
349 | - $ratings = array_flip( array_reverse( $ratings )); |
|
350 | - array_walk( $ratings, function( &$value, $key ) { |
|
351 | - $label = _n( '%s star', '%s stars', $key, 'site-reviews' ); |
|
352 | - $value = sprintf( $label, $key ); |
|
349 | + $ratings = array_flip(array_reverse($ratings)); |
|
350 | + array_walk($ratings, function(&$value, $key) { |
|
351 | + $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
352 | + $value = sprintf($label, $key); |
|
353 | 353 | }); |
354 | - $ratings = [__( 'All ratings', 'site-reviews' )] + $ratings; |
|
355 | - printf( '<label class="screen-reader-text" for="rating">%s</label>', __( 'Filter by rating', 'site-reviews' )); |
|
356 | - glsr( Html::class )->renderPartial( 'filterby', [ |
|
354 | + $ratings = [__('All ratings', 'site-reviews')] + $ratings; |
|
355 | + printf('<label class="screen-reader-text" for="rating">%s</label>', __('Filter by rating', 'site-reviews')); |
|
356 | + glsr(Html::class)->renderPartial('filterby', [ |
|
357 | 357 | 'name' => 'rating', |
358 | 358 | 'values' => $ratings, |
359 | 359 | ]); |
@@ -363,18 +363,18 @@ discard block |
||
363 | 363 | * @param array $types |
364 | 364 | * @return void |
365 | 365 | */ |
366 | - protected function renderFilterTypes( $types ) |
|
366 | + protected function renderFilterTypes($types) |
|
367 | 367 | { |
368 | - if( count( $types ) < 1 |
|
369 | - || ( count( $types ) == 1 && $types[0] == 'local' ) |
|
370 | - || apply_filters( 'site-reviews/disable/filter/types', false ) |
|
368 | + if (count($types) < 1 |
|
369 | + || (count($types) == 1 && $types[0] == 'local') |
|
370 | + || apply_filters('site-reviews/disable/filter/types', false) |
|
371 | 371 | )return; |
372 | - $reviewTypes = [__( 'All types', 'site-reviews' )]; |
|
373 | - foreach( $types as $type ) { |
|
374 | - $reviewTypes[$type] = glsr( Strings::class )->review_types( $type, ucfirst( $type )); |
|
372 | + $reviewTypes = [__('All types', 'site-reviews')]; |
|
373 | + foreach ($types as $type) { |
|
374 | + $reviewTypes[$type] = glsr(Strings::class)->review_types($type, ucfirst($type)); |
|
375 | 375 | } |
376 | - printf( '<label class="screen-reader-text" for="type">%s</label>', __( 'Filter by type', 'site-reviews' )); |
|
377 | - glsr( Html::class )->renderPartial( 'filterby', [ |
|
376 | + printf('<label class="screen-reader-text" for="type">%s</label>', __('Filter by type', 'site-reviews')); |
|
377 | + glsr(Html::class)->renderPartial('filterby', [ |
|
378 | 378 | 'name' => 'review_type', |
379 | 379 | 'values' => $reviewTypes, |
380 | 380 | ]); |
@@ -383,30 +383,30 @@ discard block |
||
383 | 383 | /** |
384 | 384 | * @return void |
385 | 385 | */ |
386 | - protected function setMetaQuery( WP_Query $query, array $metaKeys ) |
|
386 | + protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
387 | 387 | { |
388 | - foreach( $metaKeys as $key ) { |
|
389 | - if( !( $value = filter_input( INPUT_GET, $key )))continue; |
|
390 | - $metaQuery = (array)$query->get( 'meta_query' ); |
|
388 | + foreach ($metaKeys as $key) { |
|
389 | + if (!($value = filter_input(INPUT_GET, $key)))continue; |
|
390 | + $metaQuery = (array)$query->get('meta_query'); |
|
391 | 391 | $metaQuery[] = [ |
392 | 392 | 'key' => $key, |
393 | 393 | 'value' => $value, |
394 | 394 | ]; |
395 | - $query->set( 'meta_query', $metaQuery ); |
|
395 | + $query->set('meta_query', $metaQuery); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
400 | 400 | * @return void |
401 | 401 | */ |
402 | - protected function setOrderby( WP_Query $query ) |
|
402 | + protected function setOrderby(WP_Query $query) |
|
403 | 403 | { |
404 | - $orderby = $query->get( 'orderby' ); |
|
404 | + $orderby = $query->get('orderby'); |
|
405 | 405 | $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
406 | - unset( $columns['cb'], $columns['title'], $columns['date'] ); |
|
407 | - if( in_array( $orderby, array_keys( $columns ))) { |
|
408 | - $query->set( 'meta_key', $orderby ); |
|
409 | - $query->set( 'orderby', 'meta_value' ); |
|
406 | + unset($columns['cb'], $columns['title'], $columns['date']); |
|
407 | + if (in_array($orderby, array_keys($columns))) { |
|
408 | + $query->set('meta_key', $orderby); |
|
409 | + $query->set('orderby', 'meta_value'); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | } |
@@ -13,13 +13,13 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * @return void |
15 | 15 | */ |
16 | - public function download( $filename, $content ) |
|
16 | + public function download($filename, $content) |
|
17 | 17 | { |
18 | - if( !current_user_can( Application::CAPABILITY ))return; |
|
18 | + if (!current_user_can(Application::CAPABILITY))return; |
|
19 | 19 | nocache_headers(); |
20 | - header( 'Content-Type: text/plain' ); |
|
21 | - header( 'Content-Disposition: attachment; filename="'.$filename.'"' ); |
|
22 | - echo html_entity_decode( wp_strip_all_tags( $content )); |
|
20 | + header('Content-Type: text/plain'); |
|
21 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
22 | + echo html_entity_decode(wp_strip_all_tags($content)); |
|
23 | 23 | exit; |
24 | 24 | } |
25 | 25 | |
@@ -28,19 +28,19 @@ discard block |
||
28 | 28 | * @return mixed |
29 | 29 | * @throws InvalidArgumentException |
30 | 30 | */ |
31 | - public function execute( $command ) |
|
31 | + public function execute($command) |
|
32 | 32 | { |
33 | - $handlerClass = str_replace( 'Commands', 'Handlers', get_class( $command )); |
|
34 | - if( !class_exists( $handlerClass )) { |
|
35 | - throw new InvalidArgumentException( 'Handler '.$handlerClass.' not found.' ); |
|
33 | + $handlerClass = str_replace('Commands', 'Handlers', get_class($command)); |
|
34 | + if (!class_exists($handlerClass)) { |
|
35 | + throw new InvalidArgumentException('Handler '.$handlerClass.' not found.'); |
|
36 | 36 | } |
37 | 37 | try { |
38 | - return glsr( $handlerClass )->handle( $command ); |
|
38 | + return glsr($handlerClass)->handle($command); |
|
39 | 39 | } |
40 | - catch( Exception $e ) { |
|
41 | - status_header( 400 ); |
|
42 | - glsr( Notice::class )->addError( new WP_Error( 'site_reviews_error', $e->getMessage() )); |
|
43 | - glsr_log()->error( $e->getMessage() ); |
|
40 | + catch (Exception $e) { |
|
41 | + status_header(400); |
|
42 | + glsr(Notice::class)->addError(new WP_Error('site_reviews_error', $e->getMessage())); |
|
43 | + glsr_log()->error($e->getMessage()); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
@@ -49,6 +49,6 @@ discard block |
||
49 | 49 | */ |
50 | 50 | protected function getPostId() |
51 | 51 | { |
52 | - return intval( filter_input( INPUT_GET, 'post' )); |
|
52 | + return intval(filter_input(INPUT_GET, 'post')); |
|
53 | 53 | } |
54 | 54 | } |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | * @return array |
29 | 29 | * @filter plugin_action_links_site-reviews/site-reviews.php |
30 | 30 | */ |
31 | - public function filterActionLinks( array $links ) |
|
31 | + public function filterActionLinks(array $links) |
|
32 | 32 | { |
33 | - $links[] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [ |
|
34 | - 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ), |
|
33 | + $links[] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
34 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
35 | 35 | ]); |
36 | 36 | return $links; |
37 | 37 | } |
@@ -40,19 +40,19 @@ discard block |
||
40 | 40 | * @return array |
41 | 41 | * @filter dashboard_glance_items |
42 | 42 | */ |
43 | - public function filterDashboardGlanceItems( array $items ) |
|
43 | + public function filterDashboardGlanceItems(array $items) |
|
44 | 44 | { |
45 | 45 | $postType = Application::POST_TYPE; |
46 | - $postCount = wp_count_posts( $postType ); |
|
47 | - if( !isset( $postCount->publish ) || !$postCount->publish ) { |
|
46 | + $postCount = wp_count_posts($postType); |
|
47 | + if (!isset($postCount->publish) || !$postCount->publish) { |
|
48 | 48 | return $items; |
49 | 49 | } |
50 | - $postTypeObject = get_post_type_object( $postType ); |
|
51 | - $text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' ); |
|
52 | - $text = sprintf( $text, number_format_i18n( $postCount->publish )); |
|
53 | - $items[] = $postTypeObject && current_user_can( $postTypeObject->cap->edit_posts ) |
|
54 | - ? sprintf( '<a class="glsr-review-count" href="edit.php?post_type=%s">%s</a>', $postType, $text ) |
|
55 | - : sprintf( '<span class="glsr-review-count">%s</span>', $text ); |
|
50 | + $postTypeObject = get_post_type_object($postType); |
|
51 | + $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
52 | + $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
53 | + $items[] = $postTypeObject && current_user_can($postTypeObject->cap->edit_posts) |
|
54 | + ? sprintf('<a class="glsr-review-count" href="edit.php?post_type=%s">%s</a>', $postType, $text) |
|
55 | + : sprintf('<span class="glsr-review-count">%s</span>', $text); |
|
56 | 56 | return $items; |
57 | 57 | } |
58 | 58 | |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | * @return array |
61 | 61 | * @filter mce_external_plugins |
62 | 62 | */ |
63 | - public function filterTinymcePlugins( array $plugins ) |
|
63 | + public function filterTinymcePlugins(array $plugins) |
|
64 | 64 | { |
65 | - if( user_can_richedit() |
|
66 | - && ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ))) { |
|
67 | - $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' ); |
|
65 | + if (user_can_richedit() |
|
66 | + && (current_user_can('edit_posts') || current_user_can('edit_pages'))) { |
|
67 | + $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
68 | 68 | } |
69 | 69 | return $plugins; |
70 | 70 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | public function registerPointers() |
77 | 77 | { |
78 | 78 | $command = new RegisterPointers([[ |
79 | - 'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ), |
|
79 | + 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
80 | 80 | 'id' => 'glsr-pointer-pinned', |
81 | 81 | 'position' => [ |
82 | 82 | 'edge' => 'right', |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | ], |
85 | 85 | 'screen' => Application::POST_TYPE, |
86 | 86 | 'target' => '#misc-pub-pinned', |
87 | - 'title' => __( 'Pin Your Reviews', 'site-reviews' ), |
|
87 | + 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
88 | 88 | ]]); |
89 | - $this->execute( $command ); |
|
89 | + $this->execute($command); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -96,21 +96,21 @@ discard block |
||
96 | 96 | public function registerShortcodeButtons() |
97 | 97 | { |
98 | 98 | $command = new RegisterShortcodeButtons([ |
99 | - 'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ), |
|
100 | - 'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ), |
|
101 | - 'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ), |
|
99 | + 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
100 | + 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
101 | + 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
102 | 102 | ]); |
103 | - $this->execute( $command ); |
|
103 | + $this->execute($command); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @return void |
108 | 108 | * @action edit_form_after_title |
109 | 109 | */ |
110 | - public function renderReviewEditor( WP_Post $post ) |
|
110 | + public function renderReviewEditor(WP_Post $post) |
|
111 | 111 | { |
112 | - if( !$this->isReviewEditable( $post ) )return; |
|
113 | - glsr()->render( 'editor/review', [ |
|
112 | + if (!$this->isReviewEditable($post))return; |
|
113 | + glsr()->render('editor/review', [ |
|
114 | 114 | 'post' => $post, |
115 | 115 | ]); |
116 | 116 | } |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | * @return void |
120 | 120 | * @action edit_form_top |
121 | 121 | */ |
122 | - public function renderReviewNotice( WP_Post $post ) |
|
122 | + public function renderReviewNotice(WP_Post $post) |
|
123 | 123 | { |
124 | - if( !$this->isReviewEditable( $post ) )return; |
|
125 | - glsr( Notice::class )->addWarning( __( 'This review is read-only.', 'site-reviews' )); |
|
126 | - glsr()->render( 'editor/notice' ); |
|
124 | + if (!$this->isReviewEditable($post))return; |
|
125 | + glsr(Notice::class)->addWarning(__('This review is read-only.', 'site-reviews')); |
|
126 | + glsr()->render('editor/notice'); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function renderTinymceButton() |
134 | 134 | { |
135 | - if( glsr_current_screen()->base != 'post' )return; |
|
135 | + if (glsr_current_screen()->base != 'post')return; |
|
136 | 136 | $shortcodes = []; |
137 | - foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
|
138 | - if( !apply_filters( sanitize_title( $shortcode ).'_condition', true ))continue; |
|
137 | + foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
138 | + if (!apply_filters(sanitize_title($shortcode).'_condition', true))continue; |
|
139 | 139 | $shortcodes[$shortcode] = $values; |
140 | 140 | } |
141 | - if( empty( $shortcodes ))return; |
|
142 | - glsr()->render( 'editor/tinymce', [ |
|
141 | + if (empty($shortcodes))return; |
|
142 | + glsr()->render('editor/tinymce', [ |
|
143 | 143 | 'shortcodes' => $shortcodes, |
144 | 144 | ]); |
145 | 145 | } |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function routerClearLog() |
151 | 151 | { |
152 | - glsr( Logger::class )->clear(); |
|
153 | - glsr( Notice::class )->addSuccess( __( 'Log cleared.', 'site-reviews' )); |
|
152 | + glsr(Logger::class)->clear(); |
|
153 | + glsr(Notice::class)->addSuccess(__('Log cleared.', 'site-reviews')); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function routerDownloadLog() |
160 | 160 | { |
161 | - $this->download( Application::ID.'-log.txt', glsr( Logger::class )->get() ); |
|
161 | + $this->download(Application::ID.'-log.txt', glsr(Logger::class)->get()); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function routerDownloadSystemInfo() |
168 | 168 | { |
169 | - $this->download( Application::ID.'-system-info.txt', glsr( System::class )->get() ); |
|
169 | + $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * @return bool |
174 | 174 | */ |
175 | - protected function isReviewEditable( WP_Post $post ) |
|
175 | + protected function isReviewEditable(WP_Post $post) |
|
176 | 176 | { |
177 | 177 | return $post->post_type == Application::POST_TYPE |
178 | - && post_type_supports( Application::POST_TYPE, 'title' ) |
|
179 | - && get_post_meta( $post->ID, 'review_type', true ) == 'local'; |
|
178 | + && post_type_supports(Application::POST_TYPE, 'title') |
|
179 | + && get_post_meta($post->ID, 'review_type', true) == 'local'; |
|
180 | 180 | } |
181 | 181 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * @return string |
24 | 24 | * @filter script_loader_tag |
25 | 25 | */ |
26 | - public function filterEnqueuedScripts( $tag, $handle ) |
|
26 | + public function filterEnqueuedScripts($tag, $handle) |
|
27 | 27 | { |
28 | 28 | return $handle == Application::ID.'/google-recaptcha' |
29 | - && glsr_get_option( 'reviews-form.recaptcha.integration' ) == 'custom' |
|
30 | - ? str_replace( ' src=', ' async defer src=', $tag ) |
|
29 | + && glsr_get_option('reviews-form.recaptcha.integration') == 'custom' |
|
30 | + ? str_replace(' src=', ' async defer src=', $tag) |
|
31 | 31 | : $tag; |
32 | 32 | } |
33 | 33 | |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | * @filter query_vars |
39 | 39 | * @todo remove need for dirty hack |
40 | 40 | */ |
41 | - public function filterQueryVars( $vars ) |
|
41 | + public function filterQueryVars($vars) |
|
42 | 42 | { |
43 | 43 | $vars[] = Application::PAGED_QUERY_VAR; |
44 | 44 | // dirty hack to fix a form submission with a field that has "name" as name |
45 | - if( filter_input( INPUT_POST, 'action' ) == 'submit-review' |
|
46 | - && !is_null( filter_input( INPUT_POST, 'gotcha' ))) { |
|
47 | - $index = array_search( 'name', $vars, true ); |
|
48 | - if( false !== $index ) { |
|
49 | - unset( $vars[$index] ); |
|
45 | + if (filter_input(INPUT_POST, 'action') == 'submit-review' |
|
46 | + && !is_null(filter_input(INPUT_POST, 'gotcha'))) { |
|
47 | + $index = array_search('name', $vars, true); |
|
48 | + if (false !== $index) { |
|
49 | + unset($vars[$index]); |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | return $vars; |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * @return mixed |
57 | 57 | */ |
58 | - public function postSubmitReview( array $request ) |
|
58 | + public function postSubmitReview(array $request) |
|
59 | 59 | { |
60 | - $validated = glsr( ValidateReview::class )->validate( $request ); |
|
61 | - if( !empty( $validated->error )) { |
|
60 | + $validated = glsr(ValidateReview::class)->validate($request); |
|
61 | + if (!empty($validated->error)) { |
|
62 | 62 | return $validated->request; |
63 | 63 | } |
64 | - if( $validated->recaptchaIsUnset )return; |
|
65 | - return $this->execute( new SubmitReview( $validated->request )); |
|
64 | + if ($validated->recaptchaIsUnset)return; |
|
65 | + return $this->execute(new SubmitReview($validated->request)); |
|
66 | 66 | } |
67 | 67 | } |
@@ -19,17 +19,17 @@ discard block |
||
19 | 19 | public function registerMenuCount() |
20 | 20 | { |
21 | 21 | global $menu, $typenow; |
22 | - foreach( $menu as $key => $value ) { |
|
23 | - if( !isset( $value[2] ) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE )continue; |
|
24 | - $postCount = wp_count_posts( Application::POST_TYPE ); |
|
25 | - $pendingCount = glsr( Builder::class )->span( number_format_i18n( $postCount->pending ), [ |
|
22 | + foreach ($menu as $key => $value) { |
|
23 | + if (!isset($value[2]) || $value[2] != 'edit.php?post_type='.Application::POST_TYPE)continue; |
|
24 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
25 | + $pendingCount = glsr(Builder::class)->span(number_format_i18n($postCount->pending), [ |
|
26 | 26 | 'class' => 'pending-count', |
27 | 27 | ]); |
28 | - $awaitingModeration = glsr( Builder::class )->span( $pendingCount, [ |
|
28 | + $awaitingModeration = glsr(Builder::class)->span($pendingCount, [ |
|
29 | 29 | 'class' => 'awaiting-mod count-'.$postCount->pending, |
30 | 30 | ]); |
31 | 31 | $menu[$key][0] .= $awaitingModeration; |
32 | - if( $typenow === Application::POST_TYPE ) { |
|
32 | + if ($typenow === Application::POST_TYPE) { |
|
33 | 33 | $menu[$key][4] .= ' current'; |
34 | 34 | } |
35 | 35 | break; |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function registerSubMenus() |
44 | 44 | { |
45 | - $pages = apply_filters( 'site-reviews/addon/submenu/pages', [] ); |
|
46 | - $pages = wp_parse_args( $pages, [ |
|
47 | - 'settings' => __( 'Settings', 'site-reviews' ), |
|
48 | - 'tools' => __( 'Tools', 'site-reviews' ), |
|
49 | - 'documentation' => __( 'Documentation', 'site-reviews' ), |
|
50 | - 'addons' => __( 'Add-Ons', 'site-reviews' ), |
|
45 | + $pages = apply_filters('site-reviews/addon/submenu/pages', []); |
|
46 | + $pages = wp_parse_args($pages, [ |
|
47 | + 'settings' => __('Settings', 'site-reviews'), |
|
48 | + 'tools' => __('Tools', 'site-reviews'), |
|
49 | + 'documentation' => __('Documentation', 'site-reviews'), |
|
50 | + 'addons' => __('Add-Ons', 'site-reviews'), |
|
51 | 51 | ]); |
52 | - foreach( $pages as $slug => $title ) { |
|
53 | - $method = glsr( Helper::class )->buildMethodName( 'render-'.$slug.'-menu' ); |
|
54 | - $callback = apply_filters( 'site-reviews/addon/submenu/callback', [$this, $method], $slug ); |
|
55 | - if( !is_callable( $callback ))continue; |
|
56 | - add_submenu_page( 'edit.php?post_type='.Application::POST_TYPE, $title, $title, Application::CAPABILITY, $slug, $callback ); |
|
52 | + foreach ($pages as $slug => $title) { |
|
53 | + $method = glsr(Helper::class)->buildMethodName('render-'.$slug.'-menu'); |
|
54 | + $callback = apply_filters('site-reviews/addon/submenu/callback', [$this, $method], $slug); |
|
55 | + if (!is_callable($callback))continue; |
|
56 | + add_submenu_page('edit.php?post_type='.Application::POST_TYPE, $title, $title, Application::CAPABILITY, $slug, $callback); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | public function renderAddonsMenu() |
66 | 66 | { |
67 | 67 | $tabs = [ |
68 | - 'addons' => __( 'Add-Ons', 'site-reviews' ), |
|
68 | + 'addons' => __('Add-Ons', 'site-reviews'), |
|
69 | 69 | ]; |
70 | - $this->renderMenu( 'addons', $tabs ); |
|
70 | + $this->renderMenu('addons', $tabs); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -77,15 +77,15 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function renderDocumentationMenu() |
79 | 79 | { |
80 | - $tabs = apply_filters( 'site-reviews/addon/documentation/tabs', [] ); |
|
81 | - $tabs = wp_parse_args( $tabs, [ |
|
82 | - 'support' => __( 'Support', 'site-reviews' ), |
|
83 | - 'faq' => __( 'FAQ', 'site-reviews' ), |
|
84 | - 'shortcodes' => __( 'Shortcodes', 'site-reviews' ), |
|
85 | - 'hooks' => __( 'Hooks', 'site-reviews' ), |
|
86 | - 'functions' => __( 'Functions', 'site-reviews' ), |
|
80 | + $tabs = apply_filters('site-reviews/addon/documentation/tabs', []); |
|
81 | + $tabs = wp_parse_args($tabs, [ |
|
82 | + 'support' => __('Support', 'site-reviews'), |
|
83 | + 'faq' => __('FAQ', 'site-reviews'), |
|
84 | + 'shortcodes' => __('Shortcodes', 'site-reviews'), |
|
85 | + 'hooks' => __('Hooks', 'site-reviews'), |
|
86 | + 'functions' => __('Functions', 'site-reviews'), |
|
87 | 87 | ]); |
88 | - $this->renderMenu( 'documentation', $tabs ); |
|
88 | + $this->renderMenu('documentation', $tabs); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -95,16 +95,16 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function renderSettingsMenu() |
97 | 97 | { |
98 | - $tabs = apply_filters( 'site-reviews/addon/settings/tabs', [] ); |
|
99 | - $tabs = wp_parse_args( $tabs, [ |
|
100 | - 'general' => __( 'General', 'site-reviews' ), |
|
101 | - 'reviews' => __( 'Reviews', 'site-reviews' ), |
|
102 | - 'submissions' => __( 'Submissions', 'site-reviews' ), |
|
103 | - 'schema' => __( 'Schema', 'site-reviews' ), |
|
104 | - 'translations' => __( 'Translations', 'site-reviews' ), |
|
105 | - 'licenses' => __( 'Licenses', 'site-reviews' ), |
|
98 | + $tabs = apply_filters('site-reviews/addon/settings/tabs', []); |
|
99 | + $tabs = wp_parse_args($tabs, [ |
|
100 | + 'general' => __('General', 'site-reviews'), |
|
101 | + 'reviews' => __('Reviews', 'site-reviews'), |
|
102 | + 'submissions' => __('Submissions', 'site-reviews'), |
|
103 | + 'schema' => __('Schema', 'site-reviews'), |
|
104 | + 'translations' => __('Translations', 'site-reviews'), |
|
105 | + 'licenses' => __('Licenses', 'site-reviews'), |
|
106 | 106 | ]); |
107 | - $this->renderMenu( 'settings', $tabs, [ |
|
107 | + $this->renderMenu('settings', $tabs, [ |
|
108 | 108 | 'databaseKey' => OptionManager::databaseKey(), |
109 | 109 | 'settings' => glsr()->getDefaults(), |
110 | 110 | ]); |
@@ -117,17 +117,17 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function renderToolsMenu() |
119 | 119 | { |
120 | - $tabs = apply_filters( 'site-reviews/addon/tools/tabs', [] ); |
|
121 | - $tabs = wp_parse_args( $tabs, [ |
|
122 | - 'import-export' => __( 'Import/Export', 'site-reviews' ), |
|
123 | - 'logging' => __( 'Logging', 'site-reviews' ), |
|
124 | - 'system-info' => __( 'System Info', 'site-reviews' ), |
|
120 | + $tabs = apply_filters('site-reviews/addon/tools/tabs', []); |
|
121 | + $tabs = wp_parse_args($tabs, [ |
|
122 | + 'import-export' => __('Import/Export', 'site-reviews'), |
|
123 | + 'logging' => __('Logging', 'site-reviews'), |
|
124 | + 'system-info' => __('System Info', 'site-reviews'), |
|
125 | 125 | ]); |
126 | - $this->renderMenu( 'tools', $tabs, [ |
|
126 | + $this->renderMenu('tools', $tabs, [ |
|
127 | 127 | 'id' => Application::ID, |
128 | - 'logger' => glsr( Logger::class ), |
|
128 | + 'logger' => glsr(Logger::class), |
|
129 | 129 | 'prefix' => Application::PREFIX, |
130 | - 'system' => glsr( System::class ), |
|
130 | + 'system' => glsr(System::class), |
|
131 | 131 | ]); |
132 | 132 | } |
133 | 133 | |
@@ -137,8 +137,8 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function setCustomPermissions() |
139 | 139 | { |
140 | - foreach( wp_roles()->roles as $role => $value ) { |
|
141 | - wp_roles()->remove_cap( $role, 'create_'.Application::POST_TYPE ); |
|
140 | + foreach (wp_roles()->roles as $role => $value) { |
|
141 | + wp_roles()->remove_cap($role, 'create_'.Application::POST_TYPE); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | * @param string $tab |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - protected function getCurrentSection( array $tabs, $tab ) |
|
149 | + protected function getCurrentSection(array $tabs, $tab) |
|
150 | 150 | { |
151 | - $currentSection = filter_input( INPUT_GET, 'section' ); |
|
152 | - if( empty( $tabs[$tab]['sections'][$currentSection] )) { |
|
153 | - $currentSection = isset( $tabs[$tab]['sections'] ) |
|
154 | - ? key( $tabs[$tab]['sections'] ) |
|
151 | + $currentSection = filter_input(INPUT_GET, 'section'); |
|
152 | + if (empty($tabs[$tab]['sections'][$currentSection])) { |
|
153 | + $currentSection = isset($tabs[$tab]['sections']) |
|
154 | + ? key($tabs[$tab]['sections']) |
|
155 | 155 | : ''; |
156 | 156 | } |
157 | 157 | return $currentSection; |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | /** |
161 | 161 | * @return string |
162 | 162 | */ |
163 | - protected function getCurrentTab( array $tabs ) |
|
163 | + protected function getCurrentTab(array $tabs) |
|
164 | 164 | { |
165 | - $currentTab = filter_input( INPUT_GET, 'tab' ); |
|
166 | - if( !array_key_exists( $currentTab, $tabs )) { |
|
167 | - $currentTab = key( $tabs ); |
|
165 | + $currentTab = filter_input(INPUT_GET, 'tab'); |
|
166 | + if (!array_key_exists($currentTab, $tabs)) { |
|
167 | + $currentTab = key($tabs); |
|
168 | 168 | } |
169 | 169 | return $currentTab; |
170 | 170 | } |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | /** |
173 | 173 | * @return array |
174 | 174 | */ |
175 | - protected function normalizeTabs( array $tabs ) |
|
175 | + protected function normalizeTabs(array $tabs) |
|
176 | 176 | { |
177 | - foreach( $tabs as $key => $value ) { |
|
178 | - if( !is_array( $value )) { |
|
177 | + foreach ($tabs as $key => $value) { |
|
178 | + if (!is_array($value)) { |
|
179 | 179 | $value = ['title' => $value]; |
180 | 180 | } |
181 | - $tabs[$key] = wp_parse_args( $value, [ |
|
181 | + $tabs[$key] = wp_parse_args($value, [ |
|
182 | 182 | 'sections' => [], |
183 | 183 | 'title' => '', |
184 | 184 | ]); |
185 | - $useLicenses = apply_filters( 'site-reviews/addon/licenses', false ); |
|
186 | - if( !$useLicenses ) { |
|
187 | - unset( $tabs['licenses'] ); |
|
185 | + $useLicenses = apply_filters('site-reviews/addon/licenses', false); |
|
186 | + if (!$useLicenses) { |
|
187 | + unset($tabs['licenses']); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | return $tabs; |
@@ -194,18 +194,18 @@ discard block |
||
194 | 194 | * @param string $page |
195 | 195 | * @return void |
196 | 196 | */ |
197 | - protected function renderMenu( $page, array $tabs, array $data = [] ) |
|
197 | + protected function renderMenu($page, array $tabs, array $data = []) |
|
198 | 198 | { |
199 | - $tabs = $this->normalizeTabs( $tabs ); |
|
200 | - $tab = $this->getCurrentTab( $tabs ); |
|
201 | - $section = $this->getCurrentSection( $tabs, $tab ); |
|
199 | + $tabs = $this->normalizeTabs($tabs); |
|
200 | + $tab = $this->getCurrentTab($tabs); |
|
201 | + $section = $this->getCurrentSection($tabs, $tab); |
|
202 | 202 | $defaults = [ |
203 | 203 | 'currentSection' => $section, |
204 | 204 | 'currentTab' => $tab, |
205 | 205 | 'page' => $page, |
206 | 206 | 'tabs' => $tabs, |
207 | 207 | ]; |
208 | - $data = apply_filters( 'site-reviews/addon/page/data', $data, $defaults ); |
|
209 | - glsr()->render( 'pages/index', wp_parse_args( $data, $defaults )); |
|
208 | + $data = apply_filters('site-reviews/addon/page/data', $data, $defaults); |
|
209 | + glsr()->render('pages/index', wp_parse_args($data, $defaults)); |
|
210 | 210 | } |
211 | 211 | } |
@@ -13,24 +13,24 @@ discard block |
||
13 | 13 | * @return array |
14 | 14 | * @callback register_setting |
15 | 15 | */ |
16 | - public function callbackRegisterSettings( $input ) |
|
16 | + public function callbackRegisterSettings($input) |
|
17 | 17 | { |
18 | - if( !is_array( $input )) { |
|
18 | + if (!is_array($input)) { |
|
19 | 19 | $input = ['settings' => []]; |
20 | 20 | } |
21 | - $key = key( $input ); |
|
21 | + $key = key($input); |
|
22 | 22 | $message = ''; |
23 | - if( $key == 'logging' ) { |
|
24 | - $message = _n( 'Logging disabled.', 'Logging enabled.', (int)empty( $input[$key] ), 'site-reviews' ); |
|
25 | - glsr( Notice::class )->addSuccess( $message ); |
|
23 | + if ($key == 'logging') { |
|
24 | + $message = _n('Logging disabled.', 'Logging enabled.', (int)empty($input[$key]), 'site-reviews'); |
|
25 | + glsr(Notice::class)->addSuccess($message); |
|
26 | 26 | } |
27 | - if( $key == 'settings' ) { |
|
28 | - $message = __( 'Settings updated.', 'site-reviews' ); |
|
29 | - glsr( Notice::class )->addSuccess( $message ); |
|
27 | + if ($key == 'settings') { |
|
28 | + $message = __('Settings updated.', 'site-reviews'); |
|
29 | + glsr(Notice::class)->addSuccess($message); |
|
30 | 30 | } |
31 | - $options = array_replace_recursive( glsr_db()->getOptions(), $input ); |
|
32 | - $options = $this->sanitizeReviewsForm( $input, $options ); |
|
33 | - $options = $this->sanitizeStrings( $input, $options ); |
|
31 | + $options = array_replace_recursive(glsr_db()->getOptions(), $input); |
|
32 | + $options = $this->sanitizeReviewsForm($input, $options); |
|
33 | + $options = $this->sanitizeStrings($input, $options); |
|
34 | 34 | return $options; |
35 | 35 | } |
36 | 36 | |
@@ -40,25 +40,25 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function registerSettings() |
42 | 42 | { |
43 | - $settings = apply_filters( 'site-reviews/settings', ['logging', 'settings'] ); |
|
44 | - foreach( $settings as $setting ) { |
|
43 | + $settings = apply_filters('site-reviews/settings', ['logging', 'settings']); |
|
44 | + foreach ($settings as $setting) { |
|
45 | 45 | register_setting( |
46 | 46 | glsr()->id.'-'.$setting, |
47 | 47 | glsr_db()->getOptionName(), |
48 | 48 | [$this, 'callbackRegisterSettings'] |
49 | 49 | ); |
50 | 50 | } |
51 | - glsr( Settings::class )->register(); |
|
51 | + glsr(Settings::class)->register(); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - protected function sanitizeReviewsForm( array $input, array $options ) |
|
57 | + protected function sanitizeReviewsForm(array $input, array $options) |
|
58 | 58 | { |
59 | - if( isset( $input['settings']['reviews-form'] )) { |
|
59 | + if (isset($input['settings']['reviews-form'])) { |
|
60 | 60 | $inputForm = $input['settings']['reviews-form']; |
61 | - $options['settings']['reviews-form']['required'] = isset( $inputForm['required'] ) |
|
61 | + $options['settings']['reviews-form']['required'] = isset($inputForm['required']) |
|
62 | 62 | ? $inputForm['required'] |
63 | 63 | : []; |
64 | 64 | } |
@@ -68,16 +68,16 @@ discard block |
||
68 | 68 | /** |
69 | 69 | * @return array |
70 | 70 | */ |
71 | - protected function sanitizeStrings( array $input, array $options ) |
|
71 | + protected function sanitizeStrings(array $input, array $options) |
|
72 | 72 | { |
73 | - if( isset( $input['settings']['strings'] )) { |
|
74 | - $options['settings']['strings'] = array_values( array_filter( $input['settings']['strings'] )); |
|
75 | - array_walk( $options['settings']['strings'], function( &$string ) { |
|
76 | - if( isset( $string['s2'] )) { |
|
77 | - $string['s2'] = wp_strip_all_tags( $string['s2'] ); |
|
73 | + if (isset($input['settings']['strings'])) { |
|
74 | + $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
75 | + array_walk($options['settings']['strings'], function(&$string) { |
|
76 | + if (isset($string['s2'])) { |
|
77 | + $string['s2'] = wp_strip_all_tags($string['s2']); |
|
78 | 78 | } |
79 | - if( isset( $string['p2'] )) { |
|
80 | - $string['p2'] = wp_strip_all_tags( $string['p2'] ); |
|
79 | + if (isset($string['p2'])) { |
|
80 | + $string['p2'] = wp_strip_all_tags($string['p2']); |
|
81 | 81 | } |
82 | 82 | }); |
83 | 83 | } |
@@ -25,13 +25,13 @@ discard block |
||
25 | 25 | { |
26 | 26 | global $wp_scripts; |
27 | 27 | $strings = [ |
28 | - 'savePending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
29 | - 'published' => __( 'Approved', 'site-reviews' ), |
|
28 | + 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
29 | + 'published' => __('Approved', 'site-reviews'), |
|
30 | 30 | ]; |
31 | - if( $this->canModifyTranslation() && isset( $wp_scripts->registered['post']->extra['data'] )) { |
|
31 | + if ($this->canModifyTranslation() && isset($wp_scripts->registered['post']->extra['data'])) { |
|
32 | 32 | $l10n = &$wp_scripts->registered['post']->extra['data']; |
33 | - foreach( $strings as $search => $replace ) { |
|
34 | - $l10n = preg_replace( '/("'.$search.'":")([^"]+)/', "$1".$replace, $l10n ); |
|
33 | + foreach ($strings as $search => $replace) { |
|
34 | + $l10n = preg_replace('/("'.$search.'":")([^"]+)/', "$1".$replace, $l10n); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | } |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | * @return array |
41 | 41 | * @filter wp_editor_settings |
42 | 42 | */ |
43 | - public function filterEditorSettings( array $settings ) |
|
43 | + public function filterEditorSettings(array $settings) |
|
44 | 44 | { |
45 | - if( $this->isReviewEditable() ) { |
|
45 | + if ($this->isReviewEditable()) { |
|
46 | 46 | $settings = [ |
47 | 47 | 'media_buttons' => false, |
48 | 48 | 'quicktags' => false, |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | * @return string |
60 | 60 | * @filter the_editor |
61 | 61 | */ |
62 | - public function filterEditorTextarea( $html ) |
|
62 | + public function filterEditorTextarea($html) |
|
63 | 63 | { |
64 | - if( $this->isReviewEditable() ) { |
|
65 | - $html = str_replace( '<textarea', '<div id="ed_toolbar"></div><textarea', $html ); |
|
64 | + if ($this->isReviewEditable()) { |
|
65 | + $html = str_replace('<textarea', '<div id="ed_toolbar"></div><textarea', $html); |
|
66 | 66 | } |
67 | 67 | return $html; |
68 | 68 | } |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | * @return string |
75 | 75 | * @filter gettext |
76 | 76 | */ |
77 | - public function filterPostStatusLabels( $translation, $text, $domain ) |
|
77 | + public function filterPostStatusLabels($translation, $text, $domain) |
|
78 | 78 | { |
79 | - if( $this->canModifyTranslation( $domain )) { |
|
79 | + if ($this->canModifyTranslation($domain)) { |
|
80 | 80 | $replacements = [ |
81 | - 'Pending Review' => __( 'Unapproved', 'site-reviews' ), |
|
82 | - 'Pending' => __( 'Unapproved', 'site-reviews' ), |
|
83 | - 'Privately Published' => __( 'Privately Approved', 'site-reviews' ), |
|
84 | - 'Published' => __( 'Approved', 'site-reviews' ), |
|
85 | - 'Save as Pending' => __( 'Save as Unapproved', 'site-reviews' ), |
|
81 | + 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
82 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
83 | + 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
84 | + 'Published' => __('Approved', 'site-reviews'), |
|
85 | + 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
86 | 86 | ]; |
87 | - foreach( $replacements as $search => $replacement ) { |
|
88 | - if( $translation != $search )continue; |
|
87 | + foreach ($replacements as $search => $replacement) { |
|
88 | + if ($translation != $search)continue; |
|
89 | 89 | $translation = $replacement; |
90 | 90 | } |
91 | 91 | } |
@@ -99,33 +99,33 @@ discard block |
||
99 | 99 | * @return string |
100 | 100 | * @filter gettext_with_context |
101 | 101 | */ |
102 | - public function filterPostStatusLabelsWithContext( $translation, $text, $context, $domain ) |
|
102 | + public function filterPostStatusLabelsWithContext($translation, $text, $context, $domain) |
|
103 | 103 | { |
104 | - return $this->filterPostStatusLabels( $translation, $text, $domain ); |
|
104 | + return $this->filterPostStatusLabels($translation, $text, $domain); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @return array |
109 | 109 | * @filter post_updated_messages |
110 | 110 | */ |
111 | - public function filterUpdateMessages( array $messages ) |
|
111 | + public function filterUpdateMessages(array $messages) |
|
112 | 112 | { |
113 | 113 | $post = get_post(); |
114 | - if( !( $post instanceof WP_Post ))return; |
|
115 | - $strings = glsr( Strings::class )->post_updated_messages(); |
|
116 | - $restored = filter_input( INPUT_GET, 'revision' ); |
|
117 | - if( $revisionTitle = wp_post_revision_title( intval( $restored ), false )) { |
|
118 | - $restored = sprintf( $strings['restored'], $revisionTitle ); |
|
114 | + if (!($post instanceof WP_Post))return; |
|
115 | + $strings = glsr(Strings::class)->post_updated_messages(); |
|
116 | + $restored = filter_input(INPUT_GET, 'revision'); |
|
117 | + if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
118 | + $restored = sprintf($strings['restored'], $revisionTitle); |
|
119 | 119 | } |
120 | - $scheduled_date = date_i18n( 'M j, Y @ H:i', strtotime( $post->post_date )); |
|
121 | - $messages[ Application::POST_TYPE ] = [ |
|
120 | + $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
121 | + $messages[Application::POST_TYPE] = [ |
|
122 | 122 | 1 => $strings['updated'], |
123 | 123 | 4 => $strings['updated'], |
124 | 124 | 5 => $restored, |
125 | 125 | 6 => $strings['published'], |
126 | 126 | 7 => $strings['saved'], |
127 | 127 | 8 => $strings['submitted'], |
128 | - 9 => sprintf( $strings['scheduled'], '<strong>'.$scheduled_date.'</strong>' ), |
|
128 | + 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
129 | 129 | 10 => $strings['draft_updated'], |
130 | 130 | 50 => $strings['approved'], |
131 | 131 | 51 => $strings['unapproved'], |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * @param int $postId |
141 | 141 | * @return void |
142 | 142 | */ |
143 | - public function onCreateReview( $postData, $meta, $postId ) |
|
143 | + public function onCreateReview($postData, $meta, $postId) |
|
144 | 144 | { |
145 | - if( !$this->isReviewPostType( $review = get_post( $postId )))return; |
|
146 | - $this->updateAssignedToPost( $review ); |
|
145 | + if (!$this->isReviewPostType($review = get_post($postId)))return; |
|
146 | + $this->updateAssignedToPost($review); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | * @return void |
152 | 152 | * @action before_delete_post |
153 | 153 | */ |
154 | - public function onDeleteReview( $postId ) |
|
154 | + public function onDeleteReview($postId) |
|
155 | 155 | { |
156 | - if( !$this->isReviewPostType( $review = get_post( $postId )))return; |
|
156 | + if (!$this->isReviewPostType($review = get_post($postId)))return; |
|
157 | 157 | $review->post_status = 'deleted'; // important to change the post_status here first! |
158 | - $this->updateAssignedToPost( $review ); |
|
158 | + $this->updateAssignedToPost($review); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * @return void |
164 | 164 | * @action save_post_.static::POST_TYPE |
165 | 165 | */ |
166 | - public function onSaveReview( $postId, WP_Post $review ) |
|
166 | + public function onSaveReview($postId, WP_Post $review) |
|
167 | 167 | { |
168 | - $this->updateAssignedToPost( $review ); |
|
168 | + $this->updateAssignedToPost($review); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | * @return void |
174 | 174 | * @action add_meta_boxes |
175 | 175 | */ |
176 | - public function registerMetaBoxes( $postType ) |
|
176 | + public function registerMetaBoxes($postType) |
|
177 | 177 | { |
178 | - if( $postType != Application::POST_TYPE )return; |
|
179 | - add_meta_box( Application::ID.'_assigned_to', __( 'Assigned To', 'site-reviews' ), [$this, 'renderAssignedToMetabox'], null, 'side' ); |
|
180 | - add_meta_box( Application::ID.'_review', __( 'Details', 'site-reviews' ), [$this, 'renderDetailsMetaBox'], null, 'side' ); |
|
181 | - add_meta_box( Application::ID.'_response', __( 'Respond Publicly', 'site-reviews' ), [$this, 'renderResponseMetaBox'], null, 'normal' ); |
|
178 | + if ($postType != Application::POST_TYPE)return; |
|
179 | + add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side'); |
|
180 | + add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side'); |
|
181 | + add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal'); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function removeAutosave() |
189 | 189 | { |
190 | - if( $this->isReviewEditor() && !$this->isReviewEditable() ) { |
|
191 | - wp_deregister_script( 'autosave' ); |
|
190 | + if ($this->isReviewEditor() && !$this->isReviewEditable()) { |
|
191 | + wp_deregister_script('autosave'); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
@@ -198,30 +198,30 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function removeMetaBoxes() |
200 | 200 | { |
201 | - remove_meta_box( 'slugdiv', Application::POST_TYPE, 'advanced' ); |
|
201 | + remove_meta_box('slugdiv', Application::POST_TYPE, 'advanced'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
205 | 205 | * @return void |
206 | 206 | * @callback add_meta_box |
207 | 207 | */ |
208 | - public function renderAssignedToMetabox( WP_Post $post ) |
|
208 | + public function renderAssignedToMetabox(WP_Post $post) |
|
209 | 209 | { |
210 | - if( !$this->isReviewPostType( $post ))return; |
|
211 | - $assignedTo = get_post_meta( $post->ID, 'assigned_to', true ); |
|
210 | + if (!$this->isReviewPostType($post))return; |
|
211 | + $assignedTo = get_post_meta($post->ID, 'assigned_to', true); |
|
212 | 212 | $template = ''; |
213 | - if( $assignedPost = get_post( $assignedTo )) { |
|
213 | + if ($assignedPost = get_post($assignedTo)) { |
|
214 | 214 | ob_start(); |
215 | - glsr( Html::class )->renderTemplate( 'edit/assigned-post', [ |
|
215 | + glsr(Html::class)->renderTemplate('edit/assigned-post', [ |
|
216 | 216 | 'context' => [ |
217 | - 'url' => (string)get_permalink( $assignedPost ), |
|
218 | - 'title' => get_the_title( $assignedPost ), |
|
217 | + 'url' => (string)get_permalink($assignedPost), |
|
218 | + 'title' => get_the_title($assignedPost), |
|
219 | 219 | ], |
220 | 220 | ]); |
221 | 221 | $template = ob_get_clean(); |
222 | 222 | } |
223 | - wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false ); |
|
224 | - glsr()->render( 'edit/metabox-assigned-to', [ |
|
223 | + wp_nonce_field('assigned_to', '_nonce-assigned-to', false); |
|
224 | + glsr()->render('edit/metabox-assigned-to', [ |
|
225 | 225 | 'id' => $assignedTo, |
226 | 226 | 'template' => $template, |
227 | 227 | ]); |
@@ -231,13 +231,13 @@ discard block |
||
231 | 231 | * @return void |
232 | 232 | * @callback add_meta_box |
233 | 233 | */ |
234 | - public function renderDetailsMetaBox( WP_Post $post ) |
|
234 | + public function renderDetailsMetaBox(WP_Post $post) |
|
235 | 235 | { |
236 | - if( !$this->isReviewPostType( $post ))return; |
|
237 | - $review = glsr_db()->getReview( $post ); |
|
238 | - glsr()->render( 'edit/metabox-details', [ |
|
239 | - 'button' => $this->getMetaboxButton( $review, $post ), |
|
240 | - 'metabox' => $this->getMetaboxDetails( $review ), |
|
236 | + if (!$this->isReviewPostType($post))return; |
|
237 | + $review = glsr_db()->getReview($post); |
|
238 | + glsr()->render('edit/metabox-details', [ |
|
239 | + 'button' => $this->getMetaboxButton($review, $post), |
|
240 | + 'metabox' => $this->getMetaboxDetails($review), |
|
241 | 241 | ]); |
242 | 242 | } |
243 | 243 | |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public function renderMetaBoxPinned() |
249 | 249 | { |
250 | - if( !$this->isReviewPostType( get_post() ))return; |
|
251 | - $pinned = get_post_meta( get_the_ID(), 'pinned', true ); |
|
252 | - glsr()->render( 'edit/pinned', [ |
|
250 | + if (!$this->isReviewPostType(get_post()))return; |
|
251 | + $pinned = get_post_meta(get_the_ID(), 'pinned', true); |
|
252 | + glsr()->render('edit/pinned', [ |
|
253 | 253 | 'pinned' => $pinned, |
254 | 254 | ]); |
255 | 255 | } |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | * @return void |
259 | 259 | * @callback add_meta_box |
260 | 260 | */ |
261 | - public function renderResponseMetaBox( WP_Post $post ) |
|
261 | + public function renderResponseMetaBox(WP_Post $post) |
|
262 | 262 | { |
263 | - if( !$this->isReviewPostType( $post ))return; |
|
264 | - $review = glsr_db()->getReview( $post ); |
|
265 | - wp_nonce_field( 'response', '_nonce-response', false ); |
|
266 | - glsr()->render( 'edit/metabox-response', [ |
|
263 | + if (!$this->isReviewPostType($post))return; |
|
264 | + $review = glsr_db()->getReview($post); |
|
265 | + wp_nonce_field('response', '_nonce-response', false); |
|
266 | + glsr()->render('edit/metabox-response', [ |
|
267 | 267 | 'response' => $review->response, |
268 | 268 | ]); |
269 | 269 | } |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | * @see glsr_categories_meta_box() |
274 | 274 | * @callback register_taxonomy |
275 | 275 | */ |
276 | - public function renderTaxonomyMetabox( WP_Post $post ) |
|
276 | + public function renderTaxonomyMetabox(WP_Post $post) |
|
277 | 277 | { |
278 | - if( !$this->isReviewPostType( $post ))return; |
|
279 | - glsr()->render( 'edit/metabox-categories', [ |
|
278 | + if (!$this->isReviewPostType($post))return; |
|
279 | + glsr()->render('edit/metabox-categories', [ |
|
280 | 280 | 'post' => $post, |
281 | - 'tax_name' => esc_attr( Application::TAXONOMY ), |
|
282 | - 'taxonomy' => get_taxonomy( Application::TAXONOMY ), |
|
281 | + 'tax_name' => esc_attr(Application::TAXONOMY), |
|
282 | + 'taxonomy' => get_taxonomy(Application::TAXONOMY), |
|
283 | 283 | ]); |
284 | 284 | } |
285 | 285 | |
@@ -290,9 +290,9 @@ discard block |
||
290 | 290 | */ |
291 | 291 | public function revert() |
292 | 292 | { |
293 | - check_admin_referer( 'revert-review_'.( $postId = $this->getPostId() )); |
|
294 | - glsr_db()->revertReview( $postId ); |
|
295 | - $this->redirect( $postId, 52 ); |
|
293 | + check_admin_referer('revert-review_'.($postId = $this->getPostId())); |
|
294 | + glsr_db()->revertReview($postId); |
|
295 | + $this->redirect($postId, 52); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -300,20 +300,20 @@ discard block |
||
300 | 300 | * @return void |
301 | 301 | * @action save_post_.Application::POST_TYPE |
302 | 302 | */ |
303 | - public function saveMetaboxes( $postId ) |
|
303 | + public function saveMetaboxes($postId) |
|
304 | 304 | { |
305 | - $this->saveAssignedToMetabox( $postId ); |
|
306 | - $this->saveResponseMetabox( $postId ); |
|
305 | + $this->saveAssignedToMetabox($postId); |
|
306 | + $this->saveResponseMetabox($postId); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | 310 | * @param string $domain |
311 | 311 | * @return bool |
312 | 312 | */ |
313 | - protected function canModifyTranslation( $domain = 'default' ) |
|
313 | + protected function canModifyTranslation($domain = 'default') |
|
314 | 314 | { |
315 | 315 | return glsr_current_screen()->post_type == Application::POST_TYPE |
316 | - && in_array( glsr_current_screen()->base, ['edit', 'post'] ) |
|
316 | + && in_array(glsr_current_screen()->base, ['edit', 'post']) |
|
317 | 317 | && $domain == 'default'; |
318 | 318 | } |
319 | 319 | |
@@ -321,10 +321,10 @@ discard block |
||
321 | 321 | * @param int $postId |
322 | 322 | * @return int|false |
323 | 323 | */ |
324 | - protected function getAssignedToPostId( $postId ) |
|
324 | + protected function getAssignedToPostId($postId) |
|
325 | 325 | { |
326 | - $assignedTo = get_post_meta( $postId, 'assigned_to', true ); |
|
327 | - if(( $post = get_post( $assignedTo )) instanceof WP_Post ) { |
|
326 | + $assignedTo = get_post_meta($postId, 'assigned_to', true); |
|
327 | + if (($post = get_post($assignedTo)) instanceof WP_Post) { |
|
328 | 328 | return $post->ID; |
329 | 329 | } |
330 | 330 | return false; |
@@ -334,70 +334,70 @@ discard block |
||
334 | 334 | * @param object $review |
335 | 335 | * @return string |
336 | 336 | */ |
337 | - protected function getMetaboxButton( $review, WP_Post $post ) |
|
337 | + protected function getMetaboxButton($review, WP_Post $post) |
|
338 | 338 | { |
339 | 339 | $modified = false; |
340 | - if( $post->post_title !== $review->title |
|
340 | + if ($post->post_title !== $review->title |
|
341 | 341 | || $post->post_content !== $review->content |
342 | - || $post->post_date !== $review->date ) { |
|
342 | + || $post->post_date !== $review->date) { |
|
343 | 343 | $modified = true; |
344 | 344 | } |
345 | 345 | $revertUrl = wp_nonce_url( |
346 | - admin_url( 'post.php?post='.$post->ID.'&action=revert' ), |
|
346 | + admin_url('post.php?post='.$post->ID.'&action=revert'), |
|
347 | 347 | 'revert-review_'.$post->ID |
348 | 348 | ); |
349 | 349 | return !$modified |
350 | - ? sprintf( '<button id="revert" class="button button-large" disabled>%s</button>', __( 'Nothing to Revert', 'site-reviews' )) |
|
351 | - : sprintf( '<a href="%s" id="revert" class="button button-large">%s</a>', $revertUrl, __( 'Revert Changes', 'site-reviews' )); |
|
350 | + ? sprintf('<button id="revert" class="button button-large" disabled>%s</button>', __('Nothing to Revert', 'site-reviews')) |
|
351 | + : sprintf('<a href="%s" id="revert" class="button button-large">%s</a>', $revertUrl, __('Revert Changes', 'site-reviews')); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | 355 | * @param object $review |
356 | 356 | * @return array |
357 | 357 | */ |
358 | - protected function getMetaboxDetails( $review ) |
|
358 | + protected function getMetaboxDetails($review) |
|
359 | 359 | { |
360 | - $reviewer = empty( $review->user_id ) |
|
361 | - ? __( 'Unregistered user', 'site-reviews' ) |
|
362 | - : $this->generateLink( get_the_author_meta( 'display_name', $review->user_id ), [ |
|
363 | - 'href' => get_author_posts_url( $review->user_id ), |
|
360 | + $reviewer = empty($review->user_id) |
|
361 | + ? __('Unregistered user', 'site-reviews') |
|
362 | + : $this->generateLink(get_the_author_meta('display_name', $review->user_id), [ |
|
363 | + 'href' => get_author_posts_url($review->user_id), |
|
364 | 364 | ]); |
365 | - $email = empty( $review->email ) |
|
365 | + $email = empty($review->email) |
|
366 | 366 | ? '—' |
367 | - : $this->generateLink( $review->email, [ |
|
368 | - 'href' => 'mailto:'.$review->email.'?subject='.esc_attr( __( 'RE:', 'site-reviews' ).' '.$review->title ), |
|
367 | + : $this->generateLink($review->email, [ |
|
368 | + 'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title), |
|
369 | 369 | ]); |
370 | 370 | $metabox = [ |
371 | - __( 'Rating', 'site-reviews' ) => glsr( Html::class )->renderPartial( 'star-rating', ['rating' => $review->rating] ), |
|
372 | - __( 'Type', 'site-reviews' ) => $this->getReviewType( $review ), |
|
373 | - __( 'Date', 'site-reviews' ) => get_date_from_gmt( $review->date, 'F j, Y' ), |
|
374 | - __( 'Reviewer', 'site-reviews' ) => $reviewer, |
|
375 | - __( 'Name', 'site-reviews' ) => $review->author, |
|
376 | - __( 'Email', 'site-reviews' ) => $email, |
|
377 | - __( 'IP Address', 'site-reviews' ) => $review->ip_address, |
|
378 | - __( 'Avatar', 'site-reviews' ) => sprintf( '<img src="%s" width="96">', $review->avatar ), |
|
371 | + __('Rating', 'site-reviews') => glsr(Html::class)->renderPartial('star-rating', ['rating' => $review->rating]), |
|
372 | + __('Type', 'site-reviews') => $this->getReviewType($review), |
|
373 | + __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'), |
|
374 | + __('Reviewer', 'site-reviews') => $reviewer, |
|
375 | + __('Name', 'site-reviews') => $review->author, |
|
376 | + __('Email', 'site-reviews') => $email, |
|
377 | + __('IP Address', 'site-reviews') => $review->ip_address, |
|
378 | + __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar), |
|
379 | 379 | ]; |
380 | - return apply_filters( 'site-reviews/metabox/details', $metabox, $review ); |
|
380 | + return apply_filters('site-reviews/metabox/details', $metabox, $review); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | 384 | * @param object $review |
385 | 385 | * @return string |
386 | 386 | */ |
387 | - protected function getReviewType( $review ) |
|
387 | + protected function getReviewType($review) |
|
388 | 388 | { |
389 | 389 | $reviewType = $review->review_type; |
390 | - $reviewTypeFallback = !empty( $review->review_type ) |
|
391 | - ? ucfirst( $review->review_type ) |
|
392 | - : __( 'Unknown', 'site-reviews' ); |
|
393 | - if( !empty( $review->url )) { |
|
394 | - $reviewType = $this->generateLink( $reviewType, [ |
|
390 | + $reviewTypeFallback = !empty($review->review_type) |
|
391 | + ? ucfirst($review->review_type) |
|
392 | + : __('Unknown', 'site-reviews'); |
|
393 | + if (!empty($review->url)) { |
|
394 | + $reviewType = $this->generateLink($reviewType, [ |
|
395 | 395 | 'href' => $review->url, |
396 | 396 | 'target' => '_blank', |
397 | 397 | ]); |
398 | 398 | } |
399 | - return sprintf( __( '%s review', 'site-reviews' ), |
|
400 | - glsr( Strings::class )->review_types( $reviewType, $reviewTypeFallback ) |
|
399 | + return sprintf(__('%s review', 'site-reviews'), |
|
400 | + glsr(Strings::class)->review_types($reviewType, $reviewTypeFallback) |
|
401 | 401 | ); |
402 | 402 | } |
403 | 403 | |
@@ -406,9 +406,9 @@ discard block |
||
406 | 406 | */ |
407 | 407 | protected function isReviewEditable() |
408 | 408 | { |
409 | - $postId = intval( filter_input( INPUT_GET, 'post' )); |
|
409 | + $postId = intval(filter_input(INPUT_GET, 'post')); |
|
410 | 410 | return $postId > 0 |
411 | - && get_post_meta( $postId, 'review_type', true ) == 'local' |
|
411 | + && get_post_meta($postId, 'review_type', true) == 'local' |
|
412 | 412 | && $this->isReviewEditor(); |
413 | 413 | } |
414 | 414 | |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | * @param mixed $post |
427 | 427 | * @return bool |
428 | 428 | */ |
429 | - protected function isReviewPostType( $post ) |
|
429 | + protected function isReviewPostType($post) |
|
430 | 430 | { |
431 | 431 | return $post instanceof WP_Post && $post->post_type == Application::POST_TYPE; |
432 | 432 | } |
@@ -434,17 +434,17 @@ discard block |
||
434 | 434 | /** |
435 | 435 | * @return int |
436 | 436 | */ |
437 | - protected function recalculatePostAverage( array $reviews ) |
|
437 | + protected function recalculatePostAverage(array $reviews) |
|
438 | 438 | { |
439 | - return glsr( Rating::class )->getAverage( $reviews ); |
|
439 | + return glsr(Rating::class)->getAverage($reviews); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | /** |
443 | 443 | * @return int |
444 | 444 | */ |
445 | - protected function recalculatePostRanking( array $reviews ) |
|
445 | + protected function recalculatePostRanking(array $reviews) |
|
446 | 446 | { |
447 | - return glsr( Rating::class )->getRanking( $reviews ); |
|
447 | + return glsr(Rating::class)->getRanking($reviews); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -452,16 +452,16 @@ discard block |
||
452 | 452 | * @param int $messageIndex |
453 | 453 | * @return void |
454 | 454 | */ |
455 | - protected function redirect( $postId, $messageIndex ) |
|
455 | + protected function redirect($postId, $messageIndex) |
|
456 | 456 | { |
457 | 457 | $referer = wp_get_referer(); |
458 | 458 | $hasReferer = !$referer |
459 | - || strpos( $referer, 'post.php' ) !== false |
|
460 | - || strpos( $referer, 'post-new.php' ) !== false; |
|
459 | + || strpos($referer, 'post.php') !== false |
|
460 | + || strpos($referer, 'post-new.php') !== false; |
|
461 | 461 | $redirectUri = $hasReferer |
462 | - ? remove_query_arg( ['deleted', 'ids', 'trashed', 'untrashed'], $referer ) |
|
463 | - : get_edit_post_link( $postId, false ); |
|
464 | - wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri )); |
|
462 | + ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer) |
|
463 | + : get_edit_post_link($postId, false); |
|
464 | + wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri)); |
|
465 | 465 | exit; |
466 | 466 | } |
467 | 467 | |
@@ -469,27 +469,27 @@ discard block |
||
469 | 469 | * @param int $postId |
470 | 470 | * @return void |
471 | 471 | */ |
472 | - protected function saveAssignedToMetabox( $postId ) |
|
472 | + protected function saveAssignedToMetabox($postId) |
|
473 | 473 | { |
474 | - if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-assigned-to' ), 'assigned_to' ))return; |
|
475 | - $assignedTo = filter_input( INPUT_POST, 'assigned_to' ); |
|
474 | + if (!wp_verify_nonce(filter_input(INPUT_POST, '_nonce-assigned-to'), 'assigned_to'))return; |
|
475 | + $assignedTo = filter_input(INPUT_POST, 'assigned_to'); |
|
476 | 476 | $assignedTo || $assignedTo = ''; |
477 | - if( get_post_meta( $postId, 'assigned_to', true ) != $assignedTo ) { |
|
478 | - $this->onDeleteReview( $postId ); |
|
477 | + if (get_post_meta($postId, 'assigned_to', true) != $assignedTo) { |
|
478 | + $this->onDeleteReview($postId); |
|
479 | 479 | } |
480 | - update_post_meta( $postId, 'assigned_to', $assignedTo ); |
|
480 | + update_post_meta($postId, 'assigned_to', $assignedTo); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | /** |
484 | 484 | * @param int $postId |
485 | 485 | * @return mixed |
486 | 486 | */ |
487 | - protected function saveResponseMetabox( $postId ) |
|
487 | + protected function saveResponseMetabox($postId) |
|
488 | 488 | { |
489 | - if( !wp_verify_nonce( filter_input( INPUT_POST, '_nonce-response' ), 'response' ))return; |
|
490 | - $response = filter_input( INPUT_POST, 'response' ); |
|
489 | + if (!wp_verify_nonce(filter_input(INPUT_POST, '_nonce-response'), 'response'))return; |
|
490 | + $response = filter_input(INPUT_POST, 'response'); |
|
491 | 491 | $response || $response = ''; |
492 | - update_post_meta( $postId, 'response', trim( wp_kses( $response, [ |
|
492 | + update_post_meta($postId, 'response', trim(wp_kses($response, [ |
|
493 | 493 | 'a' => ['href' => [], 'title' => []], |
494 | 494 | 'em' => [], |
495 | 495 | 'strong' => [], |
@@ -499,23 +499,23 @@ discard block |
||
499 | 499 | /** |
500 | 500 | * @return void |
501 | 501 | */ |
502 | - protected function updateAssignedToPost( WP_Post $review ) |
|
502 | + protected function updateAssignedToPost(WP_Post $review) |
|
503 | 503 | { |
504 | - if( !( $postId = $this->getAssignedToPostId( $review->ID )))return; |
|
505 | - $reviewIds = get_post_meta( $postId, static::META_REVIEW_ID ); |
|
506 | - $updatedReviewIds = array_filter( (array)get_post_meta( $postId, static::META_REVIEW_ID )); |
|
507 | - $this->updateReviewIdOfPost( $postId, $review, $reviewIds ); |
|
508 | - if( empty( $updatedReviewIds )) { |
|
509 | - delete_post_meta( $postId, static::META_RANKING ); |
|
510 | - delete_post_meta( $postId, static::META_REVIEW_ID ); |
|
504 | + if (!($postId = $this->getAssignedToPostId($review->ID)))return; |
|
505 | + $reviewIds = get_post_meta($postId, static::META_REVIEW_ID); |
|
506 | + $updatedReviewIds = array_filter((array)get_post_meta($postId, static::META_REVIEW_ID)); |
|
507 | + $this->updateReviewIdOfPost($postId, $review, $reviewIds); |
|
508 | + if (empty($updatedReviewIds)) { |
|
509 | + delete_post_meta($postId, static::META_RANKING); |
|
510 | + delete_post_meta($postId, static::META_REVIEW_ID); |
|
511 | 511 | } |
512 | - else if( !glsr( Helper::class )->compareArrays( $reviewIds, $updatedReviewIds )) { |
|
512 | + else if (!glsr(Helper::class)->compareArrays($reviewIds, $updatedReviewIds)) { |
|
513 | 513 | $reviews = glsr_db()->getReviews([ |
514 | 514 | 'count' => -1, |
515 | 515 | 'post__in' => $updatedReviewIds, |
516 | 516 | ]); |
517 | - update_post_meta( $postId, static::META_AVERAGE, $this->recalculatePostAverage( $reviews->results )); |
|
518 | - update_post_meta( $postId, static::META_RANKING, $this->recalculatePostRanking( $reviews->results )); |
|
517 | + update_post_meta($postId, static::META_AVERAGE, $this->recalculatePostAverage($reviews->results)); |
|
518 | + update_post_meta($postId, static::META_RANKING, $this->recalculatePostRanking($reviews->results)); |
|
519 | 519 | } |
520 | 520 | } |
521 | 521 | |
@@ -523,13 +523,13 @@ discard block |
||
523 | 523 | * @param int $postId |
524 | 524 | * @return void |
525 | 525 | */ |
526 | - protected function updateReviewIdOfPost( $postId, WP_Post $review, array $reviewIds ) |
|
526 | + protected function updateReviewIdOfPost($postId, WP_Post $review, array $reviewIds) |
|
527 | 527 | { |
528 | - if( $review->post_status != 'publish' ) { |
|
529 | - delete_post_meta( $postId, static::META_REVIEW_ID, $review->ID ); |
|
528 | + if ($review->post_status != 'publish') { |
|
529 | + delete_post_meta($postId, static::META_REVIEW_ID, $review->ID); |
|
530 | 530 | } |
531 | - else if( !in_array( $review->ID, $reviewIds )) { |
|
532 | - add_post_meta( $postId, static::META_REVIEW_ID, $review->ID ); |
|
531 | + else if (!in_array($review->ID, $reviewIds)) { |
|
532 | + add_post_meta($postId, static::META_REVIEW_ID, $review->ID); |
|
533 | 533 | } |
534 | 534 | } |
535 | 535 | } |
@@ -12,13 +12,13 @@ discard block |
||
12 | 12 | * @param string $path |
13 | 13 | * @return string |
14 | 14 | */ |
15 | - public function buildClassName( $name, $path = '' ) |
|
15 | + public function buildClassName($name, $path = '') |
|
16 | 16 | { |
17 | - $className = array_map( 'strtolower', (array)preg_split( '/[-_]/', $name )); |
|
18 | - $className = array_map( 'ucfirst', $className ); |
|
19 | - $className = implode( '', $className ); |
|
20 | - $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' ); |
|
21 | - return !empty( $path ) |
|
17 | + $className = array_map('strtolower', (array)preg_split('/[-_]/', $name)); |
|
18 | + $className = array_map('ucfirst', $className); |
|
19 | + $className = implode('', $className); |
|
20 | + $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
21 | + return !empty($path) |
|
22 | 22 | ? __NAMESPACE__.'\\'.$path.'\\'.$className |
23 | 23 | : $className; |
24 | 24 | } |
@@ -28,38 +28,38 @@ discard block |
||
28 | 28 | * @param string $prefix |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function buildMethodName( $name, $prefix = '' ) |
|
31 | + public function buildMethodName($name, $prefix = '') |
|
32 | 32 | { |
33 | - return lcfirst( $prefix.$this->buildClassName( $name )); |
|
33 | + return lcfirst($prefix.$this->buildClassName($name)); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @param string $name |
38 | 38 | * @return string |
39 | 39 | */ |
40 | - public function buildPropertyName( $name ) |
|
40 | + public function buildPropertyName($name) |
|
41 | 41 | { |
42 | - return lcfirst( $this->buildClassName( $name )); |
|
42 | + return lcfirst($this->buildClassName($name)); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public function compareArrays( array $arr1, array $arr2 ) |
|
48 | + public function compareArrays(array $arr1, array $arr2) |
|
49 | 49 | { |
50 | - sort( $arr1 ); |
|
51 | - sort( $arr2 ); |
|
50 | + sort($arr1); |
|
51 | + sort($arr2); |
|
52 | 52 | return $arr1 == $arr2; |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @return array |
57 | 57 | */ |
58 | - public function convertDotNotationArray( array $array ) |
|
58 | + public function convertDotNotationArray(array $array) |
|
59 | 59 | { |
60 | 60 | $results = []; |
61 | - foreach( $array as $path => $value ) { |
|
62 | - $results = $this->setPathValue( $path, $value, $results ); |
|
61 | + foreach ($array as $path => $value) { |
|
62 | + $results = $this->setPathValue($path, $value, $results); |
|
63 | 63 | } |
64 | 64 | return $results; |
65 | 65 | } |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * @param string $string |
69 | 69 | * @return string |
70 | 70 | */ |
71 | - public function dashCase( $string ) |
|
71 | + public function dashCase($string) |
|
72 | 72 | { |
73 | - return str_replace( '_', '-', $this->snakeCase( $string )); |
|
73 | + return str_replace('_', '-', $this->snakeCase($string)); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -78,11 +78,11 @@ discard block |
||
78 | 78 | * @param string $haystack |
79 | 79 | * @return bool |
80 | 80 | */ |
81 | - public function endsWith( $needle, $haystack ) |
|
81 | + public function endsWith($needle, $haystack) |
|
82 | 82 | { |
83 | - $length = strlen( $needle ); |
|
83 | + $length = strlen($needle); |
|
84 | 84 | return $length != 0 |
85 | - ? substr( $haystack, -$length ) === $needle |
|
85 | + ? substr($haystack, -$length) === $needle |
|
86 | 86 | : true; |
87 | 87 | } |
88 | 88 | |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | * @param string $prefix |
91 | 91 | * @return array |
92 | 92 | */ |
93 | - public function flattenArray( array $array, $prefix = '' ) |
|
93 | + public function flattenArray(array $array, $prefix = '') |
|
94 | 94 | { |
95 | 95 | $result = []; |
96 | - foreach( $array as $key => $value ) { |
|
97 | - $newKey = $prefix.( empty( $prefix ) ? '' : '.' ).$key; |
|
98 | - if( $this->isIndexedArray( $value )) { |
|
99 | - $value = '['.implode( ', ', $value ).']'; |
|
96 | + foreach ($array as $key => $value) { |
|
97 | + $newKey = $prefix.(empty($prefix) ? '' : '.').$key; |
|
98 | + if ($this->isIndexedArray($value)) { |
|
99 | + $value = '['.implode(', ', $value).']'; |
|
100 | 100 | } |
101 | - if( is_array( $value )) { |
|
102 | - $result = array_merge( $result, $this->flattenArray( $value, $newKey )); |
|
101 | + if (is_array($value)) { |
|
102 | + $result = array_merge($result, $this->flattenArray($value, $newKey)); |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | $result[$newKey] = $value; |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function getIpAddress() |
114 | 114 | { |
115 | - $cloudflareIps = glsr( Cache::class )->getCloudflareIps(); |
|
116 | - return (string)(new Whip( Whip::CLOUDFLARE_HEADERS | Whip::REMOTE_ADDR, [ |
|
115 | + $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
116 | + return (string)(new Whip(Whip::CLOUDFLARE_HEADERS | Whip::REMOTE_ADDR, [ |
|
117 | 117 | Whip::CLOUDFLARE_HEADERS => [ |
118 | 118 | Whip::IPV4 => $cloudflareIps['v4'], |
119 | 119 | Whip::IPV6 => $cloudflareIps['v6'], |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | * @param mixed $fallback |
128 | 128 | * @return void|mixed |
129 | 129 | */ |
130 | - public function getPathValue( $path = '', $fallback, array $values ) |
|
130 | + public function getPathValue($path = '', $fallback, array $values) |
|
131 | 131 | { |
132 | - $keys = explode( '.', $path ); |
|
133 | - foreach( $keys as $key ) { |
|
134 | - if( !isset( $values[$key] )) { |
|
132 | + $keys = explode('.', $path); |
|
133 | + foreach ($keys as $key) { |
|
134 | + if (!isset($values[$key])) { |
|
135 | 135 | return $fallback; |
136 | 136 | } |
137 | 137 | $values = $values[$key]; |
@@ -143,14 +143,14 @@ discard block |
||
143 | 143 | * @param mixed $array |
144 | 144 | * @return bool |
145 | 145 | */ |
146 | - public function isIndexedArray( $array ) |
|
146 | + public function isIndexedArray($array) |
|
147 | 147 | { |
148 | - if( !is_array( $array ) || array_filter( $array, 'is_array' )) { |
|
148 | + if (!is_array($array) || array_filter($array, 'is_array')) { |
|
149 | 149 | return false; |
150 | 150 | } |
151 | 151 | $current = 0; |
152 | - foreach( array_keys( $array ) as $key ) { |
|
153 | - if( $key !== $current ) { |
|
152 | + foreach (array_keys($array) as $key) { |
|
153 | + if ($key !== $current) { |
|
154 | 154 | return false; |
155 | 155 | } |
156 | 156 | $current++; |
@@ -162,13 +162,13 @@ discard block |
||
162 | 162 | * Remove empty values from an array |
163 | 163 | * @return array |
164 | 164 | */ |
165 | - public function removeEmptyArrayValues( array $array ) |
|
165 | + public function removeEmptyArrayValues(array $array) |
|
166 | 166 | { |
167 | 167 | $result = []; |
168 | - foreach( $array as $key => $value ) { |
|
169 | - if( !$value )continue; |
|
170 | - $result[$key] = is_array( $value ) |
|
171 | - ? $this->removeEmptyArrayValues( $value ) |
|
168 | + foreach ($array as $key => $value) { |
|
169 | + if (!$value)continue; |
|
170 | + $result[$key] = is_array($value) |
|
171 | + ? $this->removeEmptyArrayValues($value) |
|
172 | 172 | : $value; |
173 | 173 | } |
174 | 174 | return $result; |
@@ -180,16 +180,16 @@ discard block |
||
180 | 180 | * @param mixed $value |
181 | 181 | * @return array |
182 | 182 | */ |
183 | - public function setPathValue( $path, $value, array $values ) |
|
183 | + public function setPathValue($path, $value, array $values) |
|
184 | 184 | { |
185 | - $token = strtok( $path, '.' ); |
|
185 | + $token = strtok($path, '.'); |
|
186 | 186 | $ref = &$values; |
187 | - while( $token !== false ) { |
|
188 | - $ref = is_array( $ref ) |
|
187 | + while ($token !== false) { |
|
188 | + $ref = is_array($ref) |
|
189 | 189 | ? $ref |
190 | 190 | : []; |
191 | 191 | $ref = &$ref[$token]; |
192 | - $token = strtok( '.' ); |
|
192 | + $token = strtok('.'); |
|
193 | 193 | } |
194 | 194 | $ref = $value; |
195 | 195 | return $values; |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | * @param string $string |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function snakeCase( $string ) |
|
202 | + public function snakeCase($string) |
|
203 | 203 | { |
204 | - if( !ctype_lower( $string )) { |
|
205 | - $string = preg_replace( '/\s+/u', '', $string ); |
|
206 | - $string = preg_replace( '/(.)(?=[A-Z])/u', '$1_', $string ); |
|
207 | - $string = mb_strtolower( $string, 'UTF-8' ); |
|
204 | + if (!ctype_lower($string)) { |
|
205 | + $string = preg_replace('/\s+/u', '', $string); |
|
206 | + $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string); |
|
207 | + $string = mb_strtolower($string, 'UTF-8'); |
|
208 | 208 | } |
209 | - return str_replace( '-', '_', $string ); |
|
209 | + return str_replace('-', '_', $string); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | * @param string $haystack |
215 | 215 | * @return bool |
216 | 216 | */ |
217 | - public function startsWith( $needle, $haystack ) |
|
217 | + public function startsWith($needle, $haystack) |
|
218 | 218 | { |
219 | - return substr( $haystack, 0, strlen( $needle )) === $needle; |
|
219 | + return substr($haystack, 0, strlen($needle)) === $needle; |
|
220 | 220 | } |
221 | 221 | } |