@@ -28,7 +28,7 @@ |
||
28 | 28 | $className = str_replace( '.php', '', $file ); |
29 | 29 | $version = str_replace( ['Upgrade_', '_'], ['', '.'], $className ); |
30 | 30 | $versionSuffix = preg_replace( '/[\d.]+(.+)?/', '${1}', glsr()->version ); // allow alpha/beta versions |
31 | - if( version_compare( $this->currentVersion(), $version.$versionSuffix, '>=' ))return; |
|
31 | + if( version_compare( $this->currentVersion(), $version.$versionSuffix, '>=' ) )return; |
|
32 | 32 | glsr( 'Modules\\Upgrader\\'.$className ); |
33 | 33 | glsr_log()->info( 'Completed Upgrade for v'.$version.$versionSuffix ); |
34 | 34 | }); |
@@ -20,7 +20,9 @@ discard block |
||
20 | 20 | $filenames = []; |
21 | 21 | $iterator = new DirectoryIterator( dirname( __FILE__ ).'/Upgrader' ); |
22 | 22 | foreach( $iterator as $fileinfo ) { |
23 | - if( !$fileinfo->isFile() )continue; |
|
23 | + if( !$fileinfo->isFile() ) { |
|
24 | + continue; |
|
25 | + } |
|
24 | 26 | $filenames[] = $fileinfo->getFilename(); |
25 | 27 | } |
26 | 28 | natsort( $filenames ); |
@@ -28,7 +30,9 @@ discard block |
||
28 | 30 | $className = str_replace( '.php', '', $file ); |
29 | 31 | $version = str_replace( ['Upgrade_', '_'], ['', '.'], $className ); |
30 | 32 | $versionSuffix = preg_replace( '/[\d.]+(.+)?/', '${1}', glsr()->version ); // allow alpha/beta versions |
31 | - if( version_compare( $this->currentVersion(), $version.$versionSuffix, '>=' ))return; |
|
33 | + if( version_compare( $this->currentVersion(), $version.$versionSuffix, '>=' )) { |
|
34 | + return; |
|
35 | + } |
|
32 | 36 | glsr( 'Modules\\Upgrader\\'.$className ); |
33 | 37 | glsr_log()->info( 'Completed Upgrade for v'.$version.$versionSuffix ); |
34 | 38 | }); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | protected function filterAttributes( array $allowedAttributeKeys ) |
124 | 124 | { |
125 | - return array_intersect_key( $this->attributes, array_flip( $allowedAttributeKeys )); |
|
125 | + return array_intersect_key( $this->attributes, array_flip( $allowedAttributeKeys ) ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $globalAttributes = $this->filterAttributes( static::GLOBAL_ATTRIBUTES ); |
134 | 134 | $wildcards = []; |
135 | 135 | foreach( static::GLOBAL_WILDCARD_ATTRIBUTES as $wildcard ) { |
136 | - $newWildcards = array_filter( $this->attributes, function( $key ) use( $wildcard ) { |
|
136 | + $newWildcards = array_filter( $this->attributes, function( $key ) use($wildcard) { |
|
137 | 137 | return glsr( Helper::class )->startsWith( $wildcard, $key ); |
138 | 138 | }, ARRAY_FILTER_USE_KEY ); |
139 | 139 | $wildcards = array_merge( $wildcards, $newWildcards ); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | protected function getPermanentAttributes() |
148 | 148 | { |
149 | 149 | $permanentAttributes = []; |
150 | - if( array_key_exists( 'value', $this->attributes )) { |
|
150 | + if( array_key_exists( 'value', $this->attributes ) ) { |
|
151 | 151 | $permanentAttributes['value'] = $this->attributes['value']; |
152 | 152 | } |
153 | 153 | return $permanentAttributes; |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | protected function normalizeBooleanAttributes() |
200 | 200 | { |
201 | 201 | foreach( $this->attributes as $key => $value ) { |
202 | - if( $this->isAttributeKeyNumeric( $key, $value )) { |
|
202 | + if( $this->isAttributeKeyNumeric( $key, $value ) ) { |
|
203 | 203 | $key = $value; |
204 | 204 | $value = true; |
205 | 205 | } |
206 | - if( !in_array( $key, static::BOOLEAN_ATTRIBUTES ))continue; |
|
206 | + if( !in_array( $key, static::BOOLEAN_ATTRIBUTES ) )continue; |
|
207 | 207 | $this->attributes[$key] = wp_validate_boolean( $value ); |
208 | 208 | } |
209 | 209 | } |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | protected function normalizeDataAttributes() |
215 | 215 | { |
216 | 216 | foreach( $this->attributes as $key => $value ) { |
217 | - if( $this->isAttributeKeyNumeric( $key, $value )) { |
|
217 | + if( $this->isAttributeKeyNumeric( $key, $value ) ) { |
|
218 | 218 | $key = $value; |
219 | 219 | $value = ''; |
220 | 220 | } |
221 | - if( !glsr( Helper::class )->startsWith( 'data-', $key ))continue; |
|
222 | - if( is_array( $value )) { |
|
223 | - $value = json_encode( $value, JSON_HEX_APOS|JSON_NUMERIC_CHECK|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE ); |
|
221 | + if( !glsr( Helper::class )->startsWith( 'data-', $key ) )continue; |
|
222 | + if( is_array( $value ) ) { |
|
223 | + $value = json_encode( $value, JSON_HEX_APOS | JSON_NUMERIC_CHECK | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); |
|
224 | 224 | } |
225 | 225 | $this->attributes[$key] = $value; |
226 | 226 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | protected function normalizeStringAttributes() |
233 | 233 | { |
234 | 234 | foreach( $this->attributes as $key => $value ) { |
235 | - if( !is_string( $value ))continue; |
|
235 | + if( !is_string( $value ) )continue; |
|
236 | 236 | $this->attributes[$key] = trim( $value ); |
237 | 237 | } |
238 | 238 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | { |
246 | 246 | if( $method != 'input' )return; |
247 | 247 | $attributes = wp_parse_args( $this->attributes, ['type' => ''] ); |
248 | - if( !in_array( $attributes['type'], static::INPUT_TYPES )) { |
|
248 | + if( !in_array( $attributes['type'], static::INPUT_TYPES ) ) { |
|
249 | 249 | $this->attributes['type'] = 'text'; |
250 | 250 | } |
251 | 251 | } |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | $permanentAttributes = $this->getPermanentAttributes(); |
260 | 260 | foreach( $this->attributes as $key => $value ) { |
261 | 261 | if( in_array( $key, static::BOOLEAN_ATTRIBUTES ) && !$value ) { |
262 | - unset( $attributes[$key] ); |
|
262 | + unset($attributes[$key]); |
|
263 | 263 | } |
264 | - if( glsr( Helper::class )->startsWith( 'data-', $key )) { |
|
264 | + if( glsr( Helper::class )->startsWith( 'data-', $key ) ) { |
|
265 | 265 | $permanentAttributes[$key] = $value; |
266 | - unset( $attributes[$key] ); |
|
266 | + unset($attributes[$key]); |
|
267 | 267 | } |
268 | 268 | } |
269 | 269 | $this->attributes = array_merge( array_filter( $attributes ), $permanentAttributes ); |
@@ -203,7 +203,9 @@ discard block |
||
203 | 203 | $key = $value; |
204 | 204 | $value = true; |
205 | 205 | } |
206 | - if( !in_array( $key, static::BOOLEAN_ATTRIBUTES ))continue; |
|
206 | + if( !in_array( $key, static::BOOLEAN_ATTRIBUTES )) { |
|
207 | + continue; |
|
208 | + } |
|
207 | 209 | $this->attributes[$key] = wp_validate_boolean( $value ); |
208 | 210 | } |
209 | 211 | } |
@@ -218,7 +220,9 @@ discard block |
||
218 | 220 | $key = $value; |
219 | 221 | $value = ''; |
220 | 222 | } |
221 | - if( !glsr( Helper::class )->startsWith( 'data-', $key ))continue; |
|
223 | + if( !glsr( Helper::class )->startsWith( 'data-', $key )) { |
|
224 | + continue; |
|
225 | + } |
|
222 | 226 | if( is_array( $value )) { |
223 | 227 | $value = json_encode( $value, JSON_HEX_APOS|JSON_NUMERIC_CHECK|JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE ); |
224 | 228 | } |
@@ -232,7 +236,9 @@ discard block |
||
232 | 236 | protected function normalizeStringAttributes() |
233 | 237 | { |
234 | 238 | foreach( $this->attributes as $key => $value ) { |
235 | - if( !is_string( $value ))continue; |
|
239 | + if( !is_string( $value )) { |
|
240 | + continue; |
|
241 | + } |
|
236 | 242 | $this->attributes[$key] = trim( $value ); |
237 | 243 | } |
238 | 244 | } |
@@ -243,7 +249,9 @@ discard block |
||
243 | 249 | */ |
244 | 250 | protected function normalizeInputType( $method ) |
245 | 251 | { |
246 | - if( $method != 'input' )return; |
|
252 | + if( $method != 'input' ) { |
|
253 | + return; |
|
254 | + } |
|
247 | 255 | $attributes = wp_parse_args( $this->attributes, ['type' => ''] ); |
248 | 256 | if( !in_array( $attributes['type'], static::INPUT_TYPES )) { |
249 | 257 | $this->attributes['type'] = 'text'; |
@@ -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 | } |