@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | { |
| 31 | 31 | $translations = $this->translations(); |
| 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->translations(); |
| 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 ); |
@@ -96,17 +96,17 @@ discard block |
||
| 96 | 96 | public function render( $template, array $entry ) |
| 97 | 97 | { |
| 98 | 98 | $data = array_combine( |
| 99 | - array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry )), |
|
| 99 | + array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ), |
|
| 100 | 100 | $entry |
| 101 | 101 | ); |
| 102 | 102 | $data['data.class'] = $data['data.error'] = ''; |
| 103 | - if( array_search( $entry['s1'], array_column( $this->entries(), 'msgid' )) === false ) { |
|
| 103 | + if( array_search( $entry['s1'], array_column( $this->entries(), 'msgid' ) ) === false ) { |
|
| 104 | 104 | $data['data.class'] = 'is-invalid'; |
| 105 | 105 | $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' ); |
| 106 | 106 | } |
| 107 | 107 | return glsr( Template::class )->build( 'partials/translations/'.$template, [ |
| 108 | 108 | 'context' => $data, |
| 109 | - ]); |
|
| 109 | + ] ); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -138,13 +138,13 @@ discard block |
||
| 138 | 138 | 'p1' => $this->getEntryString( $entry, 'msgid_plural' ), |
| 139 | 139 | 's1' => $this->getEntryString( $entry, 'msgid' ), |
| 140 | 140 | ]; |
| 141 | - $text = !empty( $data['p1'] ) |
|
| 141 | + $text = !empty($data['p1']) |
|
| 142 | 142 | ? sprintf( '%s | %s', $data['s1'], $data['p1'] ) |
| 143 | 143 | : $data['s1']; |
| 144 | 144 | $rendered .= $this->render( 'result', [ |
| 145 | - 'entry' => json_encode( $data, JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_TAG|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE ), |
|
| 145 | + 'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ), |
|
| 146 | 146 | 'text' => wp_strip_all_tags( $text ), |
| 147 | - ]); |
|
| 147 | + ] ); |
|
| 148 | 148 | } |
| 149 | 149 | if( $resetAfterRender ) { |
| 150 | 150 | $this->reset(); |
@@ -177,12 +177,12 @@ discard block |
||
| 177 | 177 | public function search( $needle = '' ) |
| 178 | 178 | { |
| 179 | 179 | $this->reset(); |
| 180 | - $needle = trim( strtolower( $needle )); |
|
| 180 | + $needle = trim( strtolower( $needle ) ); |
|
| 181 | 181 | foreach( $this->entries() as $key => $entry ) { |
| 182 | - $single = strtolower( $this->getEntryString( $entry, 'msgid' )); |
|
| 183 | - $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' )); |
|
| 182 | + $single = strtolower( $this->getEntryString( $entry, 'msgid' ) ); |
|
| 183 | + $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) ); |
|
| 184 | 184 | if( strlen( $needle ) < static::SEARCH_THRESHOLD ) { |
| 185 | - if( in_array( $needle, [$single, $plural] )) { |
|
| 185 | + if( in_array( $needle, [$single, $plural] ) ) { |
|
| 186 | 186 | $this->results[$key] = $entry; |
| 187 | 187 | } |
| 188 | 188 | } |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | public function translations() |
| 201 | 201 | { |
| 202 | 202 | static $translations; |
| 203 | - if( empty( $translations )) { |
|
| 203 | + if( empty($translations) ) { |
|
| 204 | 204 | $settings = glsr( OptionManager::class )->get( 'settings' ); |
| 205 | - $translations = isset( $settings['strings'] ) |
|
| 206 | - ? $this->normalizeSettings( (array) $settings['strings'] ) |
|
| 205 | + $translations = isset($settings['strings']) |
|
| 206 | + ? $this->normalizeSettings( (array)$settings['strings'] ) |
|
| 207 | 207 | : []; |
| 208 | 208 | } |
| 209 | 209 | return $translations; |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | protected function getEntryString( array $entry, $key ) |
| 217 | 217 | { |
| 218 | - return isset( $entry[$key] ) |
|
| 219 | - ? implode( '', (array) $entry[$key] ) |
|
| 218 | + return isset($entry[$key]) |
|
| 219 | + ? implode( '', (array)$entry[$key] ) |
|
| 220 | 220 | : ''; |
| 221 | 221 | } |
| 222 | 222 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | $keys = [ |
| 229 | 229 | 'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]', |
| 230 | 230 | ]; |
| 231 | - array_walk( $entries, function( &$entry ) use( $keys ) { |
|
| 231 | + array_walk( $entries, function( &$entry ) use($keys) { |
|
| 232 | 232 | foreach( $keys as $key ) { |
| 233 | 233 | $entry = $this->normalizeEntryString( $entry, $key ); |
| 234 | 234 | } |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | protected function normalizeEntryString( array $entry, $key ) |
| 244 | 244 | { |
| 245 | - if( isset( $entry[$key] )) { |
|
| 245 | + if( isset($entry[$key]) ) { |
|
| 246 | 246 | $entry[$key] = $this->getEntryString( $entry, $key ); |
| 247 | 247 | } |
| 248 | 248 | return $entry; |
@@ -256,11 +256,11 @@ discard block |
||
| 256 | 256 | $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' ); |
| 257 | 257 | $strings = array_filter( $strings, 'is_array' ); |
| 258 | 258 | foreach( $strings as &$string ) { |
| 259 | - $string['type'] = isset( $string['p1'] ) ? 'plural' : 'single'; |
|
| 259 | + $string['type'] = isset($string['p1']) ? 'plural' : 'single'; |
|
| 260 | 260 | $string = wp_parse_args( $string, $defaultString ); |
| 261 | 261 | } |
| 262 | 262 | return array_filter( $strings, function( $string ) { |
| 263 | - return !empty( $string['id'] ); |
|
| 263 | + return !empty($string['id']); |
|
| 264 | 264 | }); |
| 265 | 265 | } |
| 266 | 266 | } |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $this->newSettings = $this->getNewSettings(); |
| 76 | 76 | $this->oldSettings = $this->getOldSettings(); |
| 77 | - if( empty( $this->oldSettings ))return; |
|
| 77 | + if( empty($this->oldSettings) )return; |
|
| 78 | 78 | foreach( static::MAPPED_SETTINGS as $old => $new ) { |
| 79 | - if( empty( $this->oldSettings[$old] ))continue; |
|
| 79 | + if( empty($this->oldSettings[$old]) )continue; |
|
| 80 | 80 | $this->newSettings[$new] = $this->oldSettings[$old]; |
| 81 | 81 | } |
| 82 | 82 | $this->migrateNotificationSettings(); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $this->migrateRequiredSettings(); |
| 85 | 85 | $oldSettings = glsr( Helper::class )->convertDotNotationArray( $this->oldSettings ); |
| 86 | 86 | $newSettings = glsr( Helper::class )->convertDotNotationArray( $this->newSettings ); |
| 87 | - if( isset( $oldSettings['settings']['strings'] ) && is_array( $oldSettings['settings']['strings'] )) { |
|
| 87 | + if( isset($oldSettings['settings']['strings']) && is_array( $oldSettings['settings']['strings'] ) ) { |
|
| 88 | 88 | $newSettings['settings']['strings'] = $oldSettings['settings']['strings']; |
| 89 | 89 | } |
| 90 | 90 | glsr( OptionManager::class )->set( $newSettings ); |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | protected function getOldSettings() |
| 118 | 118 | { |
| 119 | 119 | $defaults = array_fill_keys( array_keys( static::MAPPED_SETTINGS ), '' ); |
| 120 | - $settings = glsr( Helper::class )->flattenArray( get_option( 'geminilabs_site_reviews-v2', [] )); |
|
| 121 | - if( !empty( $settings )) { |
|
| 120 | + $settings = glsr( Helper::class )->flattenArray( get_option( 'geminilabs_site_reviews-v2', [] ) ); |
|
| 121 | + if( !empty($settings) ) { |
|
| 122 | 122 | $settings = wp_parse_args( $settings, $defaults ); |
| 123 | 123 | } |
| 124 | 124 | return $settings; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | 'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'], |
| 152 | 152 | 'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'], |
| 153 | 153 | ]; |
| 154 | - if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] )) { |
|
| 154 | + if( in_array( $this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'] ) ) { |
|
| 155 | 155 | $this->newSettings['settings.submissions.recaptcha.integration'] = 'all'; |
| 156 | 156 | } |
| 157 | 157 | if( $this->oldSettings['settings.reviews-form.recaptcha.integration'] == 'invisible-recaptcha' ) { |
@@ -74,9 +74,13 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $this->newSettings = $this->getNewSettings(); |
| 76 | 76 | $this->oldSettings = $this->getOldSettings(); |
| 77 | - if( empty( $this->oldSettings ))return; |
|
| 77 | + if( empty( $this->oldSettings )) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 78 | 80 | foreach( static::MAPPED_SETTINGS as $old => $new ) { |
| 79 | - if( empty( $this->oldSettings[$old] ))continue; |
|
| 81 | + if( empty( $this->oldSettings[$old] )) { |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 80 | 84 | $this->newSettings[$new] = $this->oldSettings[$old]; |
| 81 | 85 | } |
| 82 | 86 | $this->migrateNotificationSettings(); |
@@ -136,7 +140,9 @@ discard block |
||
| 136 | 140 | ]; |
| 137 | 141 | $this->newSettings['settings.general.notifications'] = []; |
| 138 | 142 | foreach( $notifications as $old => $new ) { |
| 139 | - if( $this->oldSettings['settings.general.notification'] != $old )continue; |
|
| 143 | + if( $this->oldSettings['settings.general.notification'] != $old ) { |
|
| 144 | + continue; |
|
| 145 | + } |
|
| 140 | 146 | $this->newSettings['settings.general.notifications'][] = $new; |
| 141 | 147 | } |
| 142 | 148 | } |
@@ -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( Translation::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 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | function glsr( $alias = null ) { |
| 8 | 8 | $app = \GeminiLabs\SiteReviews\Application::load(); |
| 9 | - return !empty( $alias ) |
|
| 9 | + return !empty($alias) |
|
| 10 | 10 | ? $app->make( $alias ) |
| 11 | 11 | : $app; |
| 12 | 12 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @return false|\GeminiLabs\SiteReviews\Review |
| 16 | 16 | */ |
| 17 | 17 | function glsr_create_review( array $reviewValues = [] ) { |
| 18 | - if( empty( $reviewValues )) { |
|
| 18 | + if( empty($reviewValues) ) { |
|
| 19 | 19 | return false; |
| 20 | 20 | } |
| 21 | 21 | $review = new \GeminiLabs\SiteReviews\Commands\CreateReview( $reviewValues ); |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | * @return \WP_Screen|object |
| 27 | 27 | */ |
| 28 | 28 | function glsr_current_screen() { |
| 29 | - if( function_exists( 'get_current_screen' )) { |
|
| 29 | + if( function_exists( 'get_current_screen' ) ) { |
|
| 30 | 30 | $screen = get_current_screen(); |
| 31 | 31 | } |
| 32 | - return empty( $screen ) |
|
| 32 | + return empty($screen) |
|
| 33 | 33 | ? (object)array_fill_keys( ['base', 'id', 'post_type'], null ) |
| 34 | 34 | : $screen; |
| 35 | 35 | } |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | function glsr_log() { |
| 94 | 94 | $args = func_get_args(); |
| 95 | - $context = isset( $args[1] ) |
|
| 95 | + $context = isset($args[1]) |
|
| 96 | 96 | ? $args[1] |
| 97 | 97 | : []; |
| 98 | 98 | $console = glsr( 'Modules\Console' ); |
| 99 | - return !empty( $args ) |
|
| 99 | + return !empty($args) |
|
| 100 | 100 | ? $console->log( 'debug', $args[0], $context ) |
| 101 | 101 | : $console; |
| 102 | 102 | } |
@@ -4,7 +4,8 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * @return mixed |
| 6 | 6 | */ |
| 7 | -function glsr( $alias = null ) { |
|
| 7 | +function glsr( $alias = null ) |
|
| 8 | +{ |
|
| 8 | 9 | $app = \GeminiLabs\SiteReviews\Application::load(); |
| 9 | 10 | return !empty( $alias ) |
| 10 | 11 | ? $app->make( $alias ) |
@@ -14,7 +15,8 @@ discard block |
||
| 14 | 15 | /** |
| 15 | 16 | * @return false|\GeminiLabs\SiteReviews\Review |
| 16 | 17 | */ |
| 17 | -function glsr_create_review( array $reviewValues = [] ) { |
|
| 18 | +function glsr_create_review( array $reviewValues = [] ) |
|
| 19 | +{ |
|
| 18 | 20 | if( empty( $reviewValues )) { |
| 19 | 21 | return false; |
| 20 | 22 | } |
@@ -25,7 +27,8 @@ discard block |
||
| 25 | 27 | /** |
| 26 | 28 | * @return \WP_Screen|object |
| 27 | 29 | */ |
| 28 | -function glsr_current_screen() { |
|
| 30 | +function glsr_current_screen() |
|
| 31 | +{ |
|
| 29 | 32 | if( function_exists( 'get_current_screen' )) { |
| 30 | 33 | $screen = get_current_screen(); |
| 31 | 34 | } |
@@ -38,7 +41,8 @@ discard block |
||
| 38 | 41 | * @param mixed ...$vars |
| 39 | 42 | * @return void |
| 40 | 43 | */ |
| 41 | -function glsr_debug( ...$vars ) { |
|
| 44 | +function glsr_debug( ...$vars ) |
|
| 45 | +{ |
|
| 42 | 46 | if( count( $vars ) == 1 ) { |
| 43 | 47 | $value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); |
| 44 | 48 | printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); |
@@ -57,14 +61,16 @@ discard block |
||
| 57 | 61 | * @param mixed $fallback |
| 58 | 62 | * @return string|array |
| 59 | 63 | */ |
| 60 | -function glsr_get_option( $path = '', $fallback = '' ) { |
|
| 64 | +function glsr_get_option( $path = '', $fallback = '' ) |
|
| 65 | +{ |
|
| 61 | 66 | return glsr( 'Database\OptionManager' )->get( 'settings.'.$path, $fallback ); |
| 62 | 67 | } |
| 63 | 68 | |
| 64 | 69 | /** |
| 65 | 70 | * @return array |
| 66 | 71 | */ |
| 67 | -function glsr_get_options() { |
|
| 72 | +function glsr_get_options() |
|
| 73 | +{ |
|
| 68 | 74 | return glsr( 'Database\OptionManager' )->get( 'settings' ); |
| 69 | 75 | } |
| 70 | 76 | |
@@ -72,7 +78,8 @@ discard block |
||
| 72 | 78 | * @param int $post_id |
| 73 | 79 | * @return void|\GeminiLabs\SiteReviews\Review |
| 74 | 80 | */ |
| 75 | -function glsr_get_review( $post_id ) { |
|
| 81 | +function glsr_get_review( $post_id ) |
|
| 82 | +{ |
|
| 76 | 83 | $post = get_post( $post_id ); |
| 77 | 84 | if( $post instanceof WP_Post ) { |
| 78 | 85 | return glsr( 'Database\ReviewManager' )->single( $post ); |
@@ -83,14 +90,16 @@ discard block |
||
| 83 | 90 | * @return array |
| 84 | 91 | * @todo document change of $reviews->reviews to $reviews->results |
| 85 | 92 | */ |
| 86 | -function glsr_get_reviews( array $args = array() ) { |
|
| 93 | +function glsr_get_reviews( array $args = array() ) |
|
| 94 | +{ |
|
| 87 | 95 | return glsr( 'Database\ReviewManager' )->get( $args ); |
| 88 | 96 | } |
| 89 | 97 | |
| 90 | 98 | /** |
| 91 | 99 | * @return \GeminiLabs\SiteReviews\Modules\Console |
| 92 | 100 | */ |
| 93 | -function glsr_log() { |
|
| 101 | +function glsr_log() |
|
| 102 | +{ |
|
| 94 | 103 | $args = func_get_args(); |
| 95 | 104 | $context = isset( $args[1] ) |
| 96 | 105 | ? $args[1] |
@@ -13,15 +13,15 @@ discard block |
||
| 13 | 13 | public function fields() |
| 14 | 14 | { |
| 15 | 15 | return [[ |
| 16 | - 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' )), |
|
| 16 | + 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ), |
|
| 17 | 17 | 'minWidth' => 320, |
| 18 | 18 | 'type' => 'container', |
| 19 | - ],[ |
|
| 19 | + ], [ |
|
| 20 | 20 | 'label' => esc_html__( 'Title', 'site-reviews' ), |
| 21 | 21 | 'name' => 'title', |
| 22 | 22 | 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
| 23 | 23 | 'type' => 'textbox', |
| 24 | - ],[ |
|
| 24 | + ], [ |
|
| 25 | 25 | 'label' => esc_html__( 'Count', 'site-reviews' ), |
| 26 | 26 | 'maxLength' => 5, |
| 27 | 27 | 'name' => 'count', |
@@ -29,20 +29,20 @@ discard block |
||
| 29 | 29 | 'text' => '10', |
| 30 | 30 | 'tooltip' => __( 'How many reviews would you like to display (default: 10)?', 'site-reviews' ), |
| 31 | 31 | 'type' => 'textbox', |
| 32 | - ],[ |
|
| 32 | + ], [ |
|
| 33 | 33 | 'label' => esc_html__( 'Rating', 'site-reviews' ), |
| 34 | 34 | 'name' => 'rating', |
| 35 | 35 | 'options' => [ |
| 36 | - '5' => esc_html( sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 )), |
|
| 37 | - '4' => esc_html( sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 )), |
|
| 38 | - '3' => esc_html( sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 )), |
|
| 39 | - '2' => esc_html( sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 )), |
|
| 40 | - '1' => esc_html( sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 )), |
|
| 41 | - '0' => esc_html( __( 'Unrated', 'site-reviews' )), |
|
| 36 | + '5' => esc_html( sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ) ), |
|
| 37 | + '4' => esc_html( sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ) ), |
|
| 38 | + '3' => esc_html( sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ) ), |
|
| 39 | + '2' => esc_html( sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ) ), |
|
| 40 | + '1' => esc_html( sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ) ), |
|
| 41 | + '0' => esc_html( __( 'Unrated', 'site-reviews' ) ), |
|
| 42 | 42 | ], |
| 43 | 43 | 'tooltip' => __( 'What is the minimum rating to display (default: 1 star)?', 'site-reviews' ), |
| 44 | 44 | 'type' => 'listbox', |
| 45 | - ],[ |
|
| 45 | + ], [ |
|
| 46 | 46 | 'label' => esc_html__( 'Pagination', 'site-reviews' ), |
| 47 | 47 | 'name' => 'pagination', |
| 48 | 48 | 'options' => [ |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | 'name' => 'assigned_to', |
| 61 | 61 | 'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page.', 'site-reviews' ), |
| 62 | 62 | 'type' => 'textbox', |
| 63 | - ],[ |
|
| 63 | + ], [ |
|
| 64 | 64 | 'label' => esc_html__( 'Schema', 'site-reviews' ), |
| 65 | 65 | 'name' => 'schema', |
| 66 | 66 | 'options' => [ |
@@ -69,49 +69,49 @@ discard block |
||
| 69 | 69 | ], |
| 70 | 70 | 'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ), |
| 71 | 71 | 'type' => 'listbox', |
| 72 | - ],[ |
|
| 72 | + ], [ |
|
| 73 | 73 | 'label' => esc_html__( 'Classes', 'site-reviews' ), |
| 74 | 74 | 'name' => 'class', |
| 75 | 75 | 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
| 76 | 76 | 'type' => 'textbox', |
| 77 | - ],[ |
|
| 77 | + ], [ |
|
| 78 | 78 | 'columns' => 2, |
| 79 | 79 | 'items' => [[ |
| 80 | 80 | 'name' => 'hide_assigned_to', |
| 81 | 81 | 'text' => esc_html__( 'Assigned To', 'site-reviews' ), |
| 82 | 82 | 'tooltip' => __( 'Hide the assigned to link?', 'site-reviews' ), |
| 83 | 83 | 'type' => 'checkbox', |
| 84 | - ],[ |
|
| 84 | + ], [ |
|
| 85 | 85 | 'name' => 'hide_author', |
| 86 | 86 | 'text' => esc_html__( 'Author', 'site-reviews' ), |
| 87 | 87 | 'tooltip' => __( 'Hide the review author?', 'site-reviews' ), |
| 88 | 88 | 'type' => 'checkbox', |
| 89 | - ],[ |
|
| 89 | + ], [ |
|
| 90 | 90 | 'name' => 'hide_avatar', |
| 91 | 91 | 'text' => esc_html__( 'Avatar', 'site-reviews' ), |
| 92 | 92 | 'tooltip' => __( 'Hide the reviewer avatar if shown?', 'site-reviews' ), |
| 93 | 93 | 'type' => 'checkbox', |
| 94 | - ],[ |
|
| 94 | + ], [ |
|
| 95 | 95 | 'name' => 'hide_content', |
| 96 | 96 | 'text' => esc_html__( 'Content', 'site-reviews' ), |
| 97 | 97 | 'tooltip' => __( 'Hide the review content?', 'site-reviews' ), |
| 98 | 98 | 'type' => 'checkbox', |
| 99 | - ],[ |
|
| 99 | + ], [ |
|
| 100 | 100 | 'name' => 'hide_date', |
| 101 | 101 | 'text' => esc_html__( 'Date', 'site-reviews' ), |
| 102 | 102 | 'tooltip' => __( 'Hide the review date?', 'site-reviews' ), |
| 103 | 103 | 'type' => 'checkbox', |
| 104 | - ],[ |
|
| 104 | + ], [ |
|
| 105 | 105 | 'name' => 'hide_rating', |
| 106 | 106 | 'text' => esc_html__( 'Rating', 'site-reviews' ), |
| 107 | 107 | 'tooltip' => __( 'Hide the review rating?', 'site-reviews' ), |
| 108 | 108 | 'type' => 'checkbox', |
| 109 | - ],[ |
|
| 109 | + ], [ |
|
| 110 | 110 | 'name' => 'hide_response', |
| 111 | 111 | 'text' => esc_html__( 'Response', 'site-reviews' ), |
| 112 | 112 | 'tooltip' => __( 'Hide the review response?', 'site-reviews' ), |
| 113 | 113 | 'type' => 'checkbox', |
| 114 | - ],[ |
|
| 114 | + ], [ |
|
| 115 | 115 | 'name' => 'hide_title', |
| 116 | 116 | 'text' => esc_html__( 'Title', 'site-reviews' ), |
| 117 | 117 | 'tooltip' => __( 'Hide the review title?', 'site-reviews' ), |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | 'label' => esc_html__( 'Hide', 'site-reviews' ), |
| 122 | 122 | 'spacing' => 5, |
| 123 | 123 | 'type' => 'container', |
| 124 | - ],[ |
|
| 124 | + ], [ |
|
| 125 | 125 | 'hidden' => true, |
| 126 | 126 | 'name' => 'id', |
| 127 | 127 | 'type' => 'textbox', |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | public function getTerms() |
| 135 | 135 | { |
| 136 | 136 | $terms = glsr( Database::class )->getTerms(); |
| 137 | - if( empty( $terms )) { |
|
| 137 | + if( empty($terms) ) { |
|
| 138 | 138 | return []; |
| 139 | 139 | } |
| 140 | 140 | return [ |
@@ -15,12 +15,12 @@ discard block |
||
| 15 | 15 | return [[ |
| 16 | 16 | 'type' => 'container', |
| 17 | 17 | 'html' => '<p class="strong">'.esc_html__( 'All settings are optional.', 'site-reviews' ).'</p>', |
| 18 | - ],[ |
|
| 18 | + ], [ |
|
| 19 | 19 | 'label' => esc_html__( 'Title', 'site-reviews' ), |
| 20 | 20 | 'name' => 'title', |
| 21 | 21 | 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
| 22 | 22 | 'type' => 'textbox', |
| 23 | - ],[ |
|
| 23 | + ], [ |
|
| 24 | 24 | 'label' => esc_html__( 'Description', 'site-reviews' ), |
| 25 | 25 | 'minHeight' => 60, |
| 26 | 26 | 'minWidth' => 240, |
@@ -35,39 +35,39 @@ discard block |
||
| 35 | 35 | 'name' => 'assign_to', |
| 36 | 36 | 'tooltip' => __( 'Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews' ), |
| 37 | 37 | 'type' => 'textbox', |
| 38 | - ],[ |
|
| 38 | + ], [ |
|
| 39 | 39 | 'label' => esc_html__( 'Classes', 'site-reviews' ), |
| 40 | 40 | 'name' => 'class', |
| 41 | 41 | 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
| 42 | 42 | 'type' => 'textbox', |
| 43 | - ],[ |
|
| 43 | + ], [ |
|
| 44 | 44 | 'columns' => 2, |
| 45 | 45 | 'items' => [[ |
| 46 | 46 | 'name' => 'hide_content', |
| 47 | 47 | 'text' => esc_html__( 'Content', 'site-reviews' ), |
| 48 | 48 | 'tooltip' => __( 'Hide the content field?', 'site-reviews' ), |
| 49 | 49 | 'type' => 'checkbox', |
| 50 | - ],[ |
|
| 50 | + ], [ |
|
| 51 | 51 | 'name' => 'hide_email', |
| 52 | 52 | 'text' => esc_html__( 'Email', 'site-reviews' ), |
| 53 | 53 | 'tooltip' => __( 'Hide the email field?', 'site-reviews' ), |
| 54 | 54 | 'type' => 'checkbox', |
| 55 | - ],[ |
|
| 55 | + ], [ |
|
| 56 | 56 | 'name' => 'hide_name', |
| 57 | 57 | 'text' => esc_html__( 'Name', 'site-reviews' ), |
| 58 | 58 | 'tooltip' => __( 'Hide the name field?', 'site-reviews' ), |
| 59 | 59 | 'type' => 'checkbox', |
| 60 | - ],[ |
|
| 60 | + ], [ |
|
| 61 | 61 | 'name' => 'hide_rating', |
| 62 | 62 | 'text' => esc_html__( 'Rating', 'site-reviews' ), |
| 63 | 63 | 'tooltip' => __( 'Hide the rating field?', 'site-reviews' ), |
| 64 | 64 | 'type' => 'checkbox', |
| 65 | - ],[ |
|
| 65 | + ], [ |
|
| 66 | 66 | 'name' => 'hide_terms', |
| 67 | 67 | 'text' => esc_html__( 'Terms', 'site-reviews' ), |
| 68 | 68 | 'tooltip' => __( 'Hide the terms field?', 'site-reviews' ), |
| 69 | 69 | 'type' => 'checkbox', |
| 70 | - ],[ |
|
| 70 | + ], [ |
|
| 71 | 71 | 'name' => 'hide_title', |
| 72 | 72 | 'text' => esc_html__( 'Title', 'site-reviews' ), |
| 73 | 73 | 'tooltip' => __( 'Hide the title field?', 'site-reviews' ), |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | 'layout' => 'grid', |
| 78 | 78 | 'spacing' => 5, |
| 79 | 79 | 'type' => 'container', |
| 80 | - ],[ |
|
| 80 | + ], [ |
|
| 81 | 81 | 'hidden' => true, |
| 82 | 82 | 'name' => 'id', |
| 83 | 83 | 'type' => 'textbox', |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public function getTerms() |
| 91 | 91 | { |
| 92 | 92 | $terms = glsr( Database::class )->getTerms(); |
| 93 | - if( empty( $terms )) { |
|
| 93 | + if( empty($terms) ) { |
|
| 94 | 94 | return []; |
| 95 | 95 | } |
| 96 | 96 | return [ |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | 'label' => '['.$tag.']', |
| 48 | 48 | 'required' => $this->required, |
| 49 | 49 | 'title' => esc_html__( 'Shortcode', 'site-reviews' ), |
| 50 | - ]); |
|
| 50 | + ] ); |
|
| 51 | 51 | return $this; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | protected function generateFields( array $fields ) |
| 58 | 58 | { |
| 59 | 59 | $generatedFields = array_map( function( $field ) { |
| 60 | - if( empty( $field ))return; |
|
| 60 | + if( empty($field) )return; |
|
| 61 | 61 | $field = $this->normalize( $field ); |
| 62 | - if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] )))return; |
|
| 62 | + if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] ) ) )return; |
|
| 63 | 63 | return $this->$method( $field ); |
| 64 | 64 | }, $fields ); |
| 65 | - return array_values( array_filter( $generatedFields )); |
|
| 65 | + return array_values( array_filter( $generatedFields ) ); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -71,15 +71,15 @@ discard block |
||
| 71 | 71 | protected function getFields() |
| 72 | 72 | { |
| 73 | 73 | $fields = $this->generateFields( $this->fields() ); |
| 74 | - if( !empty( $this->errors )) { |
|
| 74 | + if( !empty($this->errors) ) { |
|
| 75 | 75 | $errors = []; |
| 76 | 76 | foreach( $this->required as $name => $alert ) { |
| 77 | - if( false !== array_search( $name, array_column( $fields, 'name' )))continue; |
|
| 77 | + if( false !== array_search( $name, array_column( $fields, 'name' ) ) )continue; |
|
| 78 | 78 | $errors[] = $this->errors[$name]; |
| 79 | 79 | } |
| 80 | 80 | $this->errors = $errors; |
| 81 | 81 | } |
| 82 | - return empty( $this->errors ) |
|
| 82 | + return empty($this->errors) |
|
| 83 | 83 | ? $fields |
| 84 | 84 | : $this->errors; |
| 85 | 85 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | return wp_parse_args( $field, [ |
| 93 | 93 | 'items' => [], |
| 94 | 94 | 'type' => '', |
| 95 | - ]); |
|
| 95 | + ] ); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | 'tooltip' => '', |
| 111 | 111 | 'type' => '', |
| 112 | 112 | 'value' => '', |
| 113 | - ]); |
|
| 113 | + ] ); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | protected function normalizeContainer( array $field ) |
| 120 | 120 | { |
| 121 | - if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ))return; |
|
| 121 | + if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ) )return; |
|
| 122 | 122 | $field['items'] = $this->generateFields( $field['items'] ); |
| 123 | 123 | return $field; |
| 124 | 124 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | protected function normalizeField( array $field, array $defaults ) |
| 130 | 130 | { |
| 131 | - if( !$this->validate( $field ))return; |
|
| 131 | + if( !$this->validate( $field ) )return; |
|
| 132 | 132 | return array_filter( shortcode_atts( $defaults, $field ), function( $value ) { |
| 133 | 133 | return $value !== ''; |
| 134 | 134 | }); |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | 'tooltip' => '', |
| 149 | 149 | 'type' => '', |
| 150 | 150 | 'value' => '', |
| 151 | - ]); |
|
| 152 | - if( !is_array( $listbox ))return; |
|
| 153 | - if( !array_key_exists( '', $listbox['options'] )) { |
|
| 151 | + ] ); |
|
| 152 | + if( !is_array( $listbox ) )return; |
|
| 153 | + if( !array_key_exists( '', $listbox['options'] ) ) { |
|
| 154 | 154 | $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; |
| 155 | 155 | } |
| 156 | 156 | foreach( $listbox['options'] as $value => $text ) { |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | protected function normalizePost( array $field ) |
| 169 | 169 | { |
| 170 | - if( !is_array( $field['query_args'] )) { |
|
| 170 | + if( !is_array( $field['query_args'] ) ) { |
|
| 171 | 171 | $field['query_args'] = []; |
| 172 | 172 | } |
| 173 | 173 | $posts = get_posts( wp_parse_args( $field['query_args'], [ |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | 'orderby' => 'title', |
| 176 | 176 | 'post_type' => 'post', |
| 177 | 177 | 'posts_per_page' => 30, |
| 178 | - ])); |
|
| 179 | - if( !empty( $posts )) { |
|
| 178 | + ] ) ); |
|
| 179 | + if( !empty($posts) ) { |
|
| 180 | 180 | $options = []; |
| 181 | 181 | foreach( $posts as $post ) { |
| 182 | 182 | $options[$post->ID] = esc_html( $post->post_title ); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | 'tooltip' => '', |
| 207 | 207 | 'type' => '', |
| 208 | 208 | 'value' => '', |
| 209 | - ]); |
|
| 209 | + ] ); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | protected function validate( array $field ) |
| 216 | 216 | { |
| 217 | - $args = shortcode_atts([ |
|
| 217 | + $args = shortcode_atts( [ |
|
| 218 | 218 | 'label' => '', |
| 219 | 219 | 'name' => false, |
| 220 | 220 | 'required' => false, |
@@ -230,13 +230,13 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | protected function validateErrors( array $args ) |
| 232 | 232 | { |
| 233 | - if( !isset( $args['required']['error'] )) { |
|
| 233 | + if( !isset($args['required']['error']) ) { |
|
| 234 | 234 | return true; |
| 235 | 235 | } |
| 236 | - $this->errors[$args['name']] = $this->normalizeContainer([ |
|
| 236 | + $this->errors[$args['name']] = $this->normalizeContainer( [ |
|
| 237 | 237 | 'html' => $args['required']['error'], |
| 238 | 238 | 'type' => 'container', |
| 239 | - ]); |
|
| 239 | + ] ); |
|
| 240 | 240 | return false; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -249,10 +249,10 @@ discard block |
||
| 249 | 249 | return true; |
| 250 | 250 | } |
| 251 | 251 | $alert = esc_html__( 'Some of the shortcode options are required.', 'site-reviews' ); |
| 252 | - if( isset( $args['required']['alert'] )) { |
|
| 252 | + if( isset($args['required']['alert']) ) { |
|
| 253 | 253 | $alert = $args['required']['alert']; |
| 254 | 254 | } |
| 255 | - else if( !empty( $args['label'] )) { |
|
| 255 | + else if( !empty($args['label']) ) { |
|
| 256 | 256 | $alert = sprintf( |
| 257 | 257 | esc_html_x( 'The "%s" option is required.', 'the option label', 'site-reviews' ), |
| 258 | 258 | str_replace( ':', '', $args['label'] ) |
@@ -57,9 +57,13 @@ discard block |
||
| 57 | 57 | protected function generateFields( array $fields ) |
| 58 | 58 | { |
| 59 | 59 | $generatedFields = array_map( function( $field ) { |
| 60 | - if( empty( $field ))return; |
|
| 60 | + if( empty( $field )) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 61 | 63 | $field = $this->normalize( $field ); |
| 62 | - if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] )))return; |
|
| 64 | + if( !method_exists( $this, $method = 'normalize'.ucfirst( $field['type'] ))) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 63 | 67 | return $this->$method( $field ); |
| 64 | 68 | }, $fields ); |
| 65 | 69 | return array_values( array_filter( $generatedFields )); |
@@ -74,7 +78,9 @@ discard block |
||
| 74 | 78 | if( !empty( $this->errors )) { |
| 75 | 79 | $errors = []; |
| 76 | 80 | foreach( $this->required as $name => $alert ) { |
| 77 | - if( false !== array_search( $name, array_column( $fields, 'name' )))continue; |
|
| 81 | + if( false !== array_search( $name, array_column( $fields, 'name' ))) { |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 78 | 84 | $errors[] = $this->errors[$name]; |
| 79 | 85 | } |
| 80 | 86 | $this->errors = $errors; |
@@ -118,7 +124,9 @@ discard block |
||
| 118 | 124 | */ |
| 119 | 125 | protected function normalizeContainer( array $field ) |
| 120 | 126 | { |
| 121 | - if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field ))return; |
|
| 127 | + if( !array_key_exists( 'html', $field ) && !array_key_exists( 'items', $field )) { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 122 | 130 | $field['items'] = $this->generateFields( $field['items'] ); |
| 123 | 131 | return $field; |
| 124 | 132 | } |
@@ -128,7 +136,9 @@ discard block |
||
| 128 | 136 | */ |
| 129 | 137 | protected function normalizeField( array $field, array $defaults ) |
| 130 | 138 | { |
| 131 | - if( !$this->validate( $field ))return; |
|
| 139 | + if( !$this->validate( $field )) { |
|
| 140 | + return; |
|
| 141 | + } |
|
| 132 | 142 | return array_filter( shortcode_atts( $defaults, $field ), function( $value ) { |
| 133 | 143 | return $value !== ''; |
| 134 | 144 | }); |
@@ -149,7 +159,9 @@ discard block |
||
| 149 | 159 | 'type' => '', |
| 150 | 160 | 'value' => '', |
| 151 | 161 | ]); |
| 152 | - if( !is_array( $listbox ))return; |
|
| 162 | + if( !is_array( $listbox )) { |
|
| 163 | + return; |
|
| 164 | + } |
|
| 153 | 165 | if( !array_key_exists( '', $listbox['options'] )) { |
| 154 | 166 | $listbox['options'] = ['' => $listbox['placeholder']] + $listbox['options']; |
| 155 | 167 | } |
@@ -12,10 +12,10 @@ discard block |
||
| 12 | 12 | public function fields() |
| 13 | 13 | { |
| 14 | 14 | return [[ |
| 15 | - 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' )), |
|
| 15 | + 'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' ) ), |
|
| 16 | 16 | 'minWidth' => 320, |
| 17 | 17 | 'type' => 'container', |
| 18 | - ],[ |
|
| 18 | + ], [ |
|
| 19 | 19 | 'label' => esc_html__( 'Title', 'site-reviews' ), |
| 20 | 20 | 'name' => 'title', |
| 21 | 21 | 'tooltip' => __( 'Enter a custom shortcode heading.', 'site-reviews' ), |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | 'name' => 'assigned_to', |
| 29 | 29 | 'tooltip' => __( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page.', 'site-reviews' ), |
| 30 | 30 | 'type' => 'textbox', |
| 31 | - ],[ |
|
| 31 | + ], [ |
|
| 32 | 32 | 'label' => esc_html__( 'Schema', 'site-reviews' ), |
| 33 | 33 | 'name' => 'schema', |
| 34 | 34 | 'options' => [ |
@@ -37,34 +37,34 @@ discard block |
||
| 37 | 37 | ], |
| 38 | 38 | 'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ), |
| 39 | 39 | 'type' => 'listbox', |
| 40 | - ],[ |
|
| 40 | + ], [ |
|
| 41 | 41 | 'label' => esc_html__( 'Classes', 'site-reviews' ), |
| 42 | 42 | 'name' => 'class', |
| 43 | 43 | 'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ), |
| 44 | 44 | 'type' => 'textbox', |
| 45 | - ],[ |
|
| 45 | + ], [ |
|
| 46 | 46 | 'columns' => 2, |
| 47 | 47 | 'items' => [[ |
| 48 | 48 | 'type' => 'checkbox', |
| 49 | 49 | 'name' => 'hide_bars', |
| 50 | 50 | 'text' => esc_html__( 'Bars', 'site-reviews' ), |
| 51 | 51 | 'tooltip' => __( 'Hide the percentage bars?', 'site-reviews' ), |
| 52 | - ],[ |
|
| 52 | + ], [ |
|
| 53 | 53 | 'type' => 'checkbox', |
| 54 | 54 | 'name' => 'hide_if_empty', |
| 55 | 55 | 'text' => esc_html__( 'If Empty', 'site-reviews' ), |
| 56 | 56 | 'tooltip' => __( 'Hide the summary if no reviews are found?', 'site-reviews' ), |
| 57 | - ],[ |
|
| 57 | + ], [ |
|
| 58 | 58 | 'type' => 'checkbox', |
| 59 | 59 | 'name' => 'hide_rating', |
| 60 | 60 | 'text' => esc_html__( 'Rating', 'site-reviews' ), |
| 61 | 61 | 'tooltip' => __( 'Hide the rating?', 'site-reviews' ), |
| 62 | - ],[ |
|
| 62 | + ], [ |
|
| 63 | 63 | 'type' => 'checkbox', |
| 64 | 64 | 'name' => 'hide_stars', |
| 65 | 65 | 'text' => esc_html__( 'Stars', 'site-reviews' ), |
| 66 | 66 | 'tooltip' => __( 'Hide the stars?', 'site-reviews' ), |
| 67 | - ],[ |
|
| 67 | + ], [ |
|
| 68 | 68 | 'type' => 'checkbox', |
| 69 | 69 | 'name' => 'hide_summary', |
| 70 | 70 | 'text' => esc_html__( 'Summary', 'site-reviews' ), |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $this->validateBlacklist(); |
| 68 | 68 | $this->validateAkismet(); |
| 69 | 69 | $this->validateRecaptcha(); |
| 70 | - if( !empty( $this->error )) { |
|
| 70 | + if( !empty($this->error) ) { |
|
| 71 | 71 | $this->setSessionValues( 'message', $this->error ); |
| 72 | 72 | } |
| 73 | 73 | return $this; |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
| 92 | 92 | return static::RECAPTCHA_DISABLED; |
| 93 | 93 | } |
| 94 | - if( empty( $this->request['recaptcha-token'] )) { |
|
| 95 | - return $this->request['counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 )) |
|
| 94 | + if( empty($this->request['recaptcha-token']) ) { |
|
| 95 | + return $this->request['counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) ) |
|
| 96 | 96 | ? static::RECAPTCHA_EMPTY |
| 97 | 97 | : static::RECAPTCHA_FAILED; |
| 98 | 98 | } |
@@ -104,17 +104,17 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | protected function getRecaptchaTokenStatus() |
| 106 | 106 | { |
| 107 | - $endpoint = add_query_arg([ |
|
| 107 | + $endpoint = add_query_arg( [ |
|
| 108 | 108 | 'remoteip' => glsr( Helper::class )->getIpAddress(), |
| 109 | 109 | 'response' => $this->request['recaptcha-token'], |
| 110 | 110 | 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
| 111 | 111 | ], static::RECAPTCHA_ENDPOINT ); |
| 112 | - if( is_wp_error( $response = wp_remote_get( $endpoint ))) { |
|
| 112 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
| 113 | 113 | glsr_log()->error( $response->get_error_message() ); |
| 114 | 114 | return static::RECAPTCHA_FAILED; |
| 115 | 115 | } |
| 116 | - $response = json_decode( wp_remote_retrieve_body( $response )); |
|
| 117 | - if( !empty( $response->success )) { |
|
| 116 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
| 117 | + if( !empty($response->success) ) { |
|
| 118 | 118 | return boolval( $response->success ) |
| 119 | 119 | ? static::RECAPTCHA_VALID |
| 120 | 120 | : static::RECAPTCHA_INVALID; |
@@ -132,12 +132,12 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | $rules = array_intersect_key( |
| 134 | 134 | apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ), |
| 135 | - array_flip( $this->getOption( 'settings.submissions.required', [] )) |
|
| 135 | + array_flip( $this->getOption( 'settings.submissions.required', [] ) ) |
|
| 136 | 136 | ); |
| 137 | - $excluded = isset( $request['excluded'] ) |
|
| 137 | + $excluded = isset($request['excluded']) |
|
| 138 | 138 | ? explode( ',', $request['excluded'] ) |
| 139 | 139 | : []; |
| 140 | - return array_diff_key( $rules, array_flip( $excluded )); |
|
| 140 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | { |
| 148 | 148 | $rules = $this->getValidationRules( $request ); |
| 149 | 149 | $errors = glsr( Validator::class )->validate( $request, $rules ); |
| 150 | - if( empty( $errors )) { |
|
| 150 | + if( empty($errors) ) { |
|
| 151 | 151 | return true; |
| 152 | 152 | } |
| 153 | 153 | $this->setSessionValues( 'errors', $errors ); |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
| 165 | 165 | { |
| 166 | 166 | glsr( Session::class )->set( $this->form_id.$type, $value ); |
| 167 | - if( !empty( $loggedMessage )) { |
|
| 167 | + if( !empty($loggedMessage) ) { |
|
| 168 | 168 | glsr_log()->warning( $loggedMessage ); |
| 169 | 169 | glsr_log()->warning( $this->request ); |
| 170 | 170 | } |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | protected function validateAkismet() |
| 177 | 177 | { |
| 178 | - if( !empty( $this->error ))return; |
|
| 179 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
| 178 | + if( !empty($this->error) )return; |
|
| 179 | + if( !glsr( Akismet::class )->isSpam( $this->request ) )return; |
|
| 180 | 180 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
| 181 | 181 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
| 182 | 182 | } |
@@ -186,8 +186,8 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | protected function validateBlacklist() |
| 188 | 188 | { |
| 189 | - if( !empty( $this->error ))return; |
|
| 190 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
| 189 | + if( !empty($this->error) )return; |
|
| 190 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) )return; |
|
| 191 | 191 | $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
| 192 | 192 | if( $blacklistAction == 'reject' ) { |
| 193 | 193 | $this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' ); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | protected function validateCustom() |
| 204 | 204 | { |
| 205 | - if( !empty( $this->error ))return; |
|
| 205 | + if( !empty($this->error) )return; |
|
| 206 | 206 | $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
| 207 | 207 | if( $validated === true )return; |
| 208 | 208 | $this->setSessionValues( 'errors', [] ); |
@@ -217,8 +217,8 @@ discard block |
||
| 217 | 217 | */ |
| 218 | 218 | protected function validateHoneyPot() |
| 219 | 219 | { |
| 220 | - if( !empty( $this->error ))return; |
|
| 221 | - if( empty( $this->request['gotcha'] ))return; |
|
| 220 | + if( !empty($this->error) )return; |
|
| 221 | + if( empty($this->request['gotcha']) )return; |
|
| 222 | 222 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
| 223 | 223 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
| 224 | 224 | } |
@@ -228,9 +228,9 @@ discard block |
||
| 228 | 228 | */ |
| 229 | 229 | protected function validateRecaptcha() |
| 230 | 230 | { |
| 231 | - if( !empty( $this->error ))return; |
|
| 231 | + if( !empty($this->error) )return; |
|
| 232 | 232 | $status = $this->getRecaptchaStatus(); |
| 233 | - if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ))return; |
|
| 233 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) )return; |
|
| 234 | 234 | if( $status == static::RECAPTCHA_EMPTY ) { |
| 235 | 235 | $this->setSessionValues( 'recaptcha', 'unset' ); |
| 236 | 236 | $this->recaptchaIsUnset = true; |
@@ -250,11 +250,11 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | protected function validateRequest( array $request ) |
| 252 | 252 | { |
| 253 | - if( !$this->isRequestValid( $request )) { |
|
| 253 | + if( !$this->isRequestValid( $request ) ) { |
|
| 254 | 254 | $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
| 255 | 255 | return $request; |
| 256 | 256 | } |
| 257 | - if( empty( $request['title'] )) { |
|
| 257 | + if( empty($request['title']) ) { |
|
| 258 | 258 | $request['title'] = __( 'No Title', 'site-reviews' ); |
| 259 | 259 | } |
| 260 | 260 | return array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ); |
@@ -175,8 +175,12 @@ discard block |
||
| 175 | 175 | */ |
| 176 | 176 | protected function validateAkismet() |
| 177 | 177 | { |
| 178 | - if( !empty( $this->error ))return; |
|
| 179 | - if( !glsr( Akismet::class )->isSpam( $this->request ))return; |
|
| 178 | + if( !empty( $this->error )) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + if( !glsr( Akismet::class )->isSpam( $this->request )) { |
|
| 182 | + return; |
|
| 183 | + } |
|
| 180 | 184 | $this->setSessionValues( 'errors', [], 'Akismet caught a spam submission:' ); |
| 181 | 185 | $this->error = __( 'Your review cannot be submitted at this time. Please try again later.', 'site-reviews' ); |
| 182 | 186 | } |
@@ -186,8 +190,12 @@ discard block |
||
| 186 | 190 | */ |
| 187 | 191 | protected function validateBlacklist() |
| 188 | 192 | { |
| 189 | - if( !empty( $this->error ))return; |
|
| 190 | - if( !glsr( Blacklist::class )->isBlacklisted( $this->request ))return; |
|
| 193 | + if( !empty( $this->error )) { |
|
| 194 | + return; |
|
| 195 | + } |
|
| 196 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request )) { |
|
| 197 | + return; |
|
| 198 | + } |
|
| 191 | 199 | $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
| 192 | 200 | if( $blacklistAction == 'reject' ) { |
| 193 | 201 | $this->setSessionValues( 'errors', [], 'Blacklisted submission detected:' ); |
@@ -202,9 +210,13 @@ discard block |
||
| 202 | 210 | */ |
| 203 | 211 | protected function validateCustom() |
| 204 | 212 | { |
| 205 | - if( !empty( $this->error ))return; |
|
| 213 | + if( !empty( $this->error )) { |
|
| 214 | + return; |
|
| 215 | + } |
|
| 206 | 216 | $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
| 207 | - if( $validated === true )return; |
|
| 217 | + if( $validated === true ) { |
|
| 218 | + return; |
|
| 219 | + } |
|
| 208 | 220 | $this->setSessionValues( 'errors', [] ); |
| 209 | 221 | $this->setSessionValues( 'values', $this->request ); |
| 210 | 222 | $this->error = is_string( $validated ) |
@@ -217,8 +229,12 @@ discard block |
||
| 217 | 229 | */ |
| 218 | 230 | protected function validateHoneyPot() |
| 219 | 231 | { |
| 220 | - if( !empty( $this->error ))return; |
|
| 221 | - if( empty( $this->request['gotcha'] ))return; |
|
| 232 | + if( !empty( $this->error )) { |
|
| 233 | + return; |
|
| 234 | + } |
|
| 235 | + if( empty( $this->request['gotcha'] )) { |
|
| 236 | + return; |
|
| 237 | + } |
|
| 222 | 238 | $this->setSessionValues( 'errors', [], 'The Honeypot caught a bad submission:' ); |
| 223 | 239 | $this->error = __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
| 224 | 240 | } |
@@ -228,9 +244,13 @@ discard block |
||
| 228 | 244 | */ |
| 229 | 245 | protected function validateRecaptcha() |
| 230 | 246 | { |
| 231 | - if( !empty( $this->error ))return; |
|
| 247 | + if( !empty( $this->error )) { |
|
| 248 | + return; |
|
| 249 | + } |
|
| 232 | 250 | $status = $this->getRecaptchaStatus(); |
| 233 | - if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ))return; |
|
| 251 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] )) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 234 | 254 | if( $status == static::RECAPTCHA_EMPTY ) { |
| 235 | 255 | $this->setSessionValues( 'recaptcha', 'unset' ); |
| 236 | 256 | $this->recaptchaIsUnset = true; |