@@ -64,7 +64,9 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function send() |
66 | 66 | { |
67 | - if( !$this->message || !$this->subject || !$this->to )return; |
|
67 | + if( !$this->message || !$this->subject || !$this->to ) { |
|
68 | + return; |
|
69 | + } |
|
68 | 70 | $sent = wp_mail( |
69 | 71 | $this->to, |
70 | 72 | $this->subject, |
@@ -83,7 +85,9 @@ discard block |
||
83 | 85 | */ |
84 | 86 | public function buildPlainTextMessage( $phpmailer ) |
85 | 87 | { |
86 | - if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return; |
|
88 | + if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody )) { |
|
89 | + return; |
|
90 | + } |
|
87 | 91 | $message = $this->stripHtmlTags( $phpmailer->Body ); |
88 | 92 | $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
89 | 93 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $this->message = $this->buildHtmlMessage( $email ); |
44 | 44 | $this->subject = $email['subject']; |
45 | 45 | $this->to = $email['to']; |
46 | - add_action( 'phpmailer_init', [ $this, 'buildPlainTextMessage'] ); |
|
46 | + add_action( 'phpmailer_init', [$this, 'buildPlainTextMessage'] ); |
|
47 | 47 | return $this; |
48 | 48 | } |
49 | 49 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function buildPlainTextMessage( $phpmailer ) |
85 | 85 | { |
86 | - if( $phpmailer->ContentType === 'text/plain' || !empty( $phpmailer->AltBody ))return; |
|
86 | + if( $phpmailer->ContentType === 'text/plain' || !empty($phpmailer->AltBody) )return; |
|
87 | 87 | $message = $this->stripHtmlTags( $phpmailer->Body ); |
88 | 88 | $phpmailer->AltBody = apply_filters( 'site-reviews/email/message', $message, 'text', $this ); |
89 | 89 | } |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | 'from', |
100 | 100 | 'reply-to', |
101 | 101 | ]; |
102 | - $headers = array_intersect_key( $email, array_flip( $allowed )); |
|
102 | + $headers = array_intersect_key( $email, array_flip( $allowed ) ); |
|
103 | 103 | $headers = array_filter( $headers ); |
104 | 104 | foreach( $headers as $key => $value ) { |
105 | - unset( $headers[ $key ] ); |
|
105 | + unset($headers[$key]); |
|
106 | 106 | $headers[] = "{$key}: {$value}"; |
107 | 107 | } |
108 | 108 | $headers[] = 'Content-Type: text/html'; |
@@ -114,16 +114,16 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function buildHtmlMessage( $email ) |
116 | 116 | { |
117 | - $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' )); |
|
118 | - if( !empty( $template )) { |
|
117 | + $template = trim( glsr( OptionManager::class )->get( 'settings.general.notification_message' ) ); |
|
118 | + if( !empty($template) ) { |
|
119 | 119 | $message = glsr( Template::class )->interpolate( $template, $email['template-tags'] ); |
120 | 120 | } |
121 | 121 | else if( $email['template'] ) { |
122 | 122 | $message = glsr( Template::class )->build( 'templates/'.$email['template'], [ |
123 | 123 | 'context' => $email['template-tags'], |
124 | - ]); |
|
124 | + ] ); |
|
125 | 125 | } |
126 | - if( !isset( $message )) { |
|
126 | + if( !isset($message) ) { |
|
127 | 127 | $message = $email['message']; |
128 | 128 | } |
129 | 129 | $message = $email['before'].$message.$email['after']; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $message = str_replace( ']]>', ']]>', $message ); |
135 | 135 | $message = glsr( Template::class )->build( 'partials/email/index', [ |
136 | 136 | 'context' => ['message' => $message], |
137 | - ]); |
|
137 | + ] ); |
|
138 | 138 | return apply_filters( 'site-reviews/email/message', stripslashes( $message ), 'html', $this ); |
139 | 139 | } |
140 | 140 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | 'to' => '', |
161 | 161 | ]; |
162 | 162 | $email = shortcode_atts( $defaults, $email ); |
163 | - if( empty( $email['reply-to'] )) { |
|
163 | + if( empty($email['reply-to']) ) { |
|
164 | 164 | $email['reply-to'] = $email['from']; |
165 | 165 | } |
166 | 166 | return apply_filters( 'site-reviews/email/compose', $email, $this ); |
@@ -13,7 +13,7 @@ |
||
13 | 13 | public function build( $partialPath, array $args = [] ) |
14 | 14 | { |
15 | 15 | $className = glsr( Helper::class )->buildClassName( $partialPath, 'Modules\Html\Partials' ); |
16 | - if( !class_exists( $className )) { |
|
16 | + if( !class_exists( $className ) ) { |
|
17 | 17 | glsr_log()->error( 'Partial missing: '.$className ); |
18 | 18 | return; |
19 | 19 | } |
@@ -190,7 +190,9 @@ |
||
190 | 190 | if( $index === false |
191 | 191 | || !isset( $caller[$index+2]['class'] ) |
192 | 192 | || !isset( $caller[$index+2]['function'] ) |
193 | - )return; |
|
193 | + ) { |
|
194 | + return; |
|
195 | + } |
|
194 | 196 | return sprintf( '[%s()->%s:%s] ', |
195 | 197 | $caller[$index+2]['class'], |
196 | 198 | $caller[$index+2]['function'], |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function get() |
110 | 110 | { |
111 | - return empty( $this->log ) |
|
111 | + return empty($this->log) |
|
112 | 112 | ? __( 'Log is empty', 'site-reviews' ) |
113 | 113 | : $this->log; |
114 | 114 | } |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | { |
135 | 135 | $constants = (new ReflectionClass( __CLASS__ ))->getConstants(); |
136 | 136 | $constants = (array)apply_filters( 'site-reviews/log-levels', $constants ); |
137 | - if( in_array( $level, $constants, true )) { |
|
137 | + if( in_array( $level, $constants, true ) ) { |
|
138 | 138 | $entry = $this->buildLogEntry( $level, $message, $context ); |
139 | - file_put_contents( $this->file, $entry, FILE_APPEND|LOCK_EX ); |
|
139 | + file_put_contents( $this->file, $entry, FILE_APPEND | LOCK_EX ); |
|
140 | 140 | $this->reset(); |
141 | 141 | } |
142 | 142 | return $this; |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | protected function getDebugInformation() |
187 | 187 | { |
188 | 188 | $caller = debug_backtrace( 0, 6 ); |
189 | - $index = array_search( 'log', array_column( $caller, 'function' )); |
|
189 | + $index = array_search( 'log', array_column( $caller, 'function' ) ); |
|
190 | 190 | if( $index === false |
191 | - || !isset( $caller[$index+2]['class'] ) |
|
192 | - || !isset( $caller[$index+2]['function'] ) |
|
191 | + || !isset($caller[$index + 2]['class']) |
|
192 | + || !isset($caller[$index + 2]['function']) |
|
193 | 193 | )return; |
194 | 194 | return sprintf( '[%s()->%s:%s] ', |
195 | - $caller[$index+2]['class'], |
|
196 | - $caller[$index+2]['function'], |
|
197 | - $caller[$index+1]['line'] |
|
195 | + $caller[$index + 2]['class'], |
|
196 | + $caller[$index + 2]['function'], |
|
197 | + $caller[$index + 1]['line'] |
|
198 | 198 | ); |
199 | 199 | } |
200 | 200 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | protected function interpolate( $message, $context = [] ) |
208 | 208 | { |
209 | - if( $this->isObjectOrArray( $message ) || !is_array( $context )) { |
|
209 | + if( $this->isObjectOrArray( $message ) || !is_array( $context ) ) { |
|
210 | 210 | return print_r( $message, true ); |
211 | 211 | } |
212 | 212 | $replace = []; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | if( $value instanceof DateTime ) { |
235 | 235 | $value = $value->format( 'Y-m-d H:i:s' ); |
236 | 236 | } |
237 | - else if( $this->isObjectOrArray( $value )) { |
|
237 | + else if( $this->isObjectOrArray( $value ) ) { |
|
238 | 238 | $value = json_encode( $value ); |
239 | 239 | } |
240 | 240 | return (string)$value; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $this->clear(); |
251 | 251 | file_put_contents( |
252 | 252 | $this->file, |
253 | - $this->buildLogEntry( 'info', __( 'Log has been automatically reset (512 KB max size)', 'site-reviews' )) |
|
253 | + $this->buildLogEntry( 'info', __( 'Log has been automatically reset (512 KB max size)', 'site-reviews' ) ) |
|
254 | 254 | ); |
255 | 255 | } |
256 | 256 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | public function __construct( $input ) |
11 | 11 | { |
12 | 12 | $this->id = $input['id']; |
13 | - $this->pinned = isset( $input['pinned'] ) |
|
13 | + $this->pinned = isset($input['pinned']) |
|
14 | 14 | ? wp_validate_boolean( $input['pinned'] ) |
15 | 15 | : null; |
16 | 16 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | 'author' => '', |
17 | 17 | 'avatar' => '', |
18 | 18 | 'content' => '', |
19 | - 'date' => get_date_from_gmt( gmdate( 'Y-m-d H:i:s' )), |
|
19 | + 'date' => get_date_from_gmt( gmdate( 'Y-m-d H:i:s' ) ), |
|
20 | 20 | 'email' => '', |
21 | 21 | 'ip_address' => '', |
22 | 22 | 'pinned' => false, |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public static function isPhpValid( $version = '' ) |
34 | 34 | { |
35 | - if( !empty( $version )) { |
|
36 | - static::normalize( array( 'php' => $version )); |
|
35 | + if( !empty($version) ) { |
|
36 | + static::normalize( array( 'php' => $version ) ); |
|
37 | 37 | } |
38 | 38 | return !version_compare( PHP_VERSION, static::$versions->php, '<' ); |
39 | 39 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static function isValid( array $args = array() ) |
45 | 45 | { |
46 | - if( !empty( $args )) { |
|
46 | + if( !empty($args) ) { |
|
47 | 47 | static::normalize( $args ); |
48 | 48 | } |
49 | 49 | return static::isPhpValid() && static::isWpValid(); |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | public static function isWpValid( $version = '' ) |
57 | 57 | { |
58 | 58 | global $wp_version; |
59 | - if( !empty( $version )) { |
|
60 | - static::normalize( array( 'wordpress' => $version )); |
|
59 | + if( !empty($version) ) { |
|
60 | + static::normalize( array( 'wordpress' => $version ) ); |
|
61 | 61 | } |
62 | 62 | return !version_compare( $wp_version, static::$versions->wordpress, '<' ); |
63 | 63 | } |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public static function shouldDeactivate( $file, array $args = array() ) |
70 | 70 | { |
71 | - if( empty( static::$instance )) { |
|
71 | + if( empty(static::$instance) ) { |
|
72 | 72 | static::$file = realpath( $file ); |
73 | 73 | static::$instance = new static; |
74 | 74 | static::$versions = static::normalize( $args ); |
75 | 75 | } |
76 | 76 | if( !static::isValid() ) { |
77 | - add_action( 'activated_plugin', array( static::$instance, 'deactivate' )); |
|
78 | - add_action( 'admin_notices', array( static::$instance, 'deactivate' )); |
|
77 | + add_action( 'activated_plugin', array( static::$instance, 'deactivate' ) ); |
|
78 | + add_action( 'admin_notices', array( static::$instance, 'deactivate' ) ); |
|
79 | 79 | return true; |
80 | 80 | } |
81 | 81 | return false; |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | return (object)wp_parse_args( $args, array( |
106 | 106 | 'php' => static::MIN_PHP_VERSION, |
107 | 107 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
108 | - )); |
|
108 | + ) ); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | filter_input( INPUT_GET, 'plugin_status' ), |
118 | 118 | filter_input( INPUT_GET, 'paged' ), |
119 | 119 | filter_input( INPUT_GET, 's' ) |
120 | - ))); |
|
120 | + ) ) ); |
|
121 | 121 | exit; |
122 | 122 | } |
123 | 123 |
@@ -87,7 +87,9 @@ |
||
87 | 87 | */ |
88 | 88 | public function deactivate( $plugin ) |
89 | 89 | { |
90 | - if( static::isValid() )return; |
|
90 | + if( static::isValid() ) { |
|
91 | + return; |
|
92 | + } |
|
91 | 93 | $pluginSlug = plugin_basename( static::$file ); |
92 | 94 | if( $plugin == $pluginSlug ) { |
93 | 95 | $this->redirect(); //exit |
@@ -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 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | $diff = time() - strtotime( $date ); |
32 | 32 | foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
33 | 33 | if( $diff > $timePeriod[0] )continue; |
34 | - $unit = intval( floor( $diff / $timePeriod[1] )); |
|
34 | + $unit = intval( floor( $diff / $timePeriod[1] ) ); |
|
35 | 35 | $relativeDates = [ |
36 | 36 | _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
37 | 37 | _n( '%s minute ago', '%s minutes ago', $unit, 'site-reviews' ), |
@@ -30,7 +30,9 @@ |
||
30 | 30 | { |
31 | 31 | $diff = time() - strtotime( $date ); |
32 | 32 | foreach( static::$TIME_PERIODS as $i => $timePeriod ) { |
33 | - if( $diff > $timePeriod[0] )continue; |
|
33 | + if( $diff > $timePeriod[0] ) { |
|
34 | + continue; |
|
35 | + } |
|
34 | 36 | $unit = intval( floor( $diff / $timePeriod[1] )); |
35 | 37 | $relativeDates = [ |
36 | 38 | _n( '%s second ago', '%s seconds ago', $unit, 'site-reviews' ), |
@@ -161,7 +161,9 @@ discard block |
||
161 | 161 | if( !empty( $sessions )) { |
162 | 162 | $now = time(); |
163 | 163 | foreach( $sessions as $session ) { |
164 | - if( $now <= $session->expiration )continue; |
|
164 | + if( $now <= $session->expiration ) { |
|
165 | + continue; |
|
166 | + } |
|
165 | 167 | $expiredSessions[] = $session->name; |
166 | 168 | $expiredSessions[] = str_replace( '_expires_', '_', $session->name ); |
167 | 169 | } |
@@ -204,7 +206,9 @@ discard block |
||
204 | 206 | */ |
205 | 207 | protected function setCookie() |
206 | 208 | { |
207 | - if( headers_sent() )return; |
|
209 | + if( headers_sent() ) { |
|
210 | + return; |
|
211 | + } |
|
208 | 212 | $cookie = $this->sessionId.'||'.$this->expiryTimestamp.'||'.$this->expiryTimestampReset; |
209 | 213 | $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
210 | 214 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | |
35 | 35 | public function __construct() |
36 | 36 | { |
37 | - if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE )) { |
|
38 | - $cookie = explode( '||', stripslashes( $cookieId )); |
|
37 | + if( $cookieId = filter_input( INPUT_COOKIE, static::SESSION_COOKIE ) ) { |
|
38 | + $cookie = explode( '||', stripslashes( $cookieId ) ); |
|
39 | 39 | $this->sessionId = preg_replace( '/[^A-Za-z0-9_]/', '', $cookie[0] ); |
40 | 40 | $this->expiryTimestamp = absint( $cookie[1] ); |
41 | 41 | $this->expiryTimestampReset = absint( $cookie[2] ); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function deleteExpiredSessions( $limit = 1000 ) |
77 | 77 | { |
78 | - if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ))) { |
|
78 | + if( $expiredSessions = implode( "','", $this->getExpiredSessions( $limit ) ) ) { |
|
79 | 79 | glsr( SqlQueries::class )->deleteExpiredSessions( $expiredSessions ); |
80 | 80 | } |
81 | 81 | } |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | public function get( $key, $fallback = '', $unset = false ) |
90 | 90 | { |
91 | 91 | $key = sanitize_key( $key ); |
92 | - $value = isset( $this->sessionData[$key] ) |
|
92 | + $value = isset($this->sessionData[$key]) |
|
93 | 93 | ? maybe_unserialize( $this->sessionData[$key] ) |
94 | 94 | : $fallback; |
95 | - if( isset( $this->sessionData[$key] ) && $unset ) { |
|
96 | - unset( $this->sessionData[$key] ); |
|
95 | + if( isset($this->sessionData[$key]) && $unset ) { |
|
96 | + unset($this->sessionData[$key]); |
|
97 | 97 | $this->updateSession(); |
98 | 98 | } |
99 | 99 | return $value; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | protected function deleteSession() |
128 | 128 | { |
129 | 129 | delete_option( $this->getSessionId() ); |
130 | - delete_option( $this->getSessionId( 'expires' )); |
|
130 | + delete_option( $this->getSessionId( 'expires' ) ); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | protected function generateSessionId() |
137 | 137 | { |
138 | - return md5(( new PasswordHash( 8, false ))->get_random_bytes( 32 )); |
|
138 | + return md5( (new PasswordHash( 8, false ))->get_random_bytes( 32 ) ); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | protected function getExpiredSessions( $limit ) |
146 | 146 | { |
147 | 147 | $expiredSessions = []; |
148 | - $sessions = glsr( SqlQueries::class )->getExpiredSessions( static::SESSION_COOKIE, absint( $limit )); |
|
149 | - if( !empty( $sessions )) { |
|
148 | + $sessions = glsr( SqlQueries::class )->getExpiredSessions( static::SESSION_COOKIE, absint( $limit ) ); |
|
149 | + if( !empty($sessions) ) { |
|
150 | 150 | $now = time(); |
151 | 151 | foreach( $sessions as $session ) { |
152 | 152 | if( $now <= $session->expiration )continue; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | protected function getSessionId( $separator = '' ) |
165 | 165 | { |
166 | - return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] )); |
|
166 | + return implode( '_', array_filter( [static::SESSION_COOKIE, $separator, $this->sessionId] ) ); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | { |
195 | 195 | if( headers_sent() )return; |
196 | 196 | $cookie = $this->sessionId.'||'.$this->expiryTimestamp.'||'.$this->expiryTimestampReset; |
197 | - $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ))); |
|
197 | + $cookiePath = preg_replace( '|https?://[^/]+|i', '', trailingslashit( (string)get_option( 'home' ) ) ); |
|
198 | 198 | setcookie( static::SESSION_COOKIE, $cookie, $this->expiryTimestamp, $cookiePath ); |
199 | 199 | } |
200 | 200 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | protected function updateSession() |
214 | 214 | { |
215 | - if( false === get_option( $this->getSessionId() )) { |
|
215 | + if( false === get_option( $this->getSessionId() ) ) { |
|
216 | 216 | return $this->createSession(); |
217 | 217 | } |
218 | 218 | update_option( $this->getSessionId(), $this->sessionData, false ); |