@@ -17,7 +17,9 @@ discard block |
||
17 | 17 | public function routeAdminPostRequest() |
18 | 18 | { |
19 | 19 | $request = $this->getRequest(); |
20 | - if( !$this->isValidPostRequest( $request ))return; |
|
20 | + if( !$this->isValidPostRequest( $request )) { |
|
21 | + return; |
|
22 | + } |
|
21 | 23 | check_admin_referer( $request['action'] ); |
22 | 24 | $this->routeRequest( 'admin', $request['action'], $request ); |
23 | 25 | } |
@@ -39,10 +41,16 @@ discard block |
||
39 | 41 | */ |
40 | 42 | public function routePublicPostRequest() |
41 | 43 | { |
42 | - if( is_admin() )return; |
|
44 | + if( is_admin() ) { |
|
45 | + return; |
|
46 | + } |
|
43 | 47 | $request = $this->getRequest(); |
44 | - if( !$this->isValidPostRequest( $request ))return; |
|
45 | - if( !$this->isValidPublicNonce( $request ))return; |
|
48 | + if( !$this->isValidPostRequest( $request )) { |
|
49 | + return; |
|
50 | + } |
|
51 | + if( !$this->isValidPublicNonce( $request )) { |
|
52 | + return; |
|
53 | + } |
|
46 | 54 | $this->routeRequest( 'public', $request['action'], $request ); |
47 | 55 | } |
48 | 56 | |
@@ -51,7 +59,9 @@ discard block |
||
51 | 59 | */ |
52 | 60 | protected function checkAjaxNonce( array $request ) |
53 | 61 | { |
54 | - if( !is_user_logged_in() )return; |
|
62 | + if( !is_user_logged_in() ) { |
|
63 | + return; |
|
64 | + } |
|
55 | 65 | if( !isset( $request['nonce'] )) { |
56 | 66 | $this->sendAjaxError( 'request is missing a nonce', $request ); |
57 | 67 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | public function routeAdminPostRequest() |
18 | 18 | { |
19 | 19 | $request = $this->getRequest(); |
20 | - if( !$this->isValidPostRequest( $request ))return; |
|
20 | + if( !$this->isValidPostRequest( $request ) )return; |
|
21 | 21 | check_admin_referer( $request['action'] ); |
22 | 22 | $this->routeRequest( 'admin', $request['action'], $request ); |
23 | 23 | } |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | { |
42 | 42 | if( is_admin() )return; |
43 | 43 | $request = $this->getRequest(); |
44 | - if( !$this->isValidPostRequest( $request ))return; |
|
45 | - if( !$this->isValidPublicNonce( $request ))return; |
|
44 | + if( !$this->isValidPostRequest( $request ) )return; |
|
45 | + if( !$this->isValidPublicNonce( $request ) )return; |
|
46 | 46 | $this->routeRequest( 'public', $request['action'], $request ); |
47 | 47 | } |
48 | 48 | |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | protected function checkAjaxNonce( array $request ) |
53 | 53 | { |
54 | 54 | if( !is_user_logged_in() )return; |
55 | - if( !isset( $request['nonce'] )) { |
|
55 | + if( !isset($request['nonce']) ) { |
|
56 | 56 | $this->sendAjaxError( 'request is missing a nonce', $request ); |
57 | 57 | } |
58 | - if( !wp_verify_nonce( $request['nonce'], $request['action'] )) { |
|
58 | + if( !wp_verify_nonce( $request['nonce'], $request['action'] ) ) { |
|
59 | 59 | $this->sendAjaxError( 'request failed the nonce check', $request, 403 ); |
60 | 60 | } |
61 | 61 | } |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function checkAjaxRequest( array $request ) |
67 | 67 | { |
68 | - if( !isset( $request['action'] )) { |
|
68 | + if( !isset($request['action']) ) { |
|
69 | 69 | $this->sendAjaxError( 'request must include an action', $request ); |
70 | 70 | } |
71 | - if( empty( $request['ajax_request'] )) { |
|
71 | + if( empty($request['ajax_request']) ) { |
|
72 | 72 | $this->sendAjaxError( 'request is invalid', $request ); |
73 | 73 | } |
74 | 74 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | protected function isValidPostRequest( array $request = [] ) |
97 | 97 | { |
98 | - return !empty( $request['action'] ) && empty( $request['ajax_request'] ); |
|
98 | + return !empty($request['action']) && empty($request['ajax_request']); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function isValidPublicNonce( array $request ) |
105 | 105 | { |
106 | - if( is_user_logged_in() && !wp_verify_nonce( $request['nonce'], $request['action'] )) { |
|
106 | + if( is_user_logged_in() && !wp_verify_nonce( $request['nonce'], $request['action'] ) ) { |
|
107 | 107 | glsr_log()->error( 'nonce check failed for public request' )->debug( $request ); |
108 | 108 | return false; |
109 | 109 | } |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | protected function routeRequest( $type, $action, array $request = [] ) |
119 | 119 | { |
120 | 120 | $actionHook = 'site-reviews/route/'.$type.'/request'; |
121 | - $controller = glsr( glsr( Helper::class )->buildClassName( $type.'-controller', 'Controllers' )); |
|
121 | + $controller = glsr( glsr( Helper::class )->buildClassName( $type.'-controller', 'Controllers' ) ); |
|
122 | 122 | $method = glsr( Helper::class )->buildMethodName( $action, 'router' ); |
123 | 123 | $request = apply_filters( 'site-reviews/route/request', $request, $action, $type ); |
124 | 124 | do_action( $actionHook, $action, $request ); |
125 | - if( is_callable( [$controller, $method] )) { |
|
125 | + if( is_callable( [$controller, $method] ) ) { |
|
126 | 126 | call_user_func( [$controller, $method], $request ); |
127 | 127 | return; |
128 | 128 | } |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | glsr_log()->error( $error )->debug( $request ); |
142 | 142 | glsr_log( $_POST ); |
143 | 143 | glsr( Notice::class )->addError( __( 'There was an error (try refreshing the page).', 'site-reviews' ).' <code>'.$error.'</code>' ); |
144 | - wp_send_json_error([ |
|
144 | + wp_send_json_error( [ |
|
145 | 145 | 'message' => __( 'The form could not be submitted. Please notify the site administrator.', 'site-reviews' ), |
146 | 146 | 'notices' => glsr( Notice::class )->get(), |
147 | 147 | 'error' => $error, |
148 | - ]); |
|
148 | + ] ); |
|
149 | 149 | } |
150 | 150 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | protected function getFieldDefault( array $field ) |
31 | 31 | { |
32 | - return isset( $field['default'] ) |
|
32 | + return isset($field['default']) |
|
33 | 33 | ? $field['default'] |
34 | 34 | : ''; |
35 | 35 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | protected function getSettingFields( $path ) |
41 | 41 | { |
42 | 42 | $settings = glsr( DefaultsManager::class )->settings(); |
43 | - return array_filter( $settings, function( $key ) use( $path ) { |
|
43 | + return array_filter( $settings, function( $key ) use($path) { |
|
44 | 44 | return glsr( Helper::class )->startsWith( $path, $key ); |
45 | 45 | }, ARRAY_FILTER_USE_KEY ); |
46 | 46 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | $field = wp_parse_args( $field, [ |
56 | 56 | 'is_setting' => true, |
57 | 57 | 'name' => $name, |
58 | - ]); |
|
59 | - $rows.= new Field( $this->normalize( $field )); |
|
58 | + ] ); |
|
59 | + $rows .= new Field( $this->normalize( $field ) ); |
|
60 | 60 | } |
61 | 61 | return $rows; |
62 | 62 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | protected function getTemplateData( $id ) |
69 | 69 | { |
70 | - $fields = $this->getSettingFields( $this->normalizeSettingPath( $id )); |
|
70 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
71 | 71 | return [ |
72 | 72 | 'context' => [ |
73 | 73 | 'rows' => $this->getSettingRows( $fields ), |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function getTemplateDataForAddons( $id ) |
83 | 83 | { |
84 | - $fields = $this->getSettingFields( $this->normalizeSettingPath( $id )); |
|
84 | + $fields = $this->getSettingFields( $this->normalizeSettingPath( $id ) ); |
|
85 | 85 | $settings = glsr( Helper::class )->convertDotNotationArray( $fields ); |
86 | 86 | $settingKeys = array_keys( $settings['settings']['addons'] ); |
87 | 87 | $results = []; |
88 | 88 | foreach( $settingKeys as $key ) { |
89 | - $addonFields = array_filter( $fields, function( $path ) use( $key ) { |
|
89 | + $addonFields = array_filter( $fields, function( $path ) use($key) { |
|
90 | 90 | return glsr( Helper::class )->startsWith( 'settings.addons.'.$key, $path ); |
91 | 91 | }, ARRAY_FILTER_USE_KEY ); |
92 | 92 | $results[$key] = $this->getSettingRows( $addonFields ); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | protected function getTemplateDataForTranslations() |
103 | 103 | { |
104 | 104 | $translations = glsr( Translator::class )->renderAll(); |
105 | - $class = empty( $translations ) |
|
105 | + $class = empty($translations) |
|
106 | 106 | ? 'glsr-hidden' |
107 | 107 | : ''; |
108 | 108 | return [ |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | $path, |
126 | 126 | glsr( Helper::class )->getPathValue( $path, glsr()->defaults ) |
127 | 127 | ); |
128 | - if( is_array( $expectedValue )) { |
|
128 | + if( is_array( $expectedValue ) ) { |
|
129 | 129 | return is_array( $optionValue ) |
130 | - ? count( array_intersect( $optionValue, $expectedValue )) === 0 |
|
130 | + ? count( array_intersect( $optionValue, $expectedValue ) ) === 0 |
|
131 | 131 | : !in_array( $optionValue, $expectedValue ); |
132 | 132 | } |
133 | 133 | return $optionValue != $expectedValue; |
@@ -149,17 +149,17 @@ discard block |
||
149 | 149 | */ |
150 | 150 | protected function normalizeDependsOn( array $field ) |
151 | 151 | { |
152 | - if( !empty( $field['depends_on'] ) && is_array( $field['depends_on'] )) { |
|
152 | + if( !empty($field['depends_on']) && is_array( $field['depends_on'] ) ) { |
|
153 | 153 | $path = key( $field['depends_on'] ); |
154 | 154 | $expectedValue = $field['depends_on'][$path]; |
155 | 155 | $fieldName = glsr( Helper::class )->convertPathToName( $path, OptionManager::databaseKey() ); |
156 | - if( is_array( $expectedValue )) { |
|
157 | - $fieldName.= '[]'; |
|
156 | + if( is_array( $expectedValue ) ) { |
|
157 | + $fieldName .= '[]'; |
|
158 | 158 | } |
159 | - $field['data-depends'] = json_encode([ |
|
159 | + $field['data-depends'] = json_encode( [ |
|
160 | 160 | 'name' => $fieldName, |
161 | 161 | 'value' => $expectedValue, |
162 | - ], JSON_HEX_APOS|JSON_HEX_QUOT ); |
|
162 | + ], JSON_HEX_APOS | JSON_HEX_QUOT ); |
|
163 | 163 | $field['is_hidden'] = $this->isFieldHidden( $path, $expectedValue ); |
164 | 164 | } |
165 | 165 | return $field; |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | */ |
171 | 171 | protected function normalizeLabelAndLegend( array $field ) |
172 | 172 | { |
173 | - if( !empty( $field['label'] )) { |
|
173 | + if( !empty($field['label']) ) { |
|
174 | 174 | $field['legend'] = $field['label']; |
175 | - unset( $field['label'] ); |
|
175 | + unset($field['label']); |
|
176 | 176 | } |
177 | 177 | else { |
178 | 178 | $field['is_valid'] = false; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | protected function normalizeValue( array $field ) |
188 | 188 | { |
189 | - if( !isset( $field['value'] )) { |
|
189 | + if( !isset($field['value']) ) { |
|
190 | 190 | $field['value'] = glsr( OptionManager::class )->get( |
191 | 191 | $field['name'], |
192 | 192 | $this->getFieldDefault( $field ) |
@@ -35,7 +35,9 @@ |
||
35 | 35 | */ |
36 | 36 | public function compose( Review $review, array $notification ) |
37 | 37 | { |
38 | - if( empty( $this->endpoint ))return; |
|
38 | + if( empty( $this->endpoint )) { |
|
39 | + return; |
|
40 | + } |
|
39 | 41 | $args = shortcode_atts( glsr( SlackDefaults::class )->defaults(), $notification ); |
40 | 42 | $this->review = $review; |
41 | 43 | $notification = [ |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function compose( Review $review, array $notification ) |
37 | 37 | { |
38 | - if( empty( $this->endpoint ))return; |
|
38 | + if( empty($this->endpoint) )return; |
|
39 | 39 | $args = shortcode_atts( glsr( SlackDefaults::class )->defaults(), $notification ); |
40 | 40 | $this->review = $review; |
41 | 41 | $notification = [ |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function send() |
60 | 60 | { |
61 | - if( empty( $this->endpoint )) { |
|
61 | + if( empty($this->endpoint) ) { |
|
62 | 62 | return new WP_Error( 'slack', 'Slack notification was not sent: missing endpoint' ); |
63 | 63 | } |
64 | 64 | return wp_remote_post( $this->endpoint, [ |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | 'redirection' => 5, |
71 | 71 | 'sslverify' => false, |
72 | 72 | 'timeout' => 45, |
73 | - ]); |
|
73 | + ] ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function buildAuthorField() |
92 | 92 | { |
93 | - $email = !empty( $this->review->email ) |
|
93 | + $email = !empty($this->review->email) |
|
94 | 94 | ? '<'.$this->review->email.'>' |
95 | 95 | : ''; |
96 | 96 | $author = trim( rtrim( $this->review->author ).' '.$email ); |
97 | - return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ))]; |
|
97 | + return ['value' => implode( ' - ', array_filter( [$author, $this->review->ip_address] ) )]; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function buildContentField() |
104 | 104 | { |
105 | - return !empty( $this->review->content ) |
|
105 | + return !empty($this->review->content) |
|
106 | 106 | ? ['value' => $this->review->content] |
107 | 107 | : []; |
108 | 108 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | protected function buildStarsField() |
128 | 128 | { |
129 | 129 | $solidStars = str_repeat( '★', $this->review->rating ); |
130 | - $emptyStars = str_repeat( '☆', max( 0, Rating::MAX_RATING - $this->review->rating )); |
|
130 | + $emptyStars = str_repeat( '☆', max( 0, Rating::MAX_RATING - $this->review->rating ) ); |
|
131 | 131 | $stars = $solidStars.$emptyStars; |
132 | 132 | $stars = apply_filters( 'site-reviews/slack/stars', $stars, $this->review->rating, Rating::MAX_RATING ); |
133 | 133 | return ['title' => $stars]; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | protected function buildTitleField() |
140 | 140 | { |
141 | - return !empty( $this->review->title ) |
|
141 | + return !empty($this->review->title) |
|
142 | 142 | ? ['title' => $this->review->title] |
143 | 143 | : []; |
144 | 144 | } |
@@ -85,7 +85,9 @@ discard block |
||
85 | 85 | */ |
86 | 86 | protected function buildRecaptcha() |
87 | 87 | { |
88 | - if( !glsr( OptionManager::class )->isRecaptchaEnabled() )return; |
|
88 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
89 | + return; |
|
90 | + } |
|
89 | 91 | return glsr( Builder::class )->div([ |
90 | 92 | 'class' => 'glsr-recaptcha-holder', |
91 | 93 | 'data-badge' => glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.position' ), |
@@ -161,7 +163,9 @@ discard block |
||
161 | 163 | */ |
162 | 164 | protected function getRegisterText() |
163 | 165 | { |
164 | - if( !get_option( 'users_can_register' ) || glsr( OptionManager::class )->get( 'settings.general.require.login' ) != 'yes' )return; |
|
166 | + if( !get_option( 'users_can_register' ) || glsr( OptionManager::class )->get( 'settings.general.require.login' ) != 'yes' ) { |
|
167 | + return; |
|
168 | + } |
|
165 | 169 | $registerLink = glsr( Builder::class )->a([ |
166 | 170 | 'href' => wp_registration_url(), |
167 | 171 | 'text' => __( 'register', 'site-reviews' ), |
@@ -217,7 +221,9 @@ discard block |
||
217 | 221 | */ |
218 | 222 | protected function normalizeFieldErrors( Field &$field ) |
219 | 223 | { |
220 | - if( !array_key_exists( $field->field['path'], $this->errors ))return; |
|
224 | + if( !array_key_exists( $field->field['path'], $this->errors )) { |
|
225 | + return; |
|
226 | + } |
|
221 | 227 | $field->field['errors'] = $this->errors[$field->field['path']]; |
222 | 228 | } |
223 | 229 | |
@@ -226,7 +232,9 @@ discard block |
||
226 | 232 | */ |
227 | 233 | protected function normalizeFieldRequired( Field &$field ) |
228 | 234 | { |
229 | - if( !in_array( $field->field['path'], $this->required ))return; |
|
235 | + if( !in_array( $field->field['path'], $this->required )) { |
|
236 | + return; |
|
237 | + } |
|
230 | 238 | $field->field['required'] = true; |
231 | 239 | } |
232 | 240 | |
@@ -249,7 +257,9 @@ discard block |
||
249 | 257 | */ |
250 | 258 | protected function normalizeFieldValue( Field &$field ) |
251 | 259 | { |
252 | - if( !array_key_exists( $field->field['path'], $this->values ))return; |
|
260 | + if( !array_key_exists( $field->field['path'], $this->values )) { |
|
261 | + return; |
|
262 | + } |
|
253 | 263 | if( in_array( $field->field['type'], ['radio', 'checkbox'] )) { |
254 | 264 | $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
255 | 265 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'response' => $this->buildResponse(), |
66 | 66 | 'submit_button' => $this->buildSubmitButton().$this->buildRecaptcha(), |
67 | 67 | ], |
68 | - ]); |
|
68 | + ] ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'context' => [ |
78 | 78 | 'text' => trim( $this->getLoginText().' '.$this->getRegisterText() ), |
79 | 79 | ], |
80 | - ]); |
|
80 | + ] ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,12 +86,12 @@ discard block |
||
86 | 86 | protected function buildRecaptcha() |
87 | 87 | { |
88 | 88 | if( !glsr( OptionManager::class )->isRecaptchaEnabled() )return; |
89 | - return glsr( Builder::class )->div([ |
|
89 | + return glsr( Builder::class )->div( [ |
|
90 | 90 | 'class' => 'glsr-recaptcha-holder', |
91 | 91 | 'data-badge' => glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.position' ), |
92 | - 'data-sitekey' => sanitize_text_field( glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.key' )), |
|
92 | + 'data-sitekey' => sanitize_text_field( glsr( OptionManager::class )->get( 'settings.submissions.recaptcha.key' ) ), |
|
93 | 93 | 'data-size' => 'invisible', |
94 | - ]); |
|
94 | + ] ); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function buildResponse() |
101 | 101 | { |
102 | - $classes = !empty( $this->errors ) |
|
102 | + $classes = !empty($this->errors) |
|
103 | 103 | ? glsr( StyleValidationDefaults::class )->defaults()['message_error_class'] |
104 | 104 | : ''; |
105 | 105 | return glsr( Template::class )->build( 'templates/form/response', [ |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | 'class' => $classes, |
108 | 108 | 'message' => wpautop( $this->message ), |
109 | 109 | ], |
110 | - 'has_errors' => !empty( $this->errors ), |
|
111 | - ]); |
|
110 | + 'has_errors' => !empty($this->errors), |
|
111 | + ] ); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | 'context' => [ |
121 | 121 | 'text' => __( 'Submit your review', 'site-reviews' ), |
122 | 122 | ], |
123 | - ]); |
|
123 | + ] ); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $fields = array_merge( |
140 | 140 | $this->getHiddenFields(), |
141 | 141 | [$this->getHoneypotField()], |
142 | - $this->normalizeFields( glsr( Form::class )->getFields( 'submission-form' )) |
|
142 | + $this->normalizeFields( glsr( Form::class )->getFields( 'submission-form' ) ) |
|
143 | 143 | ); |
144 | 144 | return $fields; |
145 | 145 | } |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | */ |
150 | 150 | protected function getLoginText() |
151 | 151 | { |
152 | - $loginLink = glsr( Builder::class )->a([ |
|
153 | - 'href' => wp_login_url( strval( get_permalink() )), |
|
152 | + $loginLink = glsr( Builder::class )->a( [ |
|
153 | + 'href' => wp_login_url( strval( get_permalink() ) ), |
|
154 | 154 | 'text' => __( 'logged in', 'site-reviews' ), |
155 | - ]); |
|
155 | + ] ); |
|
156 | 156 | return sprintf( __( 'You must be %s to submit a review.', 'site-reviews' ), $loginLink ); |
157 | 157 | } |
158 | 158 | |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | protected function getRegisterText() |
163 | 163 | { |
164 | 164 | if( !get_option( 'users_can_register' ) || glsr( OptionManager::class )->get( 'settings.general.require.login' ) != 'yes' )return; |
165 | - $registerLink = glsr( Builder::class )->a([ |
|
165 | + $registerLink = glsr( Builder::class )->a( [ |
|
166 | 166 | 'href' => wp_registration_url(), |
167 | 167 | 'text' => __( 'register', 'site-reviews' ), |
168 | - ]); |
|
168 | + ] ); |
|
169 | 169 | return sprintf( __( 'You may also %s for an account.', 'site-reviews' ), $registerLink ); |
170 | 170 | } |
171 | 171 | |
@@ -177,30 +177,30 @@ discard block |
||
177 | 177 | $fields = [[ |
178 | 178 | 'name' => 'action', |
179 | 179 | 'value' => 'submit-review', |
180 | - ],[ |
|
180 | + ], [ |
|
181 | 181 | 'name' => 'assign_to', |
182 | 182 | 'value' => $this->args['assign_to'], |
183 | - ],[ |
|
183 | + ], [ |
|
184 | 184 | 'name' => 'category', |
185 | 185 | 'value' => $this->args['category'], |
186 | - ],[ |
|
186 | + ], [ |
|
187 | 187 | 'name' => 'excluded', |
188 | 188 | 'value' => $this->args['excluded'], // @todo should default to "[]" |
189 | - ],[ |
|
189 | + ], [ |
|
190 | 190 | 'name' => 'form_id', |
191 | 191 | 'value' => $this->args['id'], |
192 | - ],[ |
|
192 | + ], [ |
|
193 | 193 | 'name' => 'nonce', |
194 | 194 | 'value' => wp_create_nonce( 'submit-review' ), |
195 | - ],[ |
|
195 | + ], [ |
|
196 | 196 | 'name' => 'post_id', |
197 | 197 | 'value' => get_the_ID(), |
198 | - ],[ |
|
198 | + ], [ |
|
199 | 199 | 'name' => 'referer', |
200 | - 'value' => wp_unslash( filter_input( INPUT_SERVER, 'REQUEST_URI' )), |
|
200 | + 'value' => wp_unslash( filter_input( INPUT_SERVER, 'REQUEST_URI' ) ), |
|
201 | 201 | ]]; |
202 | 202 | return array_map( function( $field ) { |
203 | - return new Field( wp_parse_args( $field, ['type' => 'hidden'] )); |
|
203 | + return new Field( wp_parse_args( $field, ['type' => 'hidden'] ) ); |
|
204 | 204 | }, $fields ); |
205 | 205 | } |
206 | 206 | |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | */ |
210 | 210 | protected function getHoneypotField() |
211 | 211 | { |
212 | - return new Field([ |
|
212 | + return new Field( [ |
|
213 | 213 | 'name' => 'gotcha', |
214 | 214 | 'type' => 'honeypot', |
215 | - ]); |
|
215 | + ] ); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | */ |
221 | 221 | protected function normalizeFieldClass( Field &$field ) |
222 | 222 | { |
223 | - if( !isset( $field->field['class'] )) { |
|
223 | + if( !isset($field->field['class']) ) { |
|
224 | 224 | $field->field['class'] = ''; |
225 | 225 | } |
226 | 226 | $field->field['class'] = trim( $field->field['class'].' glsr-field-control' ); |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | protected function normalizeFieldErrors( Field &$field ) |
233 | 233 | { |
234 | - if( !array_key_exists( $field->field['path'], $this->errors ))return; |
|
234 | + if( !array_key_exists( $field->field['path'], $this->errors ) )return; |
|
235 | 235 | $field->field['errors'] = $this->errors[$field->field['path']]; |
236 | 236 | } |
237 | 237 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | protected function normalizeFieldRequired( Field &$field ) |
242 | 242 | { |
243 | - if( !in_array( $field->field['path'], $this->required ))return; |
|
243 | + if( !in_array( $field->field['path'], $this->required ) )return; |
|
244 | 244 | $field->field['required'] = true; |
245 | 245 | } |
246 | 246 | |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | */ |
265 | 265 | protected function normalizeFieldValue( Field &$field ) |
266 | 266 | { |
267 | - if( !array_key_exists( $field->field['path'], $this->values ))return; |
|
268 | - if( in_array( $field->field['type'], ['radio', 'checkbox'] )) { |
|
267 | + if( !array_key_exists( $field->field['path'], $this->values ) )return; |
|
268 | + if( in_array( $field->field['type'], ['radio', 'checkbox'] ) ) { |
|
269 | 269 | $field->field['checked'] = $field->field['value'] == $this->values[$field->field['path']]; |
270 | 270 | } |
271 | 271 | else { |
@@ -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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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' => esc_attr__( '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 [ |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function __construct() |
34 | 34 | { |
35 | 35 | $types = glsr( OptionManager::class )->get( 'settings.general.notifications', [] ); |
36 | - $this->email = count( array_intersect( ['admin', 'custom'], $types )) > 0; |
|
36 | + $this->email = count( array_intersect( ['admin', 'custom'], $types ) ) > 0; |
|
37 | 37 | $this->slack = in_array( 'slack', $types ); |
38 | 38 | $this->types = $types; |
39 | 39 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function send( Review $review ) |
45 | 45 | { |
46 | - if( empty( $this->types ))return; |
|
46 | + if( empty($this->types) )return; |
|
47 | 47 | $this->review = $review; |
48 | 48 | $args = [ |
49 | 49 | 'link' => $this->getLink(), |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | protected function buildEmail( array $args ) |
60 | 60 | { |
61 | - return glsr( Email::class )->compose([ |
|
61 | + return glsr( Email::class )->compose( [ |
|
62 | 62 | 'to' => $this->getEmailAddresses(), |
63 | 63 | 'subject' => $args['title'], |
64 | 64 | 'template' => 'email-notification', |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | 'review_rating' => $this->review->rating, |
72 | 72 | 'review_title' => $this->review->title, |
73 | 73 | ], |
74 | - ]); |
|
74 | + ] ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | 'button_url' => $args['link'], |
84 | 84 | 'fallback' => $this->buildEmail( $args )->read( 'plaintext' ), |
85 | 85 | 'pretext' => $args['title'], |
86 | - ]); |
|
86 | + ] ); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -92,23 +92,23 @@ discard block |
||
92 | 92 | protected function getEmailAddresses() |
93 | 93 | { |
94 | 94 | $emails = []; |
95 | - if( in_array( 'admin', $this->types )) { |
|
95 | + if( in_array( 'admin', $this->types ) ) { |
|
96 | 96 | $emails[] = get_option( 'admin_email' ); |
97 | 97 | } |
98 | - if( in_array( 'author', $this->types )) { |
|
99 | - $assignedPost = get_post( intval( $this->review->assigned_to )); |
|
98 | + if( in_array( 'author', $this->types ) ) { |
|
99 | + $assignedPost = get_post( intval( $this->review->assigned_to ) ); |
|
100 | 100 | if( $assignedPost instanceof WP_Post ) { |
101 | 101 | $this->email = true; |
102 | - $emails[] = get_the_author_meta( 'user_email', intval( $assignedPost->post_author )); |
|
102 | + $emails[] = get_the_author_meta( 'user_email', intval( $assignedPost->post_author ) ); |
|
103 | 103 | } |
104 | 104 | } |
105 | - if( in_array( 'custom', $this->types )) { |
|
105 | + if( in_array( 'custom', $this->types ) ) { |
|
106 | 106 | $customEmails = glsr( OptionManager::class )->get( 'settings.general.notification_email' ); |
107 | 107 | $customEmails = str_replace( [' ', ',', ';'], ',', $customEmails ); |
108 | 108 | $customEmails = explode( ',', $customEmails ); |
109 | 109 | $emails = array_merge( $emails, $customEmails ); |
110 | 110 | } |
111 | - $emails = array_filter( array_keys( array_flip( $emails ))); |
|
111 | + $emails = array_filter( array_keys( array_flip( $emails ) ) ); |
|
112 | 112 | return apply_filters( 'site-reviews/notification/emails', $emails, $this->review ); |
113 | 113 | } |
114 | 114 | |
@@ -125,16 +125,16 @@ discard block |
||
125 | 125 | */ |
126 | 126 | protected function getTitle() |
127 | 127 | { |
128 | - $assignedTitle = get_the_title( intval( $this->review->assigned_to )); |
|
128 | + $assignedTitle = get_the_title( intval( $this->review->assigned_to ) ); |
|
129 | 129 | $title = _nx( |
130 | 130 | 'New %s-star review', |
131 | 131 | 'New %s-star review of: %s', |
132 | - intval( empty( $assignedTitle )), |
|
132 | + intval( empty($assignedTitle) ), |
|
133 | 133 | 'This string differs depending on whether or not the review has been assigned to a post.', |
134 | 134 | 'site-reviews' |
135 | 135 | ); |
136 | 136 | $title = sprintf( '[%s] %s', |
137 | - wp_specialchars_decode( strval( get_option( 'blogname' )), ENT_QUOTES ), |
|
137 | + wp_specialchars_decode( strval( get_option( 'blogname' ) ), ENT_QUOTES ), |
|
138 | 138 | sprintf( $title, $this->review->rating, $assignedTitle ) |
139 | 139 | ); |
140 | 140 | return apply_filters( 'site-reviews/notification/title', $title, $this->review ); |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | $email = $this->buildEmail( $args ); |
149 | 149 | if( !$this->email )return; |
150 | - if( empty( $email->to )) { |
|
150 | + if( empty($email->to) ) { |
|
151 | 151 | glsr_log()->error( 'Email notification was not sent: missing email address' ); |
152 | 152 | return; |
153 | 153 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | if( !$this->slack )return; |
165 | 165 | $notification = $this->buildSlackNotification( $args ); |
166 | 166 | $result = $notification->send(); |
167 | - if( is_wp_error( $result )) { |
|
167 | + if( is_wp_error( $result ) ) { |
|
168 | 168 | $notification->review = null; |
169 | 169 | glsr_log()->error( $result->get_error_message() )->debug( $notification ); |
170 | 170 | } |
@@ -43,7 +43,9 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function send( Review $review ) |
45 | 45 | { |
46 | - if( empty( $this->types ))return; |
|
46 | + if( empty( $this->types )) { |
|
47 | + return; |
|
48 | + } |
|
47 | 49 | $this->review = $review; |
48 | 50 | $args = [ |
49 | 51 | 'link' => $this->getLink(), |
@@ -146,7 +148,9 @@ discard block |
||
146 | 148 | protected function sendToEmail( array $args ) |
147 | 149 | { |
148 | 150 | $email = $this->buildEmail( $args ); |
149 | - if( !$this->email )return; |
|
151 | + if( !$this->email ) { |
|
152 | + return; |
|
153 | + } |
|
150 | 154 | if( empty( $email->to )) { |
151 | 155 | glsr_log()->error( 'Email notification was not sent: missing email address' ); |
152 | 156 | return; |
@@ -161,7 +165,9 @@ discard block |
||
161 | 165 | */ |
162 | 166 | protected function sendToSlack( array $args ) |
163 | 167 | { |
164 | - if( !$this->slack )return; |
|
168 | + if( !$this->slack ) { |
|
169 | + return; |
|
170 | + } |
|
165 | 171 | $notification = $this->buildSlackNotification( $args ); |
166 | 172 | $result = $notification->send(); |
167 | 173 | if( is_wp_error( $result )) { |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public function isBlacklisted( array $review ) |
13 | 13 | { |
14 | - $target = implode( "\n", array_filter([ |
|
14 | + $target = implode( "\n", array_filter( [ |
|
15 | 15 | $review['name'], |
16 | 16 | $review['content'], |
17 | 17 | $review['email'], |
18 | 18 | $review['ip_address'], |
19 | 19 | $review['title'], |
20 | - ])); |
|
20 | + ] ) ); |
|
21 | 21 | return (bool)apply_filters( 'site-reviews/blacklist/is-blacklisted', |
22 | 22 | $this->check( $target ), |
23 | 23 | $review |
@@ -30,16 +30,16 @@ discard block |
||
30 | 30 | */ |
31 | 31 | protected function check( $target ) |
32 | 32 | { |
33 | - $blacklist = trim( glsr( OptionManager::class )->get( 'settings.submissions.blacklist.entries' )); |
|
34 | - if( empty( $blacklist )) { |
|
33 | + $blacklist = trim( glsr( OptionManager::class )->get( 'settings.submissions.blacklist.entries' ) ); |
|
34 | + if( empty($blacklist) ) { |
|
35 | 35 | return false; |
36 | 36 | } |
37 | 37 | $lines = explode( "\n", $blacklist ); |
38 | 38 | foreach( (array)$lines as $line ) { |
39 | 39 | $line = trim( $line ); |
40 | - if( empty( $line ) || 256 < strlen( $line ))continue; |
|
41 | - $pattern = sprintf( '#%s#i', preg_quote( $line, '#' )); |
|
42 | - if( preg_match( $pattern, $target )) { |
|
40 | + if( empty($line) || 256 < strlen( $line ) )continue; |
|
41 | + $pattern = sprintf( '#%s#i', preg_quote( $line, '#' ) ); |
|
42 | + if( preg_match( $pattern, $target ) ) { |
|
43 | 43 | return true; |
44 | 44 | } |
45 | 45 | } |
@@ -37,7 +37,9 @@ |
||
37 | 37 | $lines = explode( "\n", $blacklist ); |
38 | 38 | foreach( (array)$lines as $line ) { |
39 | 39 | $line = trim( $line ); |
40 | - if( empty( $line ) || 256 < strlen( $line ))continue; |
|
40 | + if( empty( $line ) || 256 < strlen( $line )) { |
|
41 | + continue; |
|
42 | + } |
|
41 | 43 | $pattern = sprintf( '#%s#i', preg_quote( $line, '#' )); |
42 | 44 | if( preg_match( $pattern, $target )) { |
43 | 45 | return true; |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function __get( $key ) |
21 | 21 | { |
22 | - if( array_key_exists( $key, $this->values )) { |
|
22 | + if( array_key_exists( $key, $this->values ) ) { |
|
23 | 23 | return $this->values[$key]; |
24 | 24 | } |
25 | 25 | return ''; |
@@ -17,7 +17,7 @@ |
||
17 | 17 | 'avatar' => '', |
18 | 18 | 'content' => '', |
19 | 19 | 'custom' => '', |
20 | - 'date' => get_date_from_gmt( gmdate( 'Y-m-d H:i:s' )), |
|
20 | + 'date' => get_date_from_gmt( gmdate( 'Y-m-d H:i:s' ) ), |
|
21 | 21 | 'email' => '', |
22 | 22 | 'ip_address' => '', |
23 | 23 | 'pinned' => false, |