@@ -26,15 +26,15 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | sort( $newTTIds ); |
| 28 | 28 | sort( $oldTTIds ); |
| 29 | - if( $newTTIds === $oldTTIds || !$this->isReviewPostId( $postId ))return; |
|
| 30 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 29 | + if( $newTTIds === $oldTTIds || !$this->isReviewPostId( $postId ) )return; |
|
| 30 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 31 | 31 | $ignoredIds = array_intersect( $oldTTIds, $newTTIds ); |
| 32 | 32 | $decreasedIds = array_diff( $oldTTIds, $ignoredIds ); |
| 33 | 33 | $increasedIds = array_diff( $newTTIds, $ignoredIds ); |
| 34 | - if( $review->term_ids = glsr( Database::class )->getTermIds( $decreasedIds, 'term_taxonomy_id' )) { |
|
| 34 | + if( $review->term_ids = glsr( Database::class )->getTermIds( $decreasedIds, 'term_taxonomy_id' ) ) { |
|
| 35 | 35 | glsr( CountsManager::class )->decreaseTermCounts( $review ); |
| 36 | 36 | } |
| 37 | - if( $review->term_ids = glsr( Database::class )->getTermIds( $increasedIds, 'term_taxonomy_id' )) { |
|
| 37 | + if( $review->term_ids = glsr( Database::class )->getTermIds( $increasedIds, 'term_taxonomy_id' ) ) { |
|
| 38 | 38 | glsr( CountsManager::class )->increaseTermCounts( $review ); |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function onAfterChangeStatus( $newStatus, $oldStatus, $post ) |
| 50 | 50 | { |
| 51 | - if( glsr_get( $post, 'post_type') != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ))return; |
|
| 52 | - $review = glsr( ReviewManager::class )->single( get_post( $post->ID )); |
|
| 51 | + if( glsr_get( $post, 'post_type' ) != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ) )return; |
|
| 52 | + $review = glsr( ReviewManager::class )->single( get_post( $post->ID ) ); |
|
| 53 | 53 | if( $post->post_status == 'publish' ) { |
| 54 | 54 | glsr( CountsManager::class )->increase( $review ); |
| 55 | 55 | } |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function onBeforeDelete( $postId ) |
| 77 | 77 | { |
| 78 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 79 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 78 | + if( !$this->isReviewPostId( $postId ) )return; |
|
| 79 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 80 | 80 | glsr( CountsManager::class )->decrease( $review ); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | if( !$this->isReviewPostId( $postId ) |
| 94 | 94 | || !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) |
| 95 | 95 | )return; |
| 96 | - $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
|
| 96 | + $review = glsr( ReviewManager::class )->single( get_post( $postId ) ); |
|
| 97 | 97 | if( $review->$metaKey == $metaValue )return; |
| 98 | 98 | $method = glsr( Helper::class )->buildMethodName( $metaKey, 'onBeforeChange' ); |
| 99 | 99 | call_user_func( [$this, $method], $review, $metaValue ); |
@@ -26,7 +26,9 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | sort( $newTTIds ); |
| 28 | 28 | sort( $oldTTIds ); |
| 29 | - if( $newTTIds === $oldTTIds || !$this->isReviewPostId( $postId ))return; |
|
| 29 | + if( $newTTIds === $oldTTIds || !$this->isReviewPostId( $postId )) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 30 | 32 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 31 | 33 | $ignoredIds = array_intersect( $oldTTIds, $newTTIds ); |
| 32 | 34 | $decreasedIds = array_diff( $oldTTIds, $ignoredIds ); |
@@ -48,7 +50,9 @@ discard block |
||
| 48 | 50 | */ |
| 49 | 51 | public function onAfterChangeStatus( $newStatus, $oldStatus, $post ) |
| 50 | 52 | { |
| 51 | - if( glsr_get( $post, 'post_type') != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] ))return; |
|
| 53 | + if( glsr_get( $post, 'post_type') != Application::POST_TYPE || in_array( $oldStatus, ['new', $newStatus] )) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 52 | 56 | $review = glsr( ReviewManager::class )->single( get_post( $post->ID )); |
| 53 | 57 | if( $post->post_status == 'publish' ) { |
| 54 | 58 | glsr( CountsManager::class )->increase( $review ); |
@@ -64,7 +68,9 @@ discard block |
||
| 64 | 68 | */ |
| 65 | 69 | public function onAfterCreate( Review $review ) |
| 66 | 70 | { |
| 67 | - if( $review->status !== 'publish' )return; |
|
| 71 | + if( $review->status !== 'publish' ) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 68 | 74 | glsr( CountsManager::class )->increase( $review ); |
| 69 | 75 | } |
| 70 | 76 | |
@@ -75,7 +81,9 @@ discard block |
||
| 75 | 81 | */ |
| 76 | 82 | public function onBeforeDelete( $postId ) |
| 77 | 83 | { |
| 78 | - if( !$this->isReviewPostId( $postId ))return; |
|
| 84 | + if( !$this->isReviewPostId( $postId )) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 79 | 87 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 80 | 88 | glsr( CountsManager::class )->decrease( $review ); |
| 81 | 89 | } |
@@ -92,9 +100,13 @@ discard block |
||
| 92 | 100 | { |
| 93 | 101 | if( !$this->isReviewPostId( $postId ) |
| 94 | 102 | || !in_array( $metaKey, ['assigned_to', 'rating', 'review_type'] ) |
| 95 | - )return; |
|
| 103 | + ) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 96 | 106 | $review = glsr( ReviewManager::class )->single( get_post( $postId )); |
| 97 | - if( $review->$metaKey == $metaValue )return; |
|
| 107 | + if( $review->$metaKey == $metaValue ) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 98 | 110 | $method = glsr( Helper::class )->buildMethodName( $metaKey, 'onBeforeChange' ); |
| 99 | 111 | call_user_func( [$this, $method], $review, $metaValue ); |
| 100 | 112 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function enqueueAssets() |
| 26 | 26 | { |
| 27 | - $command = new EnqueueAdminAssets([ |
|
| 27 | + $command = new EnqueueAdminAssets( [ |
|
| 28 | 28 | 'pointers' => [[ |
| 29 | 29 | 'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ), |
| 30 | 30 | 'id' => 'glsr-pointer-pinned', |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | 'target' => '#misc-pub-pinned', |
| 37 | 37 | 'title' => __( 'Pin Your Reviews', 'site-reviews' ), |
| 38 | 38 | ]], |
| 39 | - ]); |
|
| 39 | + ] ); |
|
| 40 | 40 | $this->execute( $command ); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | { |
| 49 | 49 | $links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [ |
| 50 | 50 | 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ), |
| 51 | - ]); |
|
| 51 | + ] ); |
|
| 52 | 52 | return $links; |
| 53 | 53 | } |
| 54 | 54 | |
@@ -60,20 +60,20 @@ discard block |
||
| 60 | 60 | public function filterDashboardGlanceItems( $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 = glsr( Helper::class )->consolidateArray( $items ); |
| 69 | 69 | $items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts ) |
| 70 | 70 | ? glsr( Builder::class )->a( $text, [ |
| 71 | 71 | 'class' => 'glsr-review-count', |
| 72 | 72 | 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
| 73 | - ]) |
|
| 73 | + ] ) |
|
| 74 | 74 | : glsr( Builder::class )->span( $text, [ |
| 75 | 75 | 'class' => 'glsr-review-count', |
| 76 | - ]); |
|
| 76 | + ] ); |
|
| 77 | 77 | return $items; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function filterTinymcePlugins( $plugins ) |
| 86 | 86 | { |
| 87 | - if( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' )) { |
|
| 87 | + if( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) { |
|
| 88 | 88 | $plugins = glsr( Helper::class )->consolidateArray( $plugins ); |
| 89 | 89 | $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' ); |
| 90 | 90 | } |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function registerTinymcePopups() |
| 99 | 99 | { |
| 100 | - $command = new RegisterTinymcePopups([ |
|
| 100 | + $command = new RegisterTinymcePopups( [ |
|
| 101 | 101 | 'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ), |
| 102 | 102 | 'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ), |
| 103 | 103 | 'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ), |
| 104 | - ]); |
|
| 104 | + ] ); |
|
| 105 | 105 | $this->execute( $command ); |
| 106 | 106 | } |
| 107 | 107 | |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | public function renderTinymceButton( $editorId ) |
| 114 | 114 | { |
| 115 | 115 | $allowedEditors = apply_filters( 'site-reviews/tinymce/editor-ids', ['content'], $editorId ); |
| 116 | - if( glsr_current_screen()->base != 'post' || !in_array( $editorId, $allowedEditors ))return; |
|
| 116 | + if( glsr_current_screen()->base != 'post' || !in_array( $editorId, $allowedEditors ) )return; |
|
| 117 | 117 | $shortcodes = []; |
| 118 | 118 | foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
| 119 | 119 | $shortcodes[$shortcode] = $values; |
| 120 | 120 | } |
| 121 | - if( empty( $shortcodes ))return; |
|
| 121 | + if( empty($shortcodes) )return; |
|
| 122 | 122 | glsr()->render( 'partials/editor/tinymce', [ |
| 123 | 123 | 'shortcodes' => $shortcodes, |
| 124 | - ]); |
|
| 124 | + ] ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | public function routerClearConsole() |
| 131 | 131 | { |
| 132 | 132 | glsr( Console::class )->clear(); |
| 133 | - glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' )); |
|
| 133 | + glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) ); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function routerFetchConsole() |
| 140 | 140 | { |
| 141 | - glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' )); |
|
| 141 | + glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' ) ); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | public function routerCountReviews( $showNotice = true ) |
| 149 | 149 | { |
| 150 | 150 | glsr( CountsManager::class )->countAll(); |
| 151 | - glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' )); |
|
| 151 | + glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) ); |
|
| 152 | 152 | if( $showNotice ) { |
| 153 | - glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' )); |
|
| 153 | + glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' ) ); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |
@@ -185,17 +185,17 @@ discard block |
||
| 185 | 185 | { |
| 186 | 186 | $file = $_FILES['import-file']; |
| 187 | 187 | if( $file['error'] !== UPLOAD_ERR_OK ) { |
| 188 | - return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] )); |
|
| 188 | + return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) ); |
|
| 189 | 189 | } |
| 190 | - if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] )) { |
|
| 191 | - return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' )); |
|
| 190 | + if( $file['type'] !== 'application/json' || !glsr( Helper::class )->endsWith( '.json', $file['name'] ) ) { |
|
| 191 | + return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) ); |
|
| 192 | 192 | } |
| 193 | 193 | $settings = json_decode( file_get_contents( $file['tmp_name'] ), true ); |
| 194 | - if( empty( $settings )) { |
|
| 195 | - return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' )); |
|
| 194 | + if( empty($settings) ) { |
|
| 195 | + return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) ); |
|
| 196 | 196 | } |
| 197 | - glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings )); |
|
| 198 | - glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' )); |
|
| 197 | + glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) ); |
|
| 198 | + glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) ); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -213,6 +213,6 @@ discard block |
||
| 213 | 213 | UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ), |
| 214 | 214 | UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ), |
| 215 | 215 | ]; |
| 216 | - return glsr_get( $errors, $errorCode, __( 'Unknown upload error.', 'site-reviews' )); |
|
| 216 | + return glsr_get( $errors, $errorCode, __( 'Unknown upload error.', 'site-reviews' ) ); |
|
| 217 | 217 | } |
| 218 | 218 | } |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function renderTaxonomyFilter() |
| 37 | 37 | { |
| 38 | - if( !is_object_in_taxonomy( glsr_current_screen()->post_type, Application::TAXONOMY ))return; |
|
| 38 | + if( !is_object_in_taxonomy( glsr_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 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | if( $taxonomy != Application::TAXONOMY || count( $newTTIds ) <= 1 )return; |
| 71 | 71 | $diff = array_diff( $newTTIds, $oldTTIds ); |
| 72 | - if( empty( $newTerm = array_shift( $diff ))) { |
|
| 72 | + if( empty($newTerm = array_shift( $diff )) ) { |
|
| 73 | 73 | $newTerm = array_shift( $newTTIds ); |
| 74 | 74 | } |
| 75 | 75 | if( $newTerm ) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | $taxonomy = get_taxonomy( Application::TAXONOMY ); |
| 95 | 95 | return $taxonomy |
| 96 | - ? ucfirst( strtolower( $taxonomy->labels->all_items )) |
|
| 96 | + ? ucfirst( strtolower( $taxonomy->labels->all_items ) ) |
|
| 97 | 97 | : ''; |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -35,7 +35,9 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function renderTaxonomyFilter() |
| 37 | 37 | { |
| 38 | - if( !is_object_in_taxonomy( glsr_current_screen()->post_type, Application::TAXONOMY ))return; |
|
| 38 | + if( !is_object_in_taxonomy( glsr_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, |
@@ -67,7 +69,9 @@ discard block |
||
| 67 | 69 | */ |
| 68 | 70 | public function restrictTermSelection( $postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds ) |
| 69 | 71 | { |
| 70 | - if( $taxonomy != Application::TAXONOMY || count( $newTTIds ) <= 1 )return; |
|
| 72 | + if( $taxonomy != Application::TAXONOMY || count( $newTTIds ) <= 1 ) { |
|
| 73 | + return; |
|
| 74 | + } |
|
| 71 | 75 | $diff = array_diff( $newTTIds, $oldTTIds ); |
| 72 | 76 | if( empty( $newTerm = array_shift( $diff ))) { |
| 73 | 77 | $newTerm = array_shift( $newTTIds ); |
@@ -57,60 +57,60 @@ |
||
| 57 | 57 | */ |
| 58 | 58 | public function run() |
| 59 | 59 | { |
| 60 | - add_action( 'admin_enqueue_scripts', [$this->admin, 'enqueueAssets'] ); |
|
| 61 | - add_action( 'admin_init', [$this->admin, 'registerTinymcePopups'] ); |
|
| 62 | - add_action( 'media_buttons', [$this->admin, 'renderTinymceButton'], 11 ); |
|
| 63 | - add_action( 'plugins_loaded', [$this->app, 'getDefaults'], 11 ); |
|
| 64 | - add_action( 'plugins_loaded', [$this->app, 'registerAddons'] ); |
|
| 65 | - add_action( 'plugins_loaded', [$this->app, 'registerLanguages'] ); |
|
| 66 | - add_action( 'plugins_loaded', [$this->app, 'registerReviewTypes'] ); |
|
| 67 | - add_action( 'upgrader_process_complete', [$this->app, 'upgraded'], 10, 2 ); |
|
| 68 | - add_action( 'init', [$this->blocks, 'registerAssets'], 9 ); |
|
| 69 | - add_action( 'init', [$this->blocks, 'registerBlocks'] ); |
|
| 70 | - add_action( 'admin_footer', [$this->console, 'logOnce'] ); |
|
| 71 | - add_action( 'wp_footer', [$this->console, 'logOnce'] ); |
|
| 72 | - add_action( 'admin_enqueue_scripts', [$this->editor, 'customizePostStatusLabels'] ); |
|
| 73 | - add_action( 'add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes'] ); |
|
| 74 | - add_action( 'admin_print_scripts', [$this->editor, 'removeAutosave'], 999 ); |
|
| 75 | - add_action( 'admin_menu', [$this->editor, 'removeMetaBoxes'] ); |
|
| 76 | - add_action( 'current_screen', [$this->editor, 'removePostTypeSupport'] ); |
|
| 77 | - add_action( 'post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox'] ); |
|
| 78 | - add_action( 'admin_head', [$this->editor, 'renderReviewFields'] ); |
|
| 79 | - add_action( 'admin_action_revert', [$this->editor, 'revertReview'] ); |
|
| 80 | - add_action( 'save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'] ); |
|
| 81 | - add_action( 'admin_action_approve', [$this->listtable, 'approve'] ); |
|
| 82 | - add_action( 'bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2 ); |
|
| 83 | - add_action( 'restrict_manage_posts', [$this->listtable, 'renderColumnFilters'] ); |
|
| 60 | + add_action( 'admin_enqueue_scripts', [$this->admin, 'enqueueAssets'] ); |
|
| 61 | + add_action( 'admin_init', [$this->admin, 'registerTinymcePopups'] ); |
|
| 62 | + add_action( 'media_buttons', [$this->admin, 'renderTinymceButton'], 11 ); |
|
| 63 | + add_action( 'plugins_loaded', [$this->app, 'getDefaults'], 11 ); |
|
| 64 | + add_action( 'plugins_loaded', [$this->app, 'registerAddons'] ); |
|
| 65 | + add_action( 'plugins_loaded', [$this->app, 'registerLanguages'] ); |
|
| 66 | + add_action( 'plugins_loaded', [$this->app, 'registerReviewTypes'] ); |
|
| 67 | + add_action( 'upgrader_process_complete', [$this->app, 'upgraded'], 10, 2 ); |
|
| 68 | + add_action( 'init', [$this->blocks, 'registerAssets'], 9 ); |
|
| 69 | + add_action( 'init', [$this->blocks, 'registerBlocks'] ); |
|
| 70 | + add_action( 'admin_footer', [$this->console, 'logOnce'] ); |
|
| 71 | + add_action( 'wp_footer', [$this->console, 'logOnce'] ); |
|
| 72 | + add_action( 'admin_enqueue_scripts', [$this->editor, 'customizePostStatusLabels'] ); |
|
| 73 | + add_action( 'add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes'] ); |
|
| 74 | + add_action( 'admin_print_scripts', [$this->editor, 'removeAutosave'], 999 ); |
|
| 75 | + add_action( 'admin_menu', [$this->editor, 'removeMetaBoxes'] ); |
|
| 76 | + add_action( 'current_screen', [$this->editor, 'removePostTypeSupport'] ); |
|
| 77 | + add_action( 'post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox'] ); |
|
| 78 | + add_action( 'admin_head', [$this->editor, 'renderReviewFields'] ); |
|
| 79 | + add_action( 'admin_action_revert', [$this->editor, 'revertReview'] ); |
|
| 80 | + add_action( 'save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'] ); |
|
| 81 | + add_action( 'admin_action_approve', [$this->listtable, 'approve'] ); |
|
| 82 | + add_action( 'bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2 ); |
|
| 83 | + add_action( 'restrict_manage_posts', [$this->listtable, 'renderColumnFilters'] ); |
|
| 84 | 84 | add_action( 'manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2 ); |
| 85 | - add_action( 'save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields'] ); |
|
| 86 | - add_action( 'pre_get_posts', [$this->listtable, 'setQueryForColumn'] ); |
|
| 87 | - add_action( 'admin_action_unapprove', [$this->listtable, 'unapprove'] ); |
|
| 88 | - add_action( 'init', [$this->main, 'registerPostType'], 8 ); |
|
| 89 | - add_action( 'init', [$this->main, 'registerShortcodes'] ); |
|
| 90 | - add_action( 'init', [$this->main, 'registerTaxonomy'] ); |
|
| 91 | - add_action( 'widgets_init', [$this->main, 'registerWidgets'] ); |
|
| 92 | - add_action( 'admin_menu', [$this->menu, 'registerMenuCount'] ); |
|
| 93 | - add_action( 'admin_menu', [$this->menu, 'registerSubMenus'] ); |
|
| 94 | - add_action( 'admin_init', [$this->menu, 'setCustomPermissions'], 999 ); |
|
| 95 | - add_action( 'wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999 ); |
|
| 96 | - add_filter( 'site-reviews/builder', [$this->public, 'modifyBuilder'] ); |
|
| 97 | - add_action( 'wp_footer', [$this->public, 'renderSchema'] ); |
|
| 98 | - add_action( 'set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6 ); |
|
| 99 | - add_action( 'transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3 ); |
|
| 100 | - add_action( 'site-reviews/review/created', [$this->review, 'onAfterCreate'] ); |
|
| 101 | - add_action( 'before_delete_post', [$this->review, 'onBeforeDelete'] ); |
|
| 102 | - add_action( 'update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4 ); |
|
| 103 | - add_action( 'admin_init', [$this->router, 'routeAdminPostRequest'] ); |
|
| 104 | - add_action( 'wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest'] ); |
|
| 85 | + add_action( 'save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields'] ); |
|
| 86 | + add_action( 'pre_get_posts', [$this->listtable, 'setQueryForColumn'] ); |
|
| 87 | + add_action( 'admin_action_unapprove', [$this->listtable, 'unapprove'] ); |
|
| 88 | + add_action( 'init', [$this->main, 'registerPostType'], 8 ); |
|
| 89 | + add_action( 'init', [$this->main, 'registerShortcodes'] ); |
|
| 90 | + add_action( 'init', [$this->main, 'registerTaxonomy'] ); |
|
| 91 | + add_action( 'widgets_init', [$this->main, 'registerWidgets'] ); |
|
| 92 | + add_action( 'admin_menu', [$this->menu, 'registerMenuCount'] ); |
|
| 93 | + add_action( 'admin_menu', [$this->menu, 'registerSubMenus'] ); |
|
| 94 | + add_action( 'admin_init', [$this->menu, 'setCustomPermissions'], 999 ); |
|
| 95 | + add_action( 'wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999 ); |
|
| 96 | + add_filter( 'site-reviews/builder', [$this->public, 'modifyBuilder'] ); |
|
| 97 | + add_action( 'wp_footer', [$this->public, 'renderSchema'] ); |
|
| 98 | + add_action( 'set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6 ); |
|
| 99 | + add_action( 'transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3 ); |
|
| 100 | + add_action( 'site-reviews/review/created', [$this->review, 'onAfterCreate'] ); |
|
| 101 | + add_action( 'before_delete_post', [$this->review, 'onBeforeDelete'] ); |
|
| 102 | + add_action( 'update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4 ); |
|
| 103 | + add_action( 'admin_init', [$this->router, 'routeAdminPostRequest'] ); |
|
| 104 | + add_action( 'wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest'] ); |
|
| 105 | 105 | add_action( 'wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest'] ); |
| 106 | - add_action( 'init', [$this->router, 'routePublicPostRequest'] ); |
|
| 107 | - add_action( 'site-reviews/schedule/session/purge', [$this->session, 'deleteExpiredSessions'] ); |
|
| 108 | - add_action( 'admin_init', [$this->settings, 'registerSettings'] ); |
|
| 109 | - add_action( Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents'] ); |
|
| 110 | - add_action( Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents'] ); |
|
| 111 | - add_action( Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents'] ); |
|
| 112 | - add_action( Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents'] ); |
|
| 113 | - add_action( 'restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9 ); |
|
| 114 | - add_action( 'set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6 ); |
|
| 106 | + add_action( 'init', [$this->router, 'routePublicPostRequest'] ); |
|
| 107 | + add_action( 'site-reviews/schedule/session/purge', [$this->session, 'deleteExpiredSessions'] ); |
|
| 108 | + add_action( 'admin_init', [$this->settings, 'registerSettings'] ); |
|
| 109 | + add_action( Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents'] ); |
|
| 110 | + add_action( Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents'] ); |
|
| 111 | + add_action( Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents'] ); |
|
| 112 | + add_action( Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents'] ); |
|
| 113 | + add_action( 'restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9 ); |
|
| 114 | + add_action( 'set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6 ); |
|
| 115 | 115 | } |
| 116 | 116 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | public function send() |
| 74 | 74 | { |
| 75 | 75 | if( !$this->message || !$this->subject || !$this->to )return; |
| 76 | - add_action( 'wp_mail_failed', [$this, 'logMailError']); |
|
| 76 | + add_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
| 77 | 77 | $sent = wp_mail( |
| 78 | 78 | $this->to, |
| 79 | 79 | $this->subject, |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $this->headers, |
| 82 | 82 | $this->attachments |
| 83 | 83 | ); |
| 84 | - remove_action( 'wp_mail_failed', [$this, 'logMailError']); |
|
| 84 | + remove_action( 'wp_mail_failed', [$this, 'logMailError'] ); |
|
| 85 | 85 | $this->reset(); |
| 86 | 86 | return $sent; |
| 87 | 87 | } |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function buildPlainTextMessage( PHPMailer $phpmailer ) |
| 94 | 94 | { |
| 95 | - if( empty( $this->email ))return; |
|
| 96 | - if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return; |
|
| 95 | + if( empty($this->email) )return; |
|
| 96 | + if( $phpmailer->ContentType === 'text/plain' || !empty($phpmailer->AltBody) )return; |
|
| 97 | 97 | $message = $this->stripHtmlTags( $phpmailer->Body ); |
| 98 | 98 | $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
| 99 | 99 | } |
@@ -106,10 +106,10 @@ discard block |
||
| 106 | 106 | $allowed = [ |
| 107 | 107 | 'bcc', 'cc', 'from', 'reply-to', |
| 108 | 108 | ]; |
| 109 | - $headers = array_intersect_key( $this->email, array_flip( $allowed )); |
|
| 109 | + $headers = array_intersect_key( $this->email, array_flip( $allowed ) ); |
|
| 110 | 110 | $headers = array_filter( $headers ); |
| 111 | 111 | foreach( $headers as $key => $value ) { |
| 112 | - unset( $headers[$key] ); |
|
| 112 | + unset($headers[$key]); |
|
| 113 | 113 | $headers[] = $key.': '.$value; |
| 114 | 114 | } |
| 115 | 115 | $headers[] = 'Content-Type: text/html'; |
@@ -121,16 +121,16 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | protected function buildHtmlMessage() |
| 123 | 123 | { |
| 124 | - $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' )); |
|
| 125 | - if( !empty( $template )) { |
|
| 124 | + $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) ); |
|
| 125 | + if( !empty($template) ) { |
|
| 126 | 126 | $message = glsr( Template::class )->interpolate( $template, $this->email['template-tags'], $this->email['template'] ); |
| 127 | 127 | } |
| 128 | 128 | else if( $this->email['template'] ) { |
| 129 | 129 | $message = glsr( Template::class )->build( 'templates/'.$this->email['template'], [ |
| 130 | 130 | 'context' => $this->email['template-tags'], |
| 131 | - ]); |
|
| 131 | + ] ); |
|
| 132 | 132 | } |
| 133 | - if( !isset( $message )) { |
|
| 133 | + if( !isset($message) ) { |
|
| 134 | 134 | $message = $this->email['message']; |
| 135 | 135 | } |
| 136 | 136 | $message = $this->email['before'].$message.$this->email['after']; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $message = str_replace( ']]>', ']]>', $message ); |
| 142 | 142 | $message = glsr( Template::class )->build( 'partials/email/index', [ |
| 143 | 143 | 'context' => ['message' => $message], |
| 144 | - ]); |
|
| 144 | + ] ); |
|
| 145 | 145 | return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this ); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | protected function normalize( array $email = [] ) |
| 163 | 163 | { |
| 164 | 164 | $email = shortcode_atts( glsr( EmailDefaults::class )->defaults(), $email ); |
| 165 | - if( empty( $email['reply-to'] )) { |
|
| 165 | + if( empty($email['reply-to']) ) { |
|
| 166 | 166 | $email['reply-to'] = $email['from']; |
| 167 | 167 | } |
| 168 | 168 | $this->email = apply_filters( 'site-reviews/email/compose', $email, $this ); |
@@ -72,7 +72,9 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function send() |
| 74 | 74 | { |
| 75 | - if( !$this->message || !$this->subject || !$this->to )return; |
|
| 75 | + if( !$this->message || !$this->subject || !$this->to ) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 76 | 78 | add_action( 'wp_mail_failed', [$this, 'logMailError']); |
| 77 | 79 | $sent = wp_mail( |
| 78 | 80 | $this->to, |
@@ -92,8 +94,12 @@ discard block |
||
| 92 | 94 | */ |
| 93 | 95 | public function buildPlainTextMessage( PHPMailer $phpmailer ) |
| 94 | 96 | { |
| 95 | - if( empty( $this->email ))return; |
|
| 96 | - if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return; |
|
| 97 | + if( empty( $this->email )) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 100 | + if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody )) { |
|
| 101 | + return; |
|
| 102 | + } |
|
| 97 | 103 | $message = $this->stripHtmlTags( $phpmailer->Body ); |
| 98 | 104 | $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
| 99 | 105 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public function __construct() |
| 34 | 34 | { |
| 35 | 35 | $types = glsr( OptionManager::class )->get( 'settings.general.notifications', [] ); |
| 36 | - $this->email = count( array_intersect( ['admin', 'custom'], $types )) > 0; |
|
| 36 | + $this->email = count( array_intersect( ['admin', 'custom'], $types ) ) > 0; |
|
| 37 | 37 | $this->slack = in_array( 'slack', $types ); |
| 38 | 38 | $this->types = $types; |
| 39 | 39 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function send( Review $review ) |
| 45 | 45 | { |
| 46 | - if( empty( $this->types ))return; |
|
| 46 | + if( empty($this->types) )return; |
|
| 47 | 47 | $this->review = $review; |
| 48 | 48 | $args = [ |
| 49 | 49 | 'link' => $this->getLink(), |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | protected function buildEmail( array $args ) |
| 60 | 60 | { |
| 61 | - return glsr( Email::class )->compose([ |
|
| 61 | + return glsr( Email::class )->compose( [ |
|
| 62 | 62 | 'to' => $this->getEmailAddresses(), |
| 63 | 63 | 'subject' => $args['title'], |
| 64 | 64 | 'template' => 'email-notification', |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | 'review_rating' => $this->review->rating, |
| 72 | 72 | 'review_title' => $this->review->title, |
| 73 | 73 | ], |
| 74 | - ]); |
|
| 74 | + ] ); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | 'button_url' => $args['link'], |
| 84 | 84 | 'fallback' => $this->buildEmail( $args )->read( 'plaintext' ), |
| 85 | 85 | 'pretext' => $args['title'], |
| 86 | - ]); |
|
| 86 | + ] ); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -92,23 +92,23 @@ discard block |
||
| 92 | 92 | protected function getEmailAddresses() |
| 93 | 93 | { |
| 94 | 94 | $emails = []; |
| 95 | - if( in_array( 'admin', $this->types )) { |
|
| 95 | + if( in_array( 'admin', $this->types ) ) { |
|
| 96 | 96 | $emails[] = get_option( 'admin_email' ); |
| 97 | 97 | } |
| 98 | - if( in_array( 'author', $this->types )) { |
|
| 99 | - $assignedPost = get_post( intval( $this->review->assigned_to )); |
|
| 98 | + if( in_array( 'author', $this->types ) ) { |
|
| 99 | + $assignedPost = get_post( intval( $this->review->assigned_to ) ); |
|
| 100 | 100 | if( $assignedPost instanceof WP_Post ) { |
| 101 | 101 | $this->email = true; |
| 102 | - $emails[] = get_the_author_meta( 'user_email', intval( $assignedPost->post_author )); |
|
| 102 | + $emails[] = get_the_author_meta( 'user_email', intval( $assignedPost->post_author ) ); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | - if( in_array( 'custom', $this->types )) { |
|
| 105 | + if( in_array( 'custom', $this->types ) ) { |
|
| 106 | 106 | $customEmails = glsr( OptionManager::class )->get( 'settings.general.notification_email' ); |
| 107 | 107 | $customEmails = str_replace( [' ', ',', ';'], ',', $customEmails ); |
| 108 | 108 | $customEmails = explode( ',', $customEmails ); |
| 109 | 109 | $emails = array_merge( $emails, $customEmails ); |
| 110 | 110 | } |
| 111 | - $emails = array_filter( array_keys( array_flip( $emails ))); |
|
| 111 | + $emails = array_filter( array_keys( array_flip( $emails ) ) ); |
|
| 112 | 112 | return apply_filters( 'site-reviews/notification/emails', $emails, $this->review ); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | protected function getTitle() |
| 127 | 127 | { |
| 128 | - $assignedTitle = get_the_title( intval( $this->review->assigned_to )); |
|
| 128 | + $assignedTitle = get_the_title( intval( $this->review->assigned_to ) ); |
|
| 129 | 129 | $title = _nx( |
| 130 | 130 | 'New %s-star review', |
| 131 | 131 | 'New %s-star review of: %s', |
| 132 | - intval( empty( $assignedTitle )), |
|
| 132 | + intval( empty($assignedTitle) ), |
|
| 133 | 133 | 'This string differs depending on whether or not the review has been assigned to a post.', |
| 134 | 134 | 'site-reviews' |
| 135 | 135 | ); |
| 136 | 136 | $title = sprintf( '[%s] %s', |
| 137 | - wp_specialchars_decode( strval( get_option( 'blogname' )), ENT_QUOTES ), |
|
| 137 | + wp_specialchars_decode( strval( get_option( 'blogname' ) ), ENT_QUOTES ), |
|
| 138 | 138 | sprintf( $title, $this->review->rating, $assignedTitle ) |
| 139 | 139 | ); |
| 140 | 140 | return apply_filters( 'site-reviews/notification/title', $title, $this->review ); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | protected function sendToEmail( array $args ) |
| 147 | 147 | { |
| 148 | 148 | $email = $this->buildEmail( $args ); |
| 149 | - if( empty( $email->to )) { |
|
| 149 | + if( empty($email->to) ) { |
|
| 150 | 150 | glsr_log()->error( 'Email notification was not sent (missing email address)' ); |
| 151 | 151 | return; |
| 152 | 152 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | if( !$this->slack )return; |
| 162 | 162 | $notification = $this->buildSlackNotification( $args ); |
| 163 | 163 | $result = $notification->send(); |
| 164 | - if( is_wp_error( $result )) { |
|
| 164 | + if( is_wp_error( $result ) ) { |
|
| 165 | 165 | $notification->review = null; |
| 166 | 166 | glsr_log()->error( $result->get_error_message() )->debug( $notification ); |
| 167 | 167 | } |
@@ -43,7 +43,9 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function send( Review $review ) |
| 45 | 45 | { |
| 46 | - if( empty( $this->types ))return; |
|
| 46 | + if( empty( $this->types )) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 47 | 49 | $this->review = $review; |
| 48 | 50 | $args = [ |
| 49 | 51 | 'link' => $this->getLink(), |
@@ -158,7 +160,9 @@ discard block |
||
| 158 | 160 | */ |
| 159 | 161 | protected function sendToSlack( array $args ) |
| 160 | 162 | { |
| 161 | - if( !$this->slack )return; |
|
| 163 | + if( !$this->slack ) { |
|
| 164 | + return; |
|
| 165 | + } |
|
| 162 | 166 | $notification = $this->buildSlackNotification( $args ); |
| 163 | 167 | $result = $notification->send(); |
| 164 | 168 | if( is_wp_error( $result )) { |
@@ -22,11 +22,11 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function deleteAllSessions( $sessionCookiePrefix ) |
| 24 | 24 | { |
| 25 | - return $this->db->query(" |
|
| 25 | + return $this->db->query( " |
|
| 26 | 26 | DELETE |
| 27 | 27 | FROM {$this->db->options} |
| 28 | 28 | WHERE option_name LIKE '{$sessionCookiePrefix}_%' |
| 29 | - "); |
|
| 29 | + " ); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function deleteExpiredSessions( $expiredSessions ) |
| 37 | 37 | { |
| 38 | - return $this->db->query(" |
|
| 38 | + return $this->db->query( " |
|
| 39 | 39 | DELETE |
| 40 | 40 | FROM {$this->db->options} |
| 41 | 41 | WHERE option_name IN ('{$expiredSessions}') |
| 42 | - "); |
|
| 42 | + " ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function getExpiredSessions( $sessionCookiePrefix, $limit ) |
| 51 | 51 | { |
| 52 | - return (array) $this->db->get_results(" |
|
| 52 | + return (array)$this->db->get_results( " |
|
| 53 | 53 | SELECT option_name AS name, option_value AS expiration |
| 54 | 54 | FROM {$this->db->options} |
| 55 | 55 | WHERE option_name LIKE '{$sessionCookiePrefix}_expires_%' |
| 56 | 56 | ORDER BY option_value ASC |
| 57 | 57 | LIMIT 0, {$limit} |
| 58 | - "); |
|
| 58 | + " ); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -64,14 +64,14 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function getPostIdFromReviewId( $metaReviewId ) |
| 66 | 66 | { |
| 67 | - $postId = $this->db->get_var(" |
|
| 67 | + $postId = $this->db->get_var( " |
|
| 68 | 68 | SELECT p.ID |
| 69 | 69 | FROM {$this->db->posts} AS p |
| 70 | 70 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
| 71 | 71 | WHERE p.post_type = '{$this->postType}' |
| 72 | 72 | AND m.meta_key = 'review_id' |
| 73 | 73 | AND m.meta_value = '{$metaReviewId}' |
| 74 | - "); |
|
| 74 | + " ); |
|
| 75 | 75 | return intval( $postId ); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 ) |
| 84 | 84 | { |
| 85 | - return (array) $this->db->get_results(" |
|
| 85 | + return (array)$this->db->get_results( " |
|
| 86 | 86 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
| 87 | 87 | FROM {$this->db->posts} AS p |
| 88 | 88 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | {$this->getAndForCounts( $args )} |
| 97 | 97 | ORDER By p.ID ASC |
| 98 | 98 | LIMIT {$limit} |
| 99 | - "); |
|
| 99 | + " ); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,14 +106,14 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function getReviewCountsFor( $metaKey ) |
| 108 | 108 | { |
| 109 | - return (array) $this->db->get_results(" |
|
| 109 | + return (array)$this->db->get_results( " |
|
| 110 | 110 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
| 111 | 111 | FROM {$this->db->posts} AS p |
| 112 | 112 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
| 113 | 113 | WHERE p.post_type = '{$this->postType}' |
| 114 | 114 | AND m.meta_key = '{$metaKey}' |
| 115 | 115 | GROUP BY name |
| 116 | - "); |
|
| 116 | + " ); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function getReviewIdsByType( $reviewType ) |
| 125 | 125 | { |
| 126 | - $results = $this->db->get_col(" |
|
| 126 | + $results = $this->db->get_col( " |
|
| 127 | 127 | SELECT DISTINCT m1.meta_value AS review_id |
| 128 | 128 | FROM {$this->db->posts} AS p |
| 129 | 129 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | AND m1.meta_key = 'review_id' |
| 133 | 133 | AND m2.meta_key = 'review_type' |
| 134 | 134 | AND m2.meta_value = '{$reviewType}' |
| 135 | - "); |
|
| 136 | - return array_keys( array_flip( $results )); |
|
| 135 | + " ); |
|
| 136 | + return array_keys( array_flip( $results ) ); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -144,9 +144,9 @@ discard block |
||
| 144 | 144 | public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
| 145 | 145 | { |
| 146 | 146 | sort( $postIds ); |
| 147 | - $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds )), $limit ); |
|
| 147 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
| 148 | 148 | $postIds = implode( ',', $postIds ); |
| 149 | - return (array) $this->db->get_results(" |
|
| 149 | + return (array)$this->db->get_results( " |
|
| 150 | 150 | SELECT p.ID, m.meta_value AS rating |
| 151 | 151 | FROM {$this->db->posts} AS p |
| 152 | 152 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | GROUP BY p.ID |
| 159 | 159 | ORDER By p.ID ASC |
| 160 | 160 | LIMIT {$limit} |
| 161 | - "); |
|
| 161 | + " ); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | public function getReviewsMeta( $key, $status = 'publish' ) |
| 170 | 170 | { |
| 171 | - $values = $this->db->get_col(" |
|
| 171 | + $values = $this->db->get_col( " |
|
| 172 | 172 | SELECT DISTINCT m.meta_value |
| 173 | 173 | FROM {$this->db->postmeta} m |
| 174 | 174 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | AND p.post_status = '{$status}' |
| 179 | 179 | GROUP BY p.ID -- remove duplicate meta_value entries |
| 180 | 180 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
| 181 | - "); |
|
| 181 | + " ); |
|
| 182 | 182 | sort( $values ); |
| 183 | 183 | return $values; |
| 184 | 184 | } |
@@ -189,16 +189,16 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | protected function getAndForCounts( array $args, $and = '' ) |
| 191 | 191 | { |
| 192 | - $postIds = implode( ',', array_filter( $args['post_ids'] )); |
|
| 193 | - $termIds = implode( ',', array_filter( $args['term_ids'] )); |
|
| 194 | - if( !empty( $args['type'] )) { |
|
| 195 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
| 192 | + $postIds = implode( ',', array_filter( $args['post_ids'] ) ); |
|
| 193 | + $termIds = implode( ',', array_filter( $args['term_ids'] ) ); |
|
| 194 | + if( !empty($args['type']) ) { |
|
| 195 | + $and .= "AND m2.meta_value = '{$args['type']}' "; |
|
| 196 | 196 | } |
| 197 | 197 | if( $postIds ) { |
| 198 | - $and.= "AND m3.meta_key = 'assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
| 198 | + $and .= "AND m3.meta_key = 'assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
| 199 | 199 | } |
| 200 | 200 | if( $termIds ) { |
| 201 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
| 201 | + $and .= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
| 202 | 202 | } |
| 203 | 203 | return $and; |
| 204 | 204 | } |
@@ -209,11 +209,11 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | protected function getInnerJoinForCounts( array $args, $innerJoin = '' ) |
| 211 | 211 | { |
| 212 | - if( !empty( $args['post_ids'] )) { |
|
| 213 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
| 212 | + if( !empty($args['post_ids']) ) { |
|
| 213 | + $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
| 214 | 214 | } |
| 215 | - if( !empty( $args['term_ids'] )) { |
|
| 216 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
| 215 | + if( !empty($args['term_ids']) ) { |
|
| 216 | + $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
| 217 | 217 | } |
| 218 | 218 | return $innerJoin; |
| 219 | 219 | } |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | $query = $this->queryReviews( $args ); |
| 31 | 31 | while( $query ) { |
| 32 | 32 | // glsr_log($query); |
| 33 | - $types = array_keys( array_flip( glsr_array_column( $query->reviews, 'type' ))); |
|
| 34 | - $types = array_unique( array_merge( ['local'], $types )); |
|
| 33 | + $types = array_keys( array_flip( glsr_array_column( $query->reviews, 'type' ) ) ); |
|
| 34 | + $types = array_unique( array_merge( ['local'], $types ) ); |
|
| 35 | 35 | foreach( $types as $type ) { |
| 36 | 36 | $type = $this->normalizeType( $type ); |
| 37 | - if( isset( $counts[$type] ))continue; |
|
| 37 | + if( isset($counts[$type]) )continue; |
|
| 38 | 38 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 39 | 39 | } |
| 40 | 40 | foreach( $query->reviews as $review ) { |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $terms = glsr( Database::class )->getTerms( ['fields' => 'all'] ); |
| 75 | 75 | foreach( $terms as $term ) { |
| 76 | - $this->setTermCounts( $term->term_id, $this->buildTermCounts( $term->term_taxonomy_id )); |
|
| 76 | + $this->setTermCounts( $term->term_id, $this->buildTermCounts( $term->term_taxonomy_id ) ); |
|
| 77 | 77 | } |
| 78 | 78 | $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
| 79 | 79 | foreach( $postIds as $postId ) { |
| 80 | - $this->setPostCounts( $postId, $this->buildPostCounts( $postId )); |
|
| 80 | + $this->setPostCounts( $postId, $this->buildPostCounts( $postId ) ); |
|
| 81 | 81 | } |
| 82 | 82 | $this->setCounts( $this->buildCounts() ); |
| 83 | 83 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->getCounts(), |
| 102 | 102 | $review->review_type, |
| 103 | 103 | $review->rating |
| 104 | - )); |
|
| 104 | + ) ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public function decreasePostCounts( Review $review ) |
| 111 | 111 | { |
| 112 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 112 | + if( empty($counts = $this->getPostCounts( $review->assigned_to )) )return; |
|
| 113 | 113 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 114 | 114 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 115 | 115 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | public function decreaseTermCounts( Review $review ) |
| 121 | 121 | { |
| 122 | 122 | foreach( $review->term_ids as $termId ) { |
| 123 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 123 | + if( empty($counts = $this->getTermCounts( $termId )) )continue; |
|
| 124 | 124 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 125 | 125 | $this->setTermCounts( $termId, $counts ); |
| 126 | 126 | } |
@@ -132,15 +132,15 @@ discard block |
||
| 132 | 132 | public function flatten( array $reviewCounts, array $args = [] ) |
| 133 | 133 | { |
| 134 | 134 | $counts = []; |
| 135 | - array_walk_recursive( $reviewCounts, function( $num, $index ) use( &$counts ) { |
|
| 136 | - $counts[$index] = $num + intval( glsr_get( $counts, $index, 0 )); |
|
| 135 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use(&$counts) { |
|
| 136 | + $counts[$index] = $num + intval( glsr_get( $counts, $index, 0 ) ); |
|
| 137 | 137 | }); |
| 138 | 138 | $args = wp_parse_args( $args, [ |
| 139 | 139 | 'max' => Rating::MAX_RATING, |
| 140 | 140 | 'min' => Rating::MIN_RATING, |
| 141 | - ]); |
|
| 141 | + ] ); |
|
| 142 | 142 | foreach( $counts as $index => &$num ) { |
| 143 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 143 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ) )continue; |
|
| 144 | 144 | $num = 0; |
| 145 | 145 | } |
| 146 | 146 | return $counts; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | { |
| 154 | 154 | $args = $this->normalizeArgs( $args ); |
| 155 | 155 | $counts = []; |
| 156 | - if( $this->isMixedCount( $args )) { |
|
| 156 | + if( $this->isMixedCount( $args ) ) { |
|
| 157 | 157 | $counts = [$this->buildCounts( $args )]; // force query the database |
| 158 | 158 | } |
| 159 | 159 | else { |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | foreach( $args['term_ids'] as $termId ) { |
| 164 | 164 | $counts[] = $this->getTermCounts( $termId ); |
| 165 | 165 | } |
| 166 | - if( empty( $counts )) { |
|
| 166 | + if( empty($counts) ) { |
|
| 167 | 167 | $counts[] = $this->getCounts(); |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | return in_array( $args['type'], ['', 'all'] ) |
| 171 | 171 | ? $this->normalize( [$this->flatten( $counts )] ) |
| 172 | - : $this->normalize( glsr_array_column( $counts, $args['type'] )); |
|
| 172 | + : $this->normalize( glsr_array_column( $counts, $args['type'] ) ); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | public function getCounts() |
| 179 | 179 | { |
| 180 | 180 | $counts = glsr( OptionManager::class )->get( 'counts', [] ); |
| 181 | - if( !is_array( $counts )) { |
|
| 181 | + if( !is_array( $counts ) ) { |
|
| 182 | 182 | glsr_log()->error( '$counts is not an array' )->debug( $counts ); |
| 183 | 183 | return []; |
| 184 | 184 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function getPostCounts( $postId ) |
| 193 | 193 | { |
| 194 | - return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true )); |
|
| 194 | + return array_filter( (array)get_post_meta( $postId, static::META_COUNT, true ) ); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | public function getTermCounts( $termId ) |
| 202 | 202 | { |
| 203 | - return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true )); |
|
| 203 | + return array_filter( (array)get_term_meta( $termId, static::META_COUNT, true ) ); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -218,10 +218,10 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | public function increaseCounts( Review $review ) |
| 220 | 220 | { |
| 221 | - if( empty( $counts = $this->getCounts() )) { |
|
| 221 | + if( empty($counts = $this->getCounts()) ) { |
|
| 222 | 222 | $counts = $this->buildCounts(); |
| 223 | 223 | } |
| 224 | - $this->setCounts( $this->increaseRating( $counts, $review->review_type, $review->rating )); |
|
| 224 | + $this->setCounts( $this->increaseRating( $counts, $review->review_type, $review->rating ) ); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -229,9 +229,9 @@ discard block |
||
| 229 | 229 | */ |
| 230 | 230 | public function increasePostCounts( Review $review ) |
| 231 | 231 | { |
| 232 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 232 | + if( !(get_post( $review->assigned_to ) instanceof WP_Post) )return; |
|
| 233 | 233 | $counts = $this->getPostCounts( $review->assigned_to ); |
| 234 | - $counts = empty( $counts ) |
|
| 234 | + $counts = empty($counts) |
|
| 235 | 235 | ? $this->buildPostCounts( $review->assigned_to ) |
| 236 | 236 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
| 237 | 237 | $this->setPostCounts( $review->assigned_to, $counts ); |
@@ -242,10 +242,10 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | public function increaseTermCounts( Review $review ) |
| 244 | 244 | { |
| 245 | - $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids )); |
|
| 245 | + $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
| 246 | 246 | foreach( $terms as $term ) { |
| 247 | 247 | $counts = $this->getTermCounts( $term['term_id'] ); |
| 248 | - $counts = empty( $counts ) |
|
| 248 | + $counts = empty($counts) |
|
| 249 | 249 | ? $this->buildTermCounts( $term['term_taxonomy_id'] ) |
| 250 | 250 | : $this->increaseRating( $counts, $review->review_type, $review->rating ); |
| 251 | 251 | $this->setTermCounts( $term['term_id'], $counts ); |
@@ -268,8 +268,8 @@ discard block |
||
| 268 | 268 | { |
| 269 | 269 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 270 | 270 | update_post_meta( $postId, static::META_COUNT, $reviewCounts ); |
| 271 | - update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 272 | - update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 271 | + update_post_meta( $postId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 272 | + update_post_meta( $postId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | public function setTermCounts( $termId, array $reviewCounts ) |
| 280 | 280 | { |
| 281 | 281 | $term = get_term( $termId, Application::TAXONOMY ); |
| 282 | - if( !isset( $term->term_id ))return; |
|
| 282 | + if( !isset($term->term_id) )return; |
|
| 283 | 283 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 284 | 284 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 285 | - update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
|
| 286 | - update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts )); |
|
| 285 | + update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
| 286 | + update_term_meta( $termId, static::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | protected function decreaseRating( array $reviewCounts, $type, $rating ) |
| 295 | 295 | { |
| 296 | - if( isset( $reviewCounts[$type][$rating] )) { |
|
| 296 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
| 297 | 297 | $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
| 298 | 298 | } |
| 299 | 299 | return $reviewCounts; |
@@ -306,10 +306,10 @@ discard block |
||
| 306 | 306 | */ |
| 307 | 307 | protected function increaseRating( array $reviewCounts, $type, $rating ) |
| 308 | 308 | { |
| 309 | - if( !array_key_exists( $type, glsr()->reviewTypes )) { |
|
| 309 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
| 310 | 310 | return $reviewCounts; |
| 311 | 311 | } |
| 312 | - if( !array_key_exists( $type, $reviewCounts )) { |
|
| 312 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
| 313 | 313 | $reviewCounts[$type] = []; |
| 314 | 314 | } |
| 315 | 315 | $reviewCounts = $this->normalize( $reviewCounts ); |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | protected function isMixedCount( array $args ) |
| 324 | 324 | { |
| 325 | - return !empty( $args['post_ids'] ) && !empty( $args['term_ids'] ); |
|
| 325 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -330,12 +330,12 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | protected function normalize( array $reviewCounts ) |
| 332 | 332 | { |
| 333 | - if( empty( $reviewCounts )) { |
|
| 333 | + if( empty($reviewCounts) ) { |
|
| 334 | 334 | $reviewCounts = [[]]; |
| 335 | 335 | } |
| 336 | 336 | foreach( $reviewCounts as &$counts ) { |
| 337 | 337 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 338 | - if( isset( $counts[$index] ))continue; |
|
| 338 | + if( isset($counts[$index]) )continue; |
|
| 339 | 339 | $counts[$index] = 0; |
| 340 | 340 | } |
| 341 | 341 | ksort( $counts ); |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | 'post_ids' => [], |
| 353 | 353 | 'term_ids' => [], |
| 354 | 354 | 'type' => 'local', |
| 355 | - ]); |
|
| 355 | + ] ); |
|
| 356 | 356 | $args['post_ids'] = glsr( Polylang::class )->getPostIds( $args['post_ids'] ); |
| 357 | 357 | $args['type'] = $this->normalizeType( $args['type'] ); |
| 358 | 358 | return $args; |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | */ |
| 365 | 365 | protected function normalizeType( $type ) |
| 366 | 366 | { |
| 367 | - return empty( $type ) || !is_string( $type ) |
|
| 367 | + return empty($type) || !is_string( $type ) |
|
| 368 | 368 | ? 'local' |
| 369 | 369 | : $type; |
| 370 | 370 | } |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | $hasMore = is_array( $reviews ) |
| 380 | 380 | ? count( $reviews ) == static::LIMIT |
| 381 | 381 | : false; |
| 382 | - return (object) [ |
|
| 382 | + return (object)[ |
|
| 383 | 383 | 'has_more' => $hasMore, |
| 384 | 384 | 'reviews' => $reviews, |
| 385 | 385 | ]; |
@@ -34,7 +34,9 @@ discard block |
||
| 34 | 34 | $types = array_unique( array_merge( ['local'], $types )); |
| 35 | 35 | foreach( $types as $type ) { |
| 36 | 36 | $type = $this->normalizeType( $type ); |
| 37 | - if( isset( $counts[$type] ))continue; |
|
| 37 | + if( isset( $counts[$type] )) { |
|
| 38 | + continue; |
|
| 39 | + } |
|
| 38 | 40 | $counts[$type] = array_fill_keys( range( 0, Rating::MAX_RATING ), 0 ); |
| 39 | 41 | } |
| 40 | 42 | foreach( $query->reviews as $review ) { |
@@ -109,7 +111,9 @@ discard block |
||
| 109 | 111 | */ |
| 110 | 112 | public function decreasePostCounts( Review $review ) |
| 111 | 113 | { |
| 112 | - if( empty( $counts = $this->getPostCounts( $review->assigned_to )))return; |
|
| 114 | + if( empty( $counts = $this->getPostCounts( $review->assigned_to ))) { |
|
| 115 | + return; |
|
| 116 | + } |
|
| 113 | 117 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 114 | 118 | $this->setPostCounts( $review->assigned_to, $counts ); |
| 115 | 119 | } |
@@ -120,7 +124,9 @@ discard block |
||
| 120 | 124 | public function decreaseTermCounts( Review $review ) |
| 121 | 125 | { |
| 122 | 126 | foreach( $review->term_ids as $termId ) { |
| 123 | - if( empty( $counts = $this->getTermCounts( $termId )))continue; |
|
| 127 | + if( empty( $counts = $this->getTermCounts( $termId ))) { |
|
| 128 | + continue; |
|
| 129 | + } |
|
| 124 | 130 | $counts = $this->decreaseRating( $counts, $review->review_type, $review->rating ); |
| 125 | 131 | $this->setTermCounts( $termId, $counts ); |
| 126 | 132 | } |
@@ -140,7 +146,9 @@ discard block |
||
| 140 | 146 | 'min' => Rating::MIN_RATING, |
| 141 | 147 | ]); |
| 142 | 148 | foreach( $counts as $index => &$num ) { |
| 143 | - if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] ))continue; |
|
| 149 | + if( $index >= intval( $args['min'] ) && $index <= intval( $args['max'] )) { |
|
| 150 | + continue; |
|
| 151 | + } |
|
| 144 | 152 | $num = 0; |
| 145 | 153 | } |
| 146 | 154 | return $counts; |
@@ -229,7 +237,9 @@ discard block |
||
| 229 | 237 | */ |
| 230 | 238 | public function increasePostCounts( Review $review ) |
| 231 | 239 | { |
| 232 | - if( !( get_post( $review->assigned_to ) instanceof WP_Post ))return; |
|
| 240 | + if( !( get_post( $review->assigned_to ) instanceof WP_Post )) { |
|
| 241 | + return; |
|
| 242 | + } |
|
| 233 | 243 | $counts = $this->getPostCounts( $review->assigned_to ); |
| 234 | 244 | $counts = empty( $counts ) |
| 235 | 245 | ? $this->buildPostCounts( $review->assigned_to ) |
@@ -279,7 +289,9 @@ discard block |
||
| 279 | 289 | public function setTermCounts( $termId, array $reviewCounts ) |
| 280 | 290 | { |
| 281 | 291 | $term = get_term( $termId, Application::TAXONOMY ); |
| 282 | - if( !isset( $term->term_id ))return; |
|
| 292 | + if( !isset( $term->term_id )) { |
|
| 293 | + return; |
|
| 294 | + } |
|
| 283 | 295 | $ratingCounts = $this->flatten( $reviewCounts ); |
| 284 | 296 | update_term_meta( $termId, static::META_COUNT, $reviewCounts ); |
| 285 | 297 | update_term_meta( $termId, static::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts )); |
@@ -335,7 +347,9 @@ discard block |
||
| 335 | 347 | } |
| 336 | 348 | foreach( $reviewCounts as &$counts ) { |
| 337 | 349 | foreach( range( 0, Rating::MAX_RATING ) as $index ) { |
| 338 | - if( isset( $counts[$index] ))continue; |
|
| 350 | + if( isset( $counts[$index] )) { |
|
| 351 | + continue; |
|
| 352 | + } |
|
| 339 | 353 | $counts[$index] = 0; |
| 340 | 354 | } |
| 341 | 355 | ksort( $counts ); |