@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function get() |
| 110 | 110 | { |
| 111 | - return empty( $this->log ) |
|
| 111 | + return empty($this->log) |
|
| 112 | 112 | ? __( 'Console is empty', 'site-reviews' ) |
| 113 | 113 | : $this->log; |
| 114 | 114 | } |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | public function humanSize( $valueIfEmpty = null ) |
| 121 | 121 | { |
| 122 | 122 | $bytes = $this->size(); |
| 123 | - if( empty( $bytes ) && is_string( $valueIfEmpty )) { |
|
| 123 | + if( empty($bytes) && is_string( $valueIfEmpty ) ) { |
|
| 124 | 124 | return $valueIfEmpty; |
| 125 | 125 | } |
| 126 | - $exponent = floor( log( max( $bytes, 1 ), 1024 )); |
|
| 127 | - return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes','KB','MB','GB'][$exponent]; |
|
| 126 | + $exponent = floor( log( max( $bytes, 1 ), 1024 ) ); |
|
| 127 | + return round( $bytes / pow( 1024, $exponent ), 2 ).' '.['bytes', 'KB', 'MB', 'GB'][$exponent]; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -147,9 +147,9 @@ discard block |
||
| 147 | 147 | public function log( $level, $message, array $context = [] ) |
| 148 | 148 | { |
| 149 | 149 | $constants = (new ReflectionClass( __CLASS__ ))->getConstants(); |
| 150 | - if( in_array( $level, $constants, true )) { |
|
| 150 | + if( in_array( $level, $constants, true ) ) { |
|
| 151 | 151 | $entry = $this->buildLogEntry( $level, $message, $context ); |
| 152 | - file_put_contents( $this->file, $entry, FILE_APPEND|LOCK_EX ); |
|
| 152 | + file_put_contents( $this->file, $entry, FILE_APPEND | LOCK_EX ); |
|
| 153 | 153 | $this->reset(); |
| 154 | 154 | } |
| 155 | 155 | return $this; |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | protected function interpolate( $message, $context = [] ) |
| 224 | 224 | { |
| 225 | - if( $this->isObjectOrArray( $message ) || !is_array( $context )) { |
|
| 225 | + if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) { |
|
| 226 | 226 | return print_r( $message, true ); |
| 227 | 227 | } |
| 228 | 228 | $replace = []; |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | if( $value instanceof DateTime ) { |
| 251 | 251 | $value = $value->format( 'Y-m-d H:i:s' ); |
| 252 | 252 | } |
| 253 | - else if( $this->isObjectOrArray( $value )) { |
|
| 253 | + else if( $this->isObjectOrArray( $value ) ) { |
|
| 254 | 254 | $value = json_encode( $value ); |
| 255 | 255 | } |
| 256 | 256 | return (string)$value; |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | $this->clear(); |
| 266 | 266 | file_put_contents( |
| 267 | 267 | $this->file, |
| 268 | - $this->buildLogEntry( 'info', __( 'Console was automatically cleared (128 KB maximum size)', 'site-reviews' )) |
|
| 268 | + $this->buildLogEntry( 'info', __( 'Console was automatically cleared (128 KB maximum size)', 'site-reviews' ) ) |
|
| 269 | 269 | ); |
| 270 | 270 | } |
| 271 | 271 | } |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | public function renderAssignedToMetabox( WP_Post $post ) |
| 121 | 121 | { |
| 122 | - if( !$this->isReviewPostType( $post ))return; |
|
| 122 | + if( !$this->isReviewPostType( $post ) )return; |
|
| 123 | 123 | $assignedTo = (string)get_post_meta( $post->ID, 'assigned_to', true ); |
| 124 | 124 | wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false ); |
| 125 | 125 | glsr()->render( 'partials/editor/metabox-assigned-to', [ |
| 126 | 126 | 'id' => $assignedTo, |
| 127 | 127 | 'template' => $this->buildAssignedToTemplate( $assignedTo, $post ), |
| 128 | - ]); |
|
| 128 | + ] ); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -134,12 +134,12 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | public function renderDetailsMetaBox( WP_Post $post ) |
| 136 | 136 | { |
| 137 | - if( !$this->isReviewPostType( $post ))return; |
|
| 137 | + if( !$this->isReviewPostType( $post ) )return; |
|
| 138 | 138 | $review = glsr( ReviewManager::class )->single( $post ); |
| 139 | 139 | glsr()->render( 'partials/editor/metabox-details', [ |
| 140 | 140 | 'button' => $this->buildDetailsMetaBoxRevertButton( $review, $post ), |
| 141 | 141 | 'metabox' => $this->normalizeDetailsMetaBox( $review ), |
| 142 | - ]); |
|
| 142 | + ] ); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -148,14 +148,14 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function renderPinnedInPublishMetaBox() |
| 150 | 150 | { |
| 151 | - if( !$this->isReviewPostType( get_post() ))return; |
|
| 151 | + if( !$this->isReviewPostType( get_post() ) )return; |
|
| 152 | 152 | glsr( Template::class )->render( 'partials/editor/pinned', [ |
| 153 | 153 | 'context' => [ |
| 154 | 154 | 'no' => __( 'No', 'site-reviews' ), |
| 155 | 155 | 'yes' => __( 'Yes', 'site-reviews' ), |
| 156 | 156 | ], |
| 157 | - 'pinned' => wp_validate_boolean( get_post_meta( intval( get_the_ID() ), 'pinned', true )), |
|
| 158 | - ]); |
|
| 157 | + 'pinned' => wp_validate_boolean( get_post_meta( intval( get_the_ID() ), 'pinned', true ) ), |
|
| 158 | + ] ); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -164,11 +164,11 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | public function renderResponseMetaBox( WP_Post $post ) |
| 166 | 166 | { |
| 167 | - if( !$this->isReviewPostType( $post ))return; |
|
| 167 | + if( !$this->isReviewPostType( $post ) )return; |
|
| 168 | 168 | wp_nonce_field( 'response', '_nonce-response', false ); |
| 169 | 169 | glsr()->render( 'partials/editor/metabox-response', [ |
| 170 | 170 | 'response' => get_post_meta( $post->ID, 'response', true ), |
| 171 | - ]); |
|
| 171 | + ] ); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function renderTaxonomyMetabox( WP_Post $post ) |
| 180 | 180 | { |
| 181 | - if( !$this->isReviewPostType( $post ))return; |
|
| 181 | + if( !$this->isReviewPostType( $post ) )return; |
|
| 182 | 182 | glsr()->render( 'partials/editor/metabox-categories', [ |
| 183 | 183 | 'post' => $post, |
| 184 | 184 | 'tax_name' => Application::TAXONOMY, |
| 185 | 185 | 'taxonomy' => get_taxonomy( Application::TAXONOMY ), |
| 186 | - ]); |
|
| 186 | + ] ); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | public function revertReview() |
| 195 | 195 | { |
| 196 | - check_admin_referer( 'revert-review_'.( $postId = $this->getPostId() )); |
|
| 196 | + check_admin_referer( 'revert-review_'.($postId = $this->getPostId()) ); |
|
| 197 | 197 | glsr( ReviewManager::class )->revert( $postId ); |
| 198 | 198 | $this->redirect( $postId, 52 ); |
| 199 | 199 | } |
@@ -216,13 +216,13 @@ discard block |
||
| 216 | 216 | protected function buildAssignedToTemplate( $assignedTo, WP_Post $post ) |
| 217 | 217 | { |
| 218 | 218 | $assignedPost = glsr( Database::class )->getAssignedToPost( $post->ID, $assignedTo ); |
| 219 | - if( !( $assignedPost instanceof WP_Post ))return; |
|
| 219 | + if( !($assignedPost instanceof WP_Post) )return; |
|
| 220 | 220 | return glsr( Template::class )->build( 'partials/editor/assigned-post', [ |
| 221 | 221 | 'context' => [ |
| 222 | 222 | 'data.url' => (string)get_permalink( $assignedPost ), |
| 223 | 223 | 'data.title' => get_the_title( $assignedPost ), |
| 224 | 224 | ], |
| 225 | - ]); |
|
| 225 | + ] ); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -242,13 +242,13 @@ discard block |
||
| 242 | 242 | 'class' => 'button button-large', |
| 243 | 243 | 'href' => $revertUrl, |
| 244 | 244 | 'id' => 'revert', |
| 245 | - ]); |
|
| 245 | + ] ); |
|
| 246 | 246 | } |
| 247 | 247 | return glsr( Builder::class )->button( __( 'Nothing to Revert', 'site-reviews' ), [ |
| 248 | 248 | 'class' => 'button button-large', |
| 249 | 249 | 'disabled' => true, |
| 250 | 250 | 'id' => 'revert', |
| 251 | - ]); |
|
| 251 | + ] ); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -261,11 +261,11 @@ discard block |
||
| 261 | 261 | $reviewType = array_key_exists( $review->review_type, glsr()->reviewTypes ) |
| 262 | 262 | ? glsr()->reviewTypes[$review->review_type] |
| 263 | 263 | : __( 'Unknown', 'site-reviews' ); |
| 264 | - if( !empty( $review->url )) { |
|
| 264 | + if( !empty($review->url) ) { |
|
| 265 | 265 | $reviewType = glsr( Builder::class )->a( $reviewType, [ |
| 266 | 266 | 'href' => $review->url, |
| 267 | 267 | 'target' => '_blank', |
| 268 | - ]); |
|
| 268 | + ] ); |
|
| 269 | 269 | } |
| 270 | 270 | return $reviewType; |
| 271 | 271 | } |
@@ -284,16 +284,16 @@ discard block |
||
| 284 | 284 | */ |
| 285 | 285 | protected function normalizeDetailsMetaBox( Review $review ) |
| 286 | 286 | { |
| 287 | - $user = empty( $review->user_id ) |
|
| 287 | + $user = empty($review->user_id) |
|
| 288 | 288 | ? __( 'Unregistered user', 'site-reviews' ) |
| 289 | 289 | : glsr( Builder::class )->a( get_the_author_meta( 'display_name', $review->user_id ), [ |
| 290 | 290 | 'href' => get_author_posts_url( $review->user_id ), |
| 291 | - ]); |
|
| 292 | - $email = empty( $review->email ) |
|
| 291 | + ] ); |
|
| 292 | + $email = empty($review->email) |
|
| 293 | 293 | ? '—' |
| 294 | 294 | : glsr( Builder::class )->a( $review->email, [ |
| 295 | 295 | 'href' => 'mailto:'.$review->email.'?subject='.esc_attr( __( 'RE:', 'site-reviews' ).' '.$review->title ), |
| 296 | - ]); |
|
| 296 | + ] ); |
|
| 297 | 297 | $metabox = [ |
| 298 | 298 | __( 'Rating', 'site-reviews' ) => glsr( Partial::class )->build( 'star-rating', ['rating' => $review->rating] ), |
| 299 | 299 | __( 'Type', 'site-reviews' ) => $this->getReviewType( $review ), |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | __( 'IP Address', 'site-reviews' ) => $review->ip_address, |
| 305 | 305 | __( 'Avatar', 'site-reviews' ) => sprintf( '<img src="%s" width="96">', $review->avatar ), |
| 306 | 306 | ]; |
| 307 | - return array_filter( apply_filters( 'site-reviews/metabox/details', $metabox, $review )); |
|
| 307 | + return array_filter( apply_filters( 'site-reviews/metabox/details', $metabox, $review ) ); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $redirectUri = $hasReferer |
| 322 | 322 | ? remove_query_arg( ['deleted', 'ids', 'trashed', 'untrashed'], $referer ) |
| 323 | 323 | : get_edit_post_link( $postId ); |
| 324 | - wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri )); |
|
| 324 | + wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri ) ); |
|
| 325 | 325 | exit; |
| 326 | 326 | } |
| 327 | 327 | } |
@@ -89,7 +89,9 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function registerMetaBoxes( $postType ) |
| 91 | 91 | { |
| 92 | - if( $postType != Application::POST_TYPE )return; |
|
| 92 | + if( $postType != Application::POST_TYPE ) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 93 | 95 | add_meta_box( Application::ID.'_assigned_to', __( 'Assigned To', 'site-reviews' ), [$this, 'renderAssignedToMetabox'], null, 'side' ); |
| 94 | 96 | add_meta_box( Application::ID.'_review', __( 'Details', 'site-reviews' ), [$this, 'renderDetailsMetaBox'], null, 'side' ); |
| 95 | 97 | add_meta_box( Application::ID.'_response', __( 'Respond Publicly', 'site-reviews' ), [$this, 'renderResponseMetaBox'], null, 'normal' ); |
@@ -119,7 +121,9 @@ discard block |
||
| 119 | 121 | */ |
| 120 | 122 | public function renderAssignedToMetabox( WP_Post $post ) |
| 121 | 123 | { |
| 122 | - if( !$this->isReviewPostType( $post ))return; |
|
| 124 | + if( !$this->isReviewPostType( $post )) { |
|
| 125 | + return; |
|
| 126 | + } |
|
| 123 | 127 | $assignedTo = (string)get_post_meta( $post->ID, 'assigned_to', true ); |
| 124 | 128 | wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false ); |
| 125 | 129 | glsr()->render( 'partials/editor/metabox-assigned-to', [ |
@@ -134,7 +138,9 @@ discard block |
||
| 134 | 138 | */ |
| 135 | 139 | public function renderDetailsMetaBox( WP_Post $post ) |
| 136 | 140 | { |
| 137 | - if( !$this->isReviewPostType( $post ))return; |
|
| 141 | + if( !$this->isReviewPostType( $post )) { |
|
| 142 | + return; |
|
| 143 | + } |
|
| 138 | 144 | $review = glsr( ReviewManager::class )->single( $post ); |
| 139 | 145 | glsr()->render( 'partials/editor/metabox-details', [ |
| 140 | 146 | 'button' => $this->buildDetailsMetaBoxRevertButton( $review, $post ), |
@@ -148,7 +154,9 @@ discard block |
||
| 148 | 154 | */ |
| 149 | 155 | public function renderPinnedInPublishMetaBox() |
| 150 | 156 | { |
| 151 | - if( !$this->isReviewPostType( get_post() ))return; |
|
| 157 | + if( !$this->isReviewPostType( get_post() )) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 152 | 160 | glsr( Template::class )->render( 'partials/editor/pinned', [ |
| 153 | 161 | 'context' => [ |
| 154 | 162 | 'no' => __( 'No', 'site-reviews' ), |
@@ -164,7 +172,9 @@ discard block |
||
| 164 | 172 | */ |
| 165 | 173 | public function renderResponseMetaBox( WP_Post $post ) |
| 166 | 174 | { |
| 167 | - if( !$this->isReviewPostType( $post ))return; |
|
| 175 | + if( !$this->isReviewPostType( $post )) { |
|
| 176 | + return; |
|
| 177 | + } |
|
| 168 | 178 | wp_nonce_field( 'response', '_nonce-response', false ); |
| 169 | 179 | glsr()->render( 'partials/editor/metabox-response', [ |
| 170 | 180 | 'response' => get_post_meta( $post->ID, 'response', true ), |
@@ -178,7 +188,9 @@ discard block |
||
| 178 | 188 | */ |
| 179 | 189 | public function renderTaxonomyMetabox( WP_Post $post ) |
| 180 | 190 | { |
| 181 | - if( !$this->isReviewPostType( $post ))return; |
|
| 191 | + if( !$this->isReviewPostType( $post )) { |
|
| 192 | + return; |
|
| 193 | + } |
|
| 182 | 194 | glsr()->render( 'partials/editor/metabox-categories', [ |
| 183 | 195 | 'post' => $post, |
| 184 | 196 | 'tax_name' => Application::TAXONOMY, |
@@ -216,7 +228,9 @@ discard block |
||
| 216 | 228 | protected function buildAssignedToTemplate( $assignedTo, WP_Post $post ) |
| 217 | 229 | { |
| 218 | 230 | $assignedPost = glsr( Database::class )->getAssignedToPost( $post->ID, $assignedTo ); |
| 219 | - if( !( $assignedPost instanceof WP_Post ))return; |
|
| 231 | + if( !( $assignedPost instanceof WP_Post )) { |
|
| 232 | + return; |
|
| 233 | + } |
|
| 220 | 234 | return glsr( Template::class )->build( 'partials/editor/assigned-post', [ |
| 221 | 235 | 'context' => [ |
| 222 | 236 | 'data.url' => (string)get_permalink( $assignedPost ), |
@@ -257,7 +271,9 @@ discard block |
||
| 257 | 271 | */ |
| 258 | 272 | protected function getReviewType( $review ) |
| 259 | 273 | { |
| 260 | - if( count( glsr()->reviewTypes ) < 2 )return; |
|
| 274 | + if( count( glsr()->reviewTypes ) < 2 ) { |
|
| 275 | + return; |
|
| 276 | + } |
|
| 261 | 277 | $reviewType = array_key_exists( $review->review_type, glsr()->reviewTypes ) |
| 262 | 278 | ? glsr()->reviewTypes[$review->review_type] |
| 263 | 279 | : __( 'Unknown', 'site-reviews' ); |
@@ -109,7 +109,9 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function renderReviewEditor( WP_Post $post ) |
| 111 | 111 | { |
| 112 | - if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ))return; |
|
| 112 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post )) { |
|
| 113 | + return; |
|
| 114 | + } |
|
| 113 | 115 | glsr()->render( 'partials/editor/review', [ |
| 114 | 116 | 'post' => $post, |
| 115 | 117 | ]); |
@@ -121,7 +123,9 @@ discard block |
||
| 121 | 123 | */ |
| 122 | 124 | public function renderReviewNotice( WP_Post $post ) |
| 123 | 125 | { |
| 124 | - if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ))return; |
|
| 126 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post )) { |
|
| 127 | + return; |
|
| 128 | + } |
|
| 125 | 129 | glsr( Notice::class )->addWarning( __( 'This review is read-only.', 'site-reviews' )); |
| 126 | 130 | glsr( Template::class )->render( 'partials/editor/notice', [ |
| 127 | 131 | 'context' => [ |
@@ -136,12 +140,16 @@ discard block |
||
| 136 | 140 | */ |
| 137 | 141 | public function renderTinymceButton() |
| 138 | 142 | { |
| 139 | - if( glsr_current_screen()->base != 'post' )return; |
|
| 143 | + if( glsr_current_screen()->base != 'post' ) { |
|
| 144 | + return; |
|
| 145 | + } |
|
| 140 | 146 | $shortcodes = []; |
| 141 | 147 | foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
| 142 | 148 | $shortcodes[$shortcode] = $values; |
| 143 | 149 | } |
| 144 | - if( empty( $shortcodes ))return; |
|
| 150 | + if( empty( $shortcodes )) { |
|
| 151 | + return; |
|
| 152 | + } |
|
| 145 | 153 | glsr()->render( 'partials/editor/tinymce', [ |
| 146 | 154 | 'shortcodes' => $shortcodes, |
| 147 | 155 | ]); |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function enqueueAssets() |
| 27 | 27 | { |
| 28 | - $command = new EnqueueAdminAssets([ |
|
| 28 | + $command = new EnqueueAdminAssets( [ |
|
| 29 | 29 | 'pointers' => [[ |
| 30 | 30 | 'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ), |
| 31 | 31 | 'id' => 'glsr-pointer-pinned', |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | 'target' => '#misc-pub-pinned', |
| 38 | 38 | 'title' => __( 'Pin Your Reviews', 'site-reviews' ), |
| 39 | 39 | ]], |
| 40 | - ]); |
|
| 40 | + ] ); |
|
| 41 | 41 | $this->execute( $command ); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [ |
| 51 | 51 | 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ), |
| 52 | - ]); |
|
| 52 | + ] ); |
|
| 53 | 53 | return $links; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -60,19 +60,19 @@ discard block |
||
| 60 | 60 | public function filterDashboardGlanceItems( array $items ) |
| 61 | 61 | { |
| 62 | 62 | $postCount = wp_count_posts( Application::POST_TYPE ); |
| 63 | - if( empty( $postCount->publish )) { |
|
| 63 | + if( empty($postCount->publish) ) { |
|
| 64 | 64 | return $items; |
| 65 | 65 | } |
| 66 | 66 | $text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' ); |
| 67 | - $text = sprintf( $text, number_format_i18n( $postCount->publish )); |
|
| 67 | + $text = sprintf( $text, number_format_i18n( $postCount->publish ) ); |
|
| 68 | 68 | $items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts ) |
| 69 | 69 | ? glsr( Builder::class )->a( $text, [ |
| 70 | 70 | 'class' => 'glsr-review-count', |
| 71 | 71 | 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
| 72 | - ]) |
|
| 72 | + ] ) |
|
| 73 | 73 | : glsr( Builder::class )->span( $text, [ |
| 74 | 74 | 'class' => 'glsr-review-count', |
| 75 | - ]); |
|
| 75 | + ] ); |
|
| 76 | 76 | return $items; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | public function filterTinymcePlugins( array $plugins ) |
| 84 | 84 | { |
| 85 | 85 | if( user_can_richedit() |
| 86 | - && ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ))) { |
|
| 86 | + && (current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' )) ) { |
|
| 87 | 87 | $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' ); |
| 88 | 88 | } |
| 89 | 89 | return $plugins; |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function registerShortcodeButtons() |
| 97 | 97 | { |
| 98 | - $command = new RegisterShortcodeButtons([ |
|
| 98 | + $command = new RegisterShortcodeButtons( [ |
|
| 99 | 99 | 'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ), |
| 100 | 100 | 'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ), |
| 101 | 101 | 'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ), |
| 102 | - ]); |
|
| 102 | + ] ); |
|
| 103 | 103 | $this->execute( $command ); |
| 104 | 104 | } |
| 105 | 105 | |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function renderReviewEditor( WP_Post $post ) |
| 111 | 111 | { |
| 112 | - if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ))return; |
|
| 112 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) )return; |
|
| 113 | 113 | glsr()->render( 'partials/editor/review', [ |
| 114 | 114 | 'post' => $post, |
| 115 | - ]); |
|
| 115 | + ] ); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function renderReviewNotice( WP_Post $post ) |
| 123 | 123 | { |
| 124 | - if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ))return; |
|
| 125 | - glsr( Notice::class )->addWarning( __( 'This review is read-only.', 'site-reviews' )); |
|
| 124 | + if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) )return; |
|
| 125 | + glsr( Notice::class )->addWarning( __( 'This review is read-only.', 'site-reviews' ) ); |
|
| 126 | 126 | glsr( Template::class )->render( 'partials/editor/notice', [ |
| 127 | 127 | 'context' => [ |
| 128 | 128 | 'notices' => glsr( Notice::class )->get(), |
| 129 | 129 | ], |
| 130 | - ]); |
|
| 130 | + ] ); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
| 142 | 142 | $shortcodes[$shortcode] = $values; |
| 143 | 143 | } |
| 144 | - if( empty( $shortcodes ))return; |
|
| 144 | + if( empty($shortcodes) )return; |
|
| 145 | 145 | glsr()->render( 'partials/editor/tinymce', [ |
| 146 | 146 | 'shortcodes' => $shortcodes, |
| 147 | - ]); |
|
| 147 | + ] ); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | public function routerClearConsole() |
| 154 | 154 | { |
| 155 | 155 | glsr( Console::class )->clear(); |
| 156 | - glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' )); |
|
| 156 | + glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function routerFetchConsole() |
| 163 | 163 | { |
| 164 | - glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' )); |
|
| 164 | + glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' ) ); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -170,19 +170,19 @@ discard block |
||
| 170 | 170 | public function routerCountReviews() |
| 171 | 171 | { |
| 172 | 172 | $countManager = glsr( CountsManager::class ); |
| 173 | - $terms = get_terms([ |
|
| 173 | + $terms = get_terms( [ |
|
| 174 | 174 | 'hide_empty' => true, |
| 175 | 175 | 'taxonomy' => Application::TAXONOMY, |
| 176 | - ]); |
|
| 176 | + ] ); |
|
| 177 | 177 | foreach( $terms as $term ) { |
| 178 | - $countManager->setTermCounts( $term->term_id, $countManager->buildTermCounts( $term->term_id )); |
|
| 178 | + $countManager->setTermCounts( $term->term_id, $countManager->buildTermCounts( $term->term_id ) ); |
|
| 179 | 179 | } |
| 180 | 180 | $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
| 181 | 181 | foreach( $postIds as $postId ) { |
| 182 | - $countManager->setPostCounts( $postId, $countManager->buildPostCounts( $postId )); |
|
| 182 | + $countManager->setPostCounts( $postId, $countManager->buildPostCounts( $postId ) ); |
|
| 183 | 183 | } |
| 184 | 184 | $countManager->setCounts( $countManager->buildCounts() ); |
| 185 | - glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' )); |
|
| 185 | + glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' ) ); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -216,17 +216,17 @@ discard block |
||
| 216 | 216 | { |
| 217 | 217 | $file = $_FILES['import-file']; |
| 218 | 218 | if( $file['error'] !== UPLOAD_ERR_OK ) { |
| 219 | - return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] )); |
|
| 219 | + return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) ); |
|
| 220 | 220 | } |
| 221 | - if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] )) { |
|
| 222 | - return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' )); |
|
| 221 | + if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] ) ) { |
|
| 222 | + return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) ); |
|
| 223 | 223 | } |
| 224 | 224 | $settings = json_decode( file_get_contents( $file['tmp_name'] ), true ); |
| 225 | - if( empty( $settings )) { |
|
| 226 | - return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' )); |
|
| 225 | + if( empty($settings) ) { |
|
| 226 | + return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) ); |
|
| 227 | 227 | } |
| 228 | - glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings )); |
|
| 229 | - glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' )); |
|
| 228 | + glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) ); |
|
| 229 | + glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) ); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ), |
| 245 | 245 | UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ), |
| 246 | 246 | ]; |
| 247 | - return !isset( $errors[$errorCode] ) |
|
| 247 | + return !isset($errors[$errorCode]) |
|
| 248 | 248 | ? __( 'Unknown upload error.', 'site-reviews' ) |
| 249 | 249 | : $errors[$errorCode]; |
| 250 | 250 | } |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function renderTaxonomyFilter() |
| 37 | 37 | { |
| 38 | - if( !is_object_in_taxonomy( get_current_screen()->post_type, Application::TAXONOMY ))return; |
|
| 38 | + if( !is_object_in_taxonomy( get_current_screen()->post_type, Application::TAXONOMY ) )return; |
|
| 39 | 39 | echo glsr( Builder::class )->label( __( 'Filter by category', 'site-reviews' ), [ |
| 40 | 40 | 'class' => 'screen-reader-text', |
| 41 | 41 | 'for' => Application::TAXONOMY, |
| 42 | - ]); |
|
| 43 | - wp_dropdown_categories([ |
|
| 42 | + ] ); |
|
| 43 | + wp_dropdown_categories( [ |
|
| 44 | 44 | 'depth' => 3, |
| 45 | 45 | 'hide_empty' => true, |
| 46 | 46 | 'hide_if_empty' => true, |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | 'show_option_all' => $this->getShowOptionAll(), |
| 53 | 53 | 'taxonomy' => Application::TAXONOMY, |
| 54 | 54 | 'value_field' => 'slug', |
| 55 | - ]); |
|
| 55 | + ] ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | protected function getSelected() |
| 62 | 62 | { |
| 63 | 63 | global $wp_query; |
| 64 | - return isset( $wp_query->query[Application::TAXONOMY] ) |
|
| 64 | + return isset($wp_query->query[Application::TAXONOMY]) |
|
| 65 | 65 | ? $wp_query->query[Application::TAXONOMY] |
| 66 | 66 | : ''; |
| 67 | 67 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $taxonomy = get_taxonomy( Application::TAXONOMY ); |
| 75 | 75 | return $taxonomy |
| 76 | - ? ucfirst( strtolower( $taxonomy->labels->all_items )) |
|
| 76 | + ? ucfirst( strtolower( $taxonomy->labels->all_items ) ) |
|
| 77 | 77 | : ''; |
| 78 | 78 | } |
| 79 | 79 | } |
@@ -35,7 +35,9 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function renderTaxonomyFilter() |
| 37 | 37 | { |
| 38 | - if( !is_object_in_taxonomy( get_current_screen()->post_type, Application::TAXONOMY ))return; |
|
| 38 | + if( !is_object_in_taxonomy( get_current_screen()->post_type, Application::TAXONOMY )) { |
|
| 39 | + return; |
|
| 40 | + } |
|
| 39 | 41 | echo glsr( Builder::class )->label( __( 'Filter by category', 'site-reviews' ), [ |
| 40 | 42 | 'class' => 'screen-reader-text', |
| 41 | 43 | 'for' => Application::TAXONOMY, |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | $translations = $this->getTranslations(); |
| 32 | 32 | $entries = $this->filter( $translations, $this->entries() )->results(); |
| 33 | - array_walk( $translations, function( &$entry ) use( $entries ) { |
|
| 33 | + array_walk( $translations, function( &$entry ) use($entries) { |
|
| 34 | 34 | $entry['desc'] = array_key_exists( $entry['id'], $entries ) |
| 35 | 35 | ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' ) |
| 36 | 36 | : ''; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function entries() |
| 45 | 45 | { |
| 46 | - if( !isset( $this->entries )) { |
|
| 46 | + if( !isset($this->entries) ) { |
|
| 47 | 47 | try { |
| 48 | 48 | $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' ); |
| 49 | 49 | $entries = $this->normalize( Parser::parseFile( $potFile )->getEntries() ); |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function filter( $filterWith = null, $entries = null, $intersect = true ) |
| 78 | 78 | { |
| 79 | - if( !is_array( $entries )) { |
|
| 79 | + if( !is_array( $entries ) ) { |
|
| 80 | 80 | $entries = $this->results; |
| 81 | 81 | } |
| 82 | - if( !is_array( $filterWith )) { |
|
| 82 | + if( !is_array( $filterWith ) ) { |
|
| 83 | 83 | $filterWith = $this->getTranslations(); |
| 84 | 84 | } |
| 85 | - $keys = array_flip( array_column( $filterWith, 'id' )); |
|
| 85 | + $keys = array_flip( array_column( $filterWith, 'id' ) ); |
|
| 86 | 86 | $this->results = $intersect |
| 87 | 87 | ? array_intersect_key( $entries, $keys ) |
| 88 | 88 | : array_diff_key( $entries, $keys ); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | return $this->translate( $translation, $domain, [ |
| 101 | 101 | 'single' => $text, |
| 102 | - ]); |
|
| 102 | + ] ); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | return $this->translate( $translation, $domain, [ |
| 115 | 115 | 'context' => $context, |
| 116 | 116 | 'single' => $text, |
| 117 | - ]); |
|
| 117 | + ] ); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | 'number' => $number, |
| 132 | 132 | 'plural' => $plural, |
| 133 | 133 | 'single' => $single, |
| 134 | - ]); |
|
| 134 | + ] ); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | 'number' => $number, |
| 151 | 151 | 'plural' => $plural, |
| 152 | 152 | 'single' => $single, |
| 153 | - ]); |
|
| 153 | + ] ); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | public function render( $template, array $entry ) |
| 161 | 161 | { |
| 162 | 162 | $data = array_combine( |
| 163 | - array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry )), |
|
| 163 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
| 164 | 164 | $entry |
| 165 | 165 | ); |
| 166 | 166 | ob_start(); |
| 167 | 167 | glsr( Template::class )->render( 'partials/translations/'.$template, [ |
| 168 | 168 | 'context' => $data, |
| 169 | - ]); |
|
| 169 | + ] ); |
|
| 170 | 170 | return ob_get_clean(); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -199,13 +199,13 @@ discard block |
||
| 199 | 199 | 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
| 200 | 200 | 's1' => $this->getEntryString( $entry, 'msgid' ), |
| 201 | 201 | ]; |
| 202 | - $text = !empty( $data['p1'] ) |
|
| 202 | + $text = !empty($data['p1']) |
|
| 203 | 203 | ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
| 204 | 204 | : $data['s1']; |
| 205 | 205 | $rendered .= $this->render( 'result', [ |
| 206 | 206 | 'entry' => wp_json_encode( $data ), |
| 207 | 207 | 'text' => wp_strip_all_tags( $text ), |
| 208 | - ]); |
|
| 208 | + ] ); |
|
| 209 | 209 | } |
| 210 | 210 | if( $resetAfterRender ) { |
| 211 | 211 | $this->reset(); |
@@ -238,12 +238,12 @@ discard block |
||
| 238 | 238 | public function search( $needle = '' ) |
| 239 | 239 | { |
| 240 | 240 | $this->reset(); |
| 241 | - $needle = trim( strtolower( $needle )); |
|
| 241 | + $needle = trim( strtolower( $needle ) ); |
|
| 242 | 242 | foreach( $this->entries() as $key => $entry ) { |
| 243 | - $single = strtolower( $this->getEntryString( $entry, 'msgid' )); |
|
| 244 | - $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' )); |
|
| 243 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
| 244 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
| 245 | 245 | if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
| 246 | - if( in_array( $needle, [$single, $plural] )) { |
|
| 246 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
| 247 | 247 | $this->results[$key] = $entry; |
| 248 | 248 | } |
| 249 | 249 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | } |
| 267 | 267 | $args = $this->normalizeTranslationArgs( $args ); |
| 268 | 268 | $strings = $this->getTranslationStrings( $args['single'], $args['plural'] ); |
| 269 | - if( empty( $strings )) { |
|
| 269 | + if( empty($strings) ) { |
|
| 270 | 270 | return $original; |
| 271 | 271 | } |
| 272 | 272 | $string = current( $strings ); |
@@ -281,8 +281,8 @@ discard block |
||
| 281 | 281 | */ |
| 282 | 282 | protected function getEntryString( array $entry, $key ) |
| 283 | 283 | { |
| 284 | - return isset( $entry[$key] ) |
|
| 285 | - ? implode( '', (array) $entry[$key] ) |
|
| 284 | + return isset($entry[$key]) |
|
| 285 | + ? implode( '', (array)$entry[$key] ) |
|
| 286 | 286 | : ''; |
| 287 | 287 | } |
| 288 | 288 | |
@@ -293,10 +293,10 @@ discard block |
||
| 293 | 293 | protected function getTranslations() |
| 294 | 294 | { |
| 295 | 295 | static $translations; |
| 296 | - if( empty( $translations )) { |
|
| 296 | + if( empty($translations) ) { |
|
| 297 | 297 | $settings = glsr( OptionManager::class )->get( 'settings' ); |
| 298 | - $translations = isset( $settings['strings'] ) |
|
| 299 | - ? $this->normalizeSettings( (array) $settings['strings'] ) |
|
| 298 | + $translations = isset($settings['strings']) |
|
| 299 | + ? $this->normalizeSettings( (array)$settings['strings'] ) |
|
| 300 | 300 | : []; |
| 301 | 301 | } |
| 302 | 302 | return $translations; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | protected function getTranslationStrings( $single, $plural ) |
| 311 | 311 | { |
| 312 | - return array_filter( $this->getTranslations(), function( $string ) use( $single, $plural ) { |
|
| 312 | + return array_filter( $this->getTranslations(), function( $string ) use($single, $plural) { |
|
| 313 | 313 | return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' ) |
| 314 | 314 | && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' ); |
| 315 | 315 | }); |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | $keys = [ |
| 324 | 324 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
| 325 | 325 | ]; |
| 326 | - array_walk( $entries, function( &$entry ) use( $keys ) { |
|
| 326 | + array_walk( $entries, function( &$entry ) use($keys) { |
|
| 327 | 327 | foreach( $keys as $key ) { |
| 328 | 328 | $entry = $this->normalizeEntryString( $entry, $key ); |
| 329 | 329 | } |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | */ |
| 338 | 338 | protected function normalizeEntryString( array $entry, $key ) |
| 339 | 339 | { |
| 340 | - if( isset( $entry[$key] )) { |
|
| 340 | + if( isset($entry[$key]) ) { |
|
| 341 | 341 | $entry[$key] = $this->getEntryString( $entry, $key ); |
| 342 | 342 | } |
| 343 | 343 | return $entry; |
@@ -351,11 +351,11 @@ discard block |
||
| 351 | 351 | $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
| 352 | 352 | $strings = array_filter( $strings, 'is_array' ); |
| 353 | 353 | foreach( $strings as &$string ) { |
| 354 | - $string['type'] = isset( $string['p1'] ) ? 'plural' : 'single'; |
|
| 354 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
| 355 | 355 | $string = wp_parse_args( $string, $defaultString ); |
| 356 | 356 | } |
| 357 | 357 | return array_filter( $strings, function( $string ) { |
| 358 | - return !empty( $string['id'] ); |
|
| 358 | + return !empty($string['id']); |
|
| 359 | 359 | }); |
| 360 | 360 | } |
| 361 | 361 | |
@@ -379,10 +379,10 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | protected function translatePlural( $domain, array $string, array $args ) |
| 381 | 381 | { |
| 382 | - if( !empty( $string['s2'] )) { |
|
| 382 | + if( !empty($string['s2']) ) { |
|
| 383 | 383 | $args['single'] = $string['s2']; |
| 384 | 384 | } |
| 385 | - if( !empty( $string['p2'] )) { |
|
| 385 | + if( !empty($string['p2']) ) { |
|
| 386 | 386 | $args['plural'] = $string['p2']; |
| 387 | 387 | } |
| 388 | 388 | return get_translations_for_domain( $domain )->translate_plural( |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | protected function translateSingle( $domain, array $string, array $args ) |
| 401 | 401 | { |
| 402 | - if( !empty( $string['s2'] )) { |
|
| 402 | + if( !empty($string['s2']) ) { |
|
| 403 | 403 | $args['single'] = $string['s2']; |
| 404 | 404 | } |
| 405 | 405 | return get_translations_for_domain( $domain )->translate( |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function routerChangeStatus( array $request ) |
| 24 | 24 | { |
| 25 | - wp_send_json_success( $this->execute( new ChangeStatus( $request ))); |
|
| 25 | + wp_send_json_success( $this->execute( new ChangeStatus( $request ) ) ); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -31,10 +31,10 @@ discard block |
||
| 31 | 31 | public function routerClearConsole() |
| 32 | 32 | { |
| 33 | 33 | glsr( AdminController::class )->routerClearConsole(); |
| 34 | - wp_send_json_success([ |
|
| 34 | + wp_send_json_success( [ |
|
| 35 | 35 | 'console' => glsr( Console::class )->get(), |
| 36 | 36 | 'notices' => glsr( Notice::class )->get(), |
| 37 | - ]); |
|
| 37 | + ] ); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | public function routerCountReviews() |
| 44 | 44 | { |
| 45 | 45 | glsr( AdminController::class )->routerCountReviews(); |
| 46 | - wp_send_json_success([ |
|
| 46 | + wp_send_json_success( [ |
|
| 47 | 47 | 'notices' => glsr( Notice::class )->get(), |
| 48 | - ]); |
|
| 48 | + ] ); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | { |
| 56 | 56 | $shortcode = $request['shortcode']; |
| 57 | 57 | $response = false; |
| 58 | - if( array_key_exists( $shortcode, glsr()->mceShortcodes )) { |
|
| 58 | + if( array_key_exists( $shortcode, glsr()->mceShortcodes ) ) { |
|
| 59 | 59 | $data = glsr()->mceShortcodes[$shortcode]; |
| 60 | - if( !empty( $data['errors'] )) { |
|
| 60 | + if( !empty($data['errors']) ) { |
|
| 61 | 61 | $data['btn_okay'] = [esc_html__( 'Okay', 'site-reviews' )]; |
| 62 | 62 | } |
| 63 | 63 | $response = [ |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | public function routerFetchConsole() |
| 78 | 78 | { |
| 79 | 79 | glsr( AdminController::class )->routerFetchConsole(); |
| 80 | - wp_send_json_success([ |
|
| 80 | + wp_send_json_success( [ |
|
| 81 | 81 | 'console' => glsr( Console::class )->get(), |
| 82 | 82 | 'notices' => glsr( Notice::class )->get(), |
| 83 | - ]); |
|
| 83 | + ] ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | public function routerSearchPosts( array $request ) |
| 90 | 90 | { |
| 91 | 91 | $results = glsr( Database::class )->searchPosts( $request['search'] ); |
| 92 | - wp_send_json_success([ |
|
| 92 | + wp_send_json_success( [ |
|
| 93 | 93 | 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
| 94 | 94 | 'items' => $results, |
| 95 | - ]); |
|
| 95 | + ] ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function routerSearchTranslations( array $request ) |
| 102 | 102 | { |
| 103 | - if( empty( $request['exclude'] )) { |
|
| 103 | + if( empty($request['exclude']) ) { |
|
| 104 | 104 | $request['exclude'] = []; |
| 105 | 105 | } |
| 106 | 106 | $results = glsr( Translator::class ) |
@@ -108,10 +108,10 @@ discard block |
||
| 108 | 108 | ->exclude() |
| 109 | 109 | ->exclude( $request['exclude'] ) |
| 110 | 110 | ->renderResults(); |
| 111 | - wp_send_json_success([ |
|
| 111 | + wp_send_json_success( [ |
|
| 112 | 112 | 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
| 113 | 113 | 'items' => $results, |
| 114 | - ]); |
|
| 114 | + ] ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | 'errors' => glsr( Session::class )->get( $request['form_id'].'errors', false, true ), |
| 125 | 125 | 'message' => glsr( Session::class )->get( $request['form_id'].'message', '', true ), |
| 126 | 126 | 'recaptcha' => glsr( Session::class )->get( $request['form_id'].'recaptcha', false, true ), |
| 127 | - 'redirect' => trim( strval( get_post_meta( intval( $request['post_id'] ), 'redirect_to', true ))), |
|
| 127 | + 'redirect' => trim( strval( get_post_meta( intval( $request['post_id'] ), 'redirect_to', true ) ) ), |
|
| 128 | 128 | ]; |
| 129 | - if( !wp_validate_boolean( $data['errors'] )) { |
|
| 129 | + if( !wp_validate_boolean( $data['errors'] ) ) { |
|
| 130 | 130 | glsr( Session::class )->clear(); |
| 131 | 131 | wp_send_json_success( $data ); |
| 132 | 132 | } |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function routerTogglePinned( array $request ) |
| 140 | 140 | { |
| 141 | - $isPinned = $this->execute( new TogglePinned( $request )); |
|
| 142 | - wp_send_json_success([ |
|
| 141 | + $isPinned = $this->execute( new TogglePinned( $request ) ); |
|
| 142 | + wp_send_json_success( [ |
|
| 143 | 143 | 'notices' => glsr( Notice::class )->get(), |
| 144 | 144 | 'pinned' => $isPinned, |
| 145 | - ]); |
|
| 145 | + ] ); |
|
| 146 | 146 | } |
| 147 | 147 | } |
@@ -111,7 +111,9 @@ discard block |
||
| 111 | 111 | $termIds = glsr( Helper::class )->convertStringToArray( $commaSeparatedTermIds ); |
| 112 | 112 | foreach( $termIds as $termId ) { |
| 113 | 113 | $term = get_term( $termId, Application::TAXONOMY ); |
| 114 | - if( !isset( $term->term_id ))continue; |
|
| 114 | + if( !isset( $term->term_id )) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 115 | 117 | $terms[] = $term->term_id; |
| 116 | 118 | } |
| 117 | 119 | return $terms; |
@@ -123,7 +125,9 @@ discard block |
||
| 123 | 125 | */ |
| 124 | 126 | public function revert( $postId ) |
| 125 | 127 | { |
| 126 | - if( get_post_field( 'post_type', $postId ) != Application::POST_TYPE )return; |
|
| 128 | + if( get_post_field( 'post_type', $postId ) != Application::POST_TYPE ) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 127 | 131 | delete_post_meta( $postId, '_edit_last' ); |
| 128 | 132 | $result = wp_update_post([ |
| 129 | 133 | 'ID' => $postId, |
@@ -141,7 +145,9 @@ discard block |
||
| 141 | 145 | */ |
| 142 | 146 | public function single( WP_Post $post ) |
| 143 | 147 | { |
| 144 | - if( $post->post_type != Application::POST_TYPE )return; |
|
| 148 | + if( $post->post_type != Application::POST_TYPE ) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 145 | 151 | $review = new Review( $post ); |
| 146 | 152 | return apply_filters( 'site-reviews/get/review', $review, $post ); |
| 147 | 153 | } |
@@ -166,7 +172,9 @@ discard block |
||
| 166 | 172 | protected function setTerms( $postId, $termIds ) |
| 167 | 173 | { |
| 168 | 174 | $terms = $this->normalizeTerms( $termIds ); |
| 169 | - if( empty( $terms ))return; |
|
| 175 | + if( empty( $terms )) { |
|
| 176 | + return; |
|
| 177 | + } |
|
| 170 | 178 | $result = wp_set_object_terms( $postId, $terms, Application::TAXONOMY ); |
| 171 | 179 | if( is_wp_error( $result )) { |
| 172 | 180 | glsr_log()->error( $result->get_error_message() ); |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | 'post_type' => Application::POST_TYPE, |
| 36 | 36 | ]; |
| 37 | 37 | $postId = wp_insert_post( $postValues, true ); |
| 38 | - if( is_wp_error( $postId )) { |
|
| 38 | + if( is_wp_error( $postId ) ) { |
|
| 39 | 39 | glsr_log()->error( $postId->get_error_message() )->debug( $postValues ); |
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | $this->setTerms( $postId, $command->category ); |
| 43 | - $review = $this->single( get_post( $postId )); |
|
| 43 | + $review = $this->single( get_post( $postId ) ); |
|
| 44 | 44 | do_action( 'site-reviews/review/created', $review, $command ); |
| 45 | 45 | return $review; |
| 46 | 46 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | public function delete( $metaReviewId ) |
| 53 | 53 | { |
| 54 | - if( $postId = $this->getPostId( $metaReviewId )) { |
|
| 54 | + if( $postId = $this->getPostId( $metaReviewId ) ) { |
|
| 55 | 55 | wp_delete_post( $postId, true ); |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | $paged = glsr( QueryBuilder::class )->getPaged( |
| 74 | 74 | wp_validate_boolean( $args['pagination'] ) |
| 75 | 75 | ); |
| 76 | - $reviews = new WP_Query([ |
|
| 76 | + $reviews = new WP_Query( [ |
|
| 77 | 77 | 'meta_key' => 'pinned', |
| 78 | 78 | 'meta_query' => $metaQuery, |
| 79 | 79 | 'offset' => $args['offset'], |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | 'post_type' => Application::POST_TYPE, |
| 87 | 87 | 'posts_per_page' => $args['count'], |
| 88 | 88 | 'tax_query' => $taxQuery, |
| 89 | - ]); |
|
| 89 | + ] ); |
|
| 90 | 90 | return (object)[ |
| 91 | 91 | 'results' => array_map( [$this, 'single'], $reviews->posts ), |
| 92 | 92 | 'max_num_pages' => $reviews->max_num_pages, |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $termIds = glsr( Helper::class )->convertStringToArray( $commaSeparatedTermIds ); |
| 113 | 113 | foreach( $termIds as $termId ) { |
| 114 | 114 | $term = get_term( $termId, Application::TAXONOMY ); |
| 115 | - if( !isset( $term->term_id ))continue; |
|
| 115 | + if( !isset($term->term_id) )continue; |
|
| 116 | 116 | $terms[] = $term->term_id; |
| 117 | 117 | } |
| 118 | 118 | return $terms; |
@@ -126,13 +126,13 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | if( get_post_field( 'post_type', $postId ) != Application::POST_TYPE )return; |
| 128 | 128 | delete_post_meta( $postId, '_edit_last' ); |
| 129 | - $result = wp_update_post([ |
|
| 129 | + $result = wp_update_post( [ |
|
| 130 | 130 | 'ID' => $postId, |
| 131 | 131 | 'post_content' => get_post_meta( $postId, 'content', true ), |
| 132 | 132 | 'post_date' => get_post_meta( $postId, 'date', true ), |
| 133 | 133 | 'post_title' => get_post_meta( $postId, 'title', true ), |
| 134 | - ]); |
|
| 135 | - if( is_wp_error( $result )) { |
|
| 134 | + ] ); |
|
| 135 | + if( is_wp_error( $result ) ) { |
|
| 136 | 136 | glsr_log()->error( $result->get_error_message() ); |
| 137 | 137 | } |
| 138 | 138 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | protected function getNewPostStatus( array $review, $isBlacklisted ) |
| 155 | 155 | { |
| 156 | 156 | $requireApprovalOption = glsr( OptionManager::class )->get( 'settings.general.require.approval' ); |
| 157 | - return $review['review_type'] == 'local' && ( $requireApprovalOption == 'yes' || $isBlacklisted ) |
|
| 157 | + return $review['review_type'] == 'local' && ($requireApprovalOption == 'yes' || $isBlacklisted) |
|
| 158 | 158 | ? 'pending' |
| 159 | 159 | : 'publish'; |
| 160 | 160 | } |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | protected function setTerms( $postId, $termIds ) |
| 168 | 168 | { |
| 169 | 169 | $terms = $this->normalizeTerms( $termIds ); |
| 170 | - if( empty( $terms ))return; |
|
| 170 | + if( empty($terms) )return; |
|
| 171 | 171 | $result = wp_set_object_terms( $postId, $terms, Application::TAXONOMY ); |
| 172 | - if( is_wp_error( $result )) { |
|
| 172 | + if( is_wp_error( $result ) ) { |
|
| 173 | 173 | glsr_log()->error( $result->get_error_message() ); |
| 174 | 174 | } |
| 175 | 175 | } |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | $queries = []; |
| 19 | 19 | foreach( $keys as $key ) { |
| 20 | - if( !array_key_exists( $key, $values ))continue; |
|
| 20 | + if( !array_key_exists( $key, $values ) )continue; |
|
| 21 | 21 | $methodName = glsr( Helper::class )->buildMethodName( $key, __FUNCTION__ ); |
| 22 | - if( !method_exists( $this, $methodName ))continue; |
|
| 22 | + if( !method_exists( $this, $methodName ) )continue; |
|
| 23 | 23 | $query = call_user_func( [$this, $methodName], $values[$key] ); |
| 24 | - if( is_array( $query )) { |
|
| 24 | + if( is_array( $query ) ) { |
|
| 25 | 25 | $queries[] = $query; |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | $string = ''; |
| 37 | 37 | $values = array_filter( $values ); |
| 38 | 38 | foreach( $conditions as $key => $value ) { |
| 39 | - if( !isset( $values[$key] ))continue; |
|
| 39 | + if( !isset($values[$key]) )continue; |
|
| 40 | 40 | $values[$key] = implode( ',', (array)$values[$key] ); |
| 41 | 41 | $string .= strpos( $value, '%s' ) !== false |
| 42 | - ? sprintf( $value, strval( $values[$key] )) |
|
| 42 | + ? sprintf( $value, strval( $values[$key] ) ) |
|
| 43 | 43 | : $value; |
| 44 | 44 | } |
| 45 | 45 | return $string; |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function buildSqlOr( $values, $sprintfFormat ) |
| 55 | 55 | { |
| 56 | - if( !is_array( $values )) { |
|
| 56 | + if( !is_array( $values ) ) { |
|
| 57 | 57 | $values = explode( ',', $values ); |
| 58 | 58 | } |
| 59 | - $values = array_filter( array_map( 'trim', (array)$values )); |
|
| 60 | - $values = array_map( function( $value ) use( $sprintfFormat ) { |
|
| 59 | + $values = array_filter( array_map( 'trim', (array)$values ) ); |
|
| 60 | + $values = array_map( function( $value ) use($sprintfFormat) { |
|
| 61 | 61 | return sprintf( $sprintfFormat, $value ); |
| 62 | 62 | }, $values ); |
| 63 | 63 | return implode( ' OR ', $values ); |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function filterSearchByTitle( $search, WP_Query $query ) |
| 74 | 74 | { |
| 75 | - if( empty( $search ) || empty( $query->get( 'search_terms' ))) { |
|
| 75 | + if( empty($search) || empty($query->get( 'search_terms' )) ) { |
|
| 76 | 76 | return $search; |
| 77 | 77 | } |
| 78 | 78 | global $wpdb; |
| 79 | - $n = empty( $query->get( 'exact' )) |
|
| 79 | + $n = empty($query->get( 'exact' )) |
|
| 80 | 80 | ? '%' |
| 81 | 81 | : ''; |
| 82 | 82 | $search = []; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | ? Application::PAGED_QUERY_VAR |
| 101 | 101 | : 'page'; |
| 102 | 102 | return $isEnabled |
| 103 | - ? max( 1, intval( get_query_var( $pagedQuery ))) |
|
| 103 | + ? max( 1, intval( get_query_var( $pagedQuery ) ) ) |
|
| 104 | 104 | : 1; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | protected function buildQueryAssignedTo( $value ) |
| 112 | 112 | { |
| 113 | - if( empty( $value ))return; |
|
| 113 | + if( empty($value) )return; |
|
| 114 | 114 | $postIds = glsr( Helper::class )->convertStringToArray( $value, 'is_numeric' ); |
| 115 | 115 | return [ |
| 116 | 116 | 'compare' => 'IN', |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | protected function buildQueryCategory( $value ) |
| 127 | 127 | { |
| 128 | - if( empty( $value ))return; |
|
| 128 | + if( empty($value) )return; |
|
| 129 | 129 | return [ |
| 130 | 130 | 'field' => 'term_id', |
| 131 | 131 | 'taxonomy' => Application::TAXONOMY, |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | protected function buildQueryRating( $value ) |
| 141 | 141 | { |
| 142 | - if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 )))return; |
|
| 142 | + if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 ) ) )return; |
|
| 143 | 143 | return [ |
| 144 | 144 | 'compare' => '>=', |
| 145 | 145 | 'key' => 'rating', |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | protected function buildQueryType( $value ) |
| 155 | 155 | { |
| 156 | - if( in_array( $value, ['','all'] ))return; |
|
| 156 | + if( in_array( $value, ['', 'all'] ) )return; |
|
| 157 | 157 | return [ |
| 158 | 158 | 'key' => 'review_type', |
| 159 | 159 | 'value' => $value, |
@@ -17,9 +17,13 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | $queries = []; |
| 19 | 19 | foreach( $keys as $key ) { |
| 20 | - if( !array_key_exists( $key, $values ))continue; |
|
| 20 | + if( !array_key_exists( $key, $values )) { |
|
| 21 | + continue; |
|
| 22 | + } |
|
| 21 | 23 | $methodName = glsr( Helper::class )->buildMethodName( $key, __FUNCTION__ ); |
| 22 | - if( !method_exists( $this, $methodName ))continue; |
|
| 24 | + if( !method_exists( $this, $methodName )) { |
|
| 25 | + continue; |
|
| 26 | + } |
|
| 23 | 27 | $query = call_user_func( [$this, $methodName], $values[$key] ); |
| 24 | 28 | if( is_array( $query )) { |
| 25 | 29 | $queries[] = $query; |
@@ -36,7 +40,9 @@ discard block |
||
| 36 | 40 | $string = ''; |
| 37 | 41 | $values = array_filter( $values ); |
| 38 | 42 | foreach( $conditions as $key => $value ) { |
| 39 | - if( !isset( $values[$key] ))continue; |
|
| 43 | + if( !isset( $values[$key] )) { |
|
| 44 | + continue; |
|
| 45 | + } |
|
| 40 | 46 | $values[$key] = implode( ',', (array)$values[$key] ); |
| 41 | 47 | $string .= strpos( $value, '%s' ) !== false |
| 42 | 48 | ? sprintf( $value, strval( $values[$key] )) |
@@ -110,7 +116,9 @@ discard block |
||
| 110 | 116 | */ |
| 111 | 117 | protected function buildQueryAssignedTo( $value ) |
| 112 | 118 | { |
| 113 | - if( empty( $value ))return; |
|
| 119 | + if( empty( $value )) { |
|
| 120 | + return; |
|
| 121 | + } |
|
| 114 | 122 | $postIds = glsr( Helper::class )->convertStringToArray( $value, 'is_numeric' ); |
| 115 | 123 | return [ |
| 116 | 124 | 'compare' => 'IN', |
@@ -125,7 +133,9 @@ discard block |
||
| 125 | 133 | */ |
| 126 | 134 | protected function buildQueryCategory( $value ) |
| 127 | 135 | { |
| 128 | - if( empty( $value ))return; |
|
| 136 | + if( empty( $value )) { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 129 | 139 | return [ |
| 130 | 140 | 'field' => 'term_id', |
| 131 | 141 | 'taxonomy' => Application::TAXONOMY, |
@@ -139,7 +149,9 @@ discard block |
||
| 139 | 149 | */ |
| 140 | 150 | protected function buildQueryRating( $value ) |
| 141 | 151 | { |
| 142 | - if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 )))return; |
|
| 152 | + if( !is_numeric( $value ) || !in_array( intval( $value ), range( 1, 5 ))) { |
|
| 153 | + return; |
|
| 154 | + } |
|
| 143 | 155 | return [ |
| 144 | 156 | 'compare' => '>=', |
| 145 | 157 | 'key' => 'rating', |
@@ -153,7 +165,9 @@ discard block |
||
| 153 | 165 | */ |
| 154 | 166 | protected function buildQueryType( $value ) |
| 155 | 167 | { |
| 156 | - if( in_array( $value, ['','all'] ))return; |
|
| 168 | + if( in_array( $value, ['','all'] )) { |
|
| 169 | + return; |
|
| 170 | + } |
|
| 157 | 171 | return [ |
| 158 | 172 | 'key' => 'review_type', |
| 159 | 173 | 'value' => $value, |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $this->getCounts(), |
| 67 | 67 | $review->review_type, |
| 68 | 68 | $review->rating |
| 69 | - )); |
|
| 69 | + ) ); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function decreasePostCounts( Review $review ) |
| 76 | 76 | { |
| 77 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 77 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) )return; |
|
| 78 | 78 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 79 | 79 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 80 | 80 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | public function decreaseTermCounts( Review $review ) |
| 86 | 86 | { |
| 87 | 87 | foreach( $review->term_ids as $termId ) { |
| 88 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 88 | + if( empty($counts = $this->getTermCounts( $termId )) )continue; |
|
| 89 | 89 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 90 | 90 | $this->setTermCounts( $termId, $counts ); |
| 91 | 91 | } |
@@ -97,17 +97,17 @@ discard block |
||
| 97 | 97 | public function flatten( array $reviewCounts, array $args = [] ) |
| 98 | 98 | { |
| 99 | 99 | $counts = []; |
| 100 | - array_walk_recursive( $reviewCounts, function( $num, $index ) use( &$counts ) { |
|
| 101 | - $counts[$index] = isset( $counts[$index] ) |
|
| 100 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use(&$counts) { |
|
| 101 | + $counts[$index] = isset($counts[$index]) |
|
| 102 | 102 | ? $num + $counts[$index] |
| 103 | 103 | : $num; |
| 104 | 104 | }); |
| 105 | 105 | $args = wp_parse_args( $args, [ |
| 106 | 106 | 'max' => Rating::MAX_RATING, |
| 107 | 107 | 'min' => Rating::MIN_RATING, |
| 108 | - ]); |
|
| 108 | + ] ); |
|
| 109 | 109 | foreach( $counts as $index => &$num ) { |
| 110 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 110 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) )continue; |
|
| 111 | 111 | $num = 0; |
| 112 | 112 | } |
| 113 | 113 | return $counts; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | 'post_ids' => [], |
| 123 | 123 | 'term_ids' => [], |
| 124 | 124 | 'type' => 'local', |
| 125 | - ]); |
|
| 125 | + ] ); |
|
| 126 | 126 | $counts = []; |
| 127 | 127 | foreach( glsr( Polylang::class )->getPostIds( $args['post_ids'] ) as $postId ) { |
| 128 | 128 | $counts[] = $this->getPostCounts( $postId ); |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | foreach( $args['term_ids'] as $termId ) { |
| 131 | 131 | $counts[] = $this->getTermCounts( $termId ); |
| 132 | 132 | } |
| 133 | - if( empty( $counts )) { |
|
| 133 | + if( empty($counts) ) { |
|
| 134 | 134 | $counts[] = $this->getCounts(); |
| 135 | 135 | } |
| 136 | - return $this->normalize( array_column( $counts, $args['type'] )); |
|
| 136 | + return $this->normalize( array_column( $counts, $args['type'] ) ); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | public function getPostCounts( $postId ) |
| 152 | 152 | { |
| 153 | - return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true )); |
|
| 153 | + return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true ) ); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public function getTermCounts( $termId ) |
| 161 | 161 | { |
| 162 | - return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true )); |
|
| 162 | + return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true ) ); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | public function increaseCounts( Review $review ) |
| 179 | 179 | { |
| 180 | - if( empty( $counts = $this->getCounts() )) { |
|
| 180 | + if( empty($counts = $this->getCounts()) ) { |
|
| 181 | 181 | $counts = $this->buildCounts(); |
| 182 | 182 | } |
| 183 | 183 | $this->setCounts( $this->increaseRating( |
| 184 | 184 | $counts, |
| 185 | 185 | $review->review_type, |
| 186 | 186 | $review->rating |
| 187 | - )); |
|
| 187 | + ) ); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function increasePostCounts( Review $review ) |
| 194 | 194 | { |
| 195 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 195 | + if( !(get_post( $review->assigned_to ) instanceof WP_Post) )return; |
|
| 196 | 196 | $counts = $this->getPostCounts( $review->assigned_to ); |
| 197 | - $counts = empty( $counts ) |
|
| 197 | + $counts = empty($counts) |
|
| 198 | 198 | ? $this->buildPostCounts( $review->assigned_to ) |
| 199 | 199 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
| 200 | 200 | $this->setPostCounts( $review->assigned_to, $counts ); |
@@ -205,10 +205,10 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | public function increaseTermCounts( Review $review ) |
| 207 | 207 | { |
| 208 | - $termIds = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids )); |
|
| 208 | + $termIds = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
| 209 | 209 | foreach( $termIds as $termId ) { |
| 210 | 210 | $counts = $this->getTermCounts( $termId ); |
| 211 | - $counts = empty( $counts ) |
|
| 211 | + $counts = empty($counts) |
|
| 212 | 212 | ? $this->buildTermCounts( $termId ) |
| 213 | 213 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
| 214 | 214 | $this->setTermCounts( $termId, $counts ); |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | { |
| 232 | 232 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 233 | 233 | update_post_meta( $postId, static::META_COUNT, $reviewCounts ); |
| 234 | - update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 235 | - update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 234 | + update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 235 | + update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -241,11 +241,11 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | public function setTermCounts( $termId, array $reviewCounts ) |
| 243 | 243 | { |
| 244 | - if( !term_exists( $termId ))return; |
|
| 244 | + if( !term_exists( $termId ) )return; |
|
| 245 | 245 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 246 | 246 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 247 | - update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 248 | - update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 247 | + update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 248 | + update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | { |
| 257 | 257 | $counts = []; |
| 258 | 258 | $lastPostId = 0; |
| 259 | - while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
|
| 260 | - $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
|
| 259 | + while( $reviews = $this->queryReviews( $args, $lastPostId, $limit ) ) { |
|
| 260 | + $types = array_keys( array_flip( array_column( $reviews, 'type' ) ) ); |
|
| 261 | 261 | foreach( $types as $type ) { |
| 262 | - if( isset( $counts[$type] ))continue; |
|
| 262 | + if( isset($counts[$type]) )continue; |
|
| 263 | 263 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 264 | 264 | } |
| 265 | 265 | foreach( $reviews as $review ) { |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | */ |
| 278 | 278 | protected function decreaseRating( array $reviewCounts, $type, $rating ) |
| 279 | 279 | { |
| 280 | - if( isset( $reviewCounts[$type][$rating] )) { |
|
| 280 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
| 281 | 281 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
| 282 | 282 | } |
| 283 | 283 | return $reviewCounts; |
@@ -290,10 +290,10 @@ discard block |
||
| 290 | 290 | */ |
| 291 | 291 | protected function increaseRating( array $reviewCounts, $type, $rating ) |
| 292 | 292 | { |
| 293 | - if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
| 293 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
| 294 | 294 | return $reviewCounts; |
| 295 | 295 | } |
| 296 | - if( !array_key_exists( $type, $reviewCounts )) { |
|
| 296 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
| 297 | 297 | $reviewCounts[$type] = []; |
| 298 | 298 | } |
| 299 | 299 | $reviewCounts = $this->normalize( $reviewCounts ); |
@@ -306,12 +306,12 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | protected function normalize( array $reviewCounts ) |
| 308 | 308 | { |
| 309 | - if( empty( $reviewCounts )) { |
|
| 309 | + if( empty($reviewCounts) ) { |
|
| 310 | 310 | $reviewCounts = [[]]; |
| 311 | 311 | } |
| 312 | 312 | foreach( $reviewCounts as &$counts ) { |
| 313 | 313 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 314 | - if( isset( $counts[$index] ))continue; |
|
| 314 | + if( isset($counts[$index]) )continue; |
|
| 315 | 315 | $counts[$index] = 0; |
| 316 | 316 | } |
| 317 | 317 | ksort( $counts ); |
@@ -326,14 +326,14 @@ discard block |
||
| 326 | 326 | */ |
| 327 | 327 | protected function queryReviews( array $args = [], $lastPostId, $limit ) |
| 328 | 328 | { |
| 329 | - $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' )); |
|
| 330 | - if( empty( array_filter( $args ))) { |
|
| 329 | + $args = wp_parse_args( $args, array_fill_keys( ['post_id', 'term_id'], '' ) ); |
|
| 330 | + if( empty(array_filter( $args )) ) { |
|
| 331 | 331 | return glsr( SqlQueries::class )->getReviewCounts( $lastPostId, $limit ); |
| 332 | 332 | } |
| 333 | - if( !empty( $args['post_id'] )) { |
|
| 333 | + if( !empty($args['post_id']) ) { |
|
| 334 | 334 | return glsr( SqlQueries::class )->getReviewPostCounts( $args['post_id'], $lastPostId, $limit ); |
| 335 | 335 | } |
| 336 | - if( !empty( $args['term_id'] )) { |
|
| 336 | + if( !empty($args['term_id']) ) { |
|
| 337 | 337 | return glsr( SqlQueries::class )->getReviewTermCounts( $args['term_id'], $lastPostId, $limit ); |
| 338 | 338 | } |
| 339 | 339 | } |
@@ -74,7 +74,9 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function decreasePostCounts( Review $review ) |
| 76 | 76 | { |
| 77 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 77 | + if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 78 | 80 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 79 | 81 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 80 | 82 | } |
@@ -85,7 +87,9 @@ discard block |
||
| 85 | 87 | public function decreaseTermCounts( Review $review ) |
| 86 | 88 | { |
| 87 | 89 | foreach( $review->term_ids as $termId ) { |
| 88 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 90 | + if( empty( $counts = $this->getTermCounts( $termId ))) { |
|
| 91 | + continue; |
|
| 92 | + } |
|
| 89 | 93 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 90 | 94 | $this->setTermCounts( $termId, $counts ); |
| 91 | 95 | } |
@@ -107,7 +111,9 @@ discard block |
||
| 107 | 111 | 'min' => Rating::MIN_RATING, |
| 108 | 112 | ]); |
| 109 | 113 | foreach( $counts as $index => &$num ) { |
| 110 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 114 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 111 | 117 | $num = 0; |
| 112 | 118 | } |
| 113 | 119 | return $counts; |
@@ -192,7 +198,9 @@ discard block |
||
| 192 | 198 | */ |
| 193 | 199 | public function increasePostCounts( Review $review ) |
| 194 | 200 | { |
| 195 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 201 | + if( !( get_post( $review->assigned_to ) instanceof WP_Post )) { |
|
| 202 | + return; |
|
| 203 | + } |
|
| 196 | 204 | $counts = $this->getPostCounts( $review->assigned_to ); |
| 197 | 205 | $counts = empty( $counts ) |
| 198 | 206 | ? $this->buildPostCounts( $review->assigned_to ) |
@@ -241,7 +249,9 @@ discard block |
||
| 241 | 249 | */ |
| 242 | 250 | public function setTermCounts( $termId, array $reviewCounts ) |
| 243 | 251 | { |
| 244 | - if( !term_exists( $termId ))return; |
|
| 252 | + if( !term_exists( $termId )) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 245 | 255 | $ratingCounts = glsr( CountsManager::class )->flatten( $reviewCounts ); |
| 246 | 256 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 247 | 257 | update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
@@ -259,7 +269,9 @@ discard block |
||
| 259 | 269 | while( $reviews = $this->queryReviews( $args, $lastPostId, $limit )) { |
| 260 | 270 | $types = array_keys( array_flip( array_column( $reviews, 'type' ))); |
| 261 | 271 | foreach( $types as $type ) { |
| 262 | - if( isset( $counts[$type] ))continue; |
|
| 272 | + if( isset( $counts[$type] )) { |
|
| 273 | + continue; |
|
| 274 | + } |
|
| 263 | 275 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 264 | 276 | } |
| 265 | 277 | foreach( $reviews as $review ) { |
@@ -311,7 +323,9 @@ discard block |
||
| 311 | 323 | } |
| 312 | 324 | foreach( $reviewCounts as &$counts ) { |
| 313 | 325 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 314 | - if( isset( $counts[$index] ))continue; |
|
| 326 | + if( isset( $counts[$index] )) { |
|
| 327 | + continue; |
|
| 328 | + } |
|
| 315 | 329 | $counts[$index] = 0; |
| 316 | 330 | } |
| 317 | 331 | ksort( $counts ); |