@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | */ |
11 | 11 | |
12 | 12 | // Exit if accessed directly. |
13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
13 | +if ( ! defined('ABSPATH')) { |
|
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | public function __construct() { |
107 | 107 | |
108 | 108 | // get it started |
109 | - add_action( 'init', array( $this, 'init' ) ); |
|
109 | + add_action('init', array($this, 'init')); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -122,28 +122,28 @@ discard block |
||
122 | 122 | public function init() { |
123 | 123 | |
124 | 124 | // Bail Out, if user is logged in. |
125 | - if ( is_user_logged_in() ) { |
|
125 | + if (is_user_logged_in()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | 129 | // Are db columns setup? |
130 | - $column_exists = Give()->donors->does_column_exist( 'token' ); |
|
131 | - if ( ! $column_exists ) { |
|
130 | + $column_exists = Give()->donors->does_column_exist('token'); |
|
131 | + if ( ! $column_exists) { |
|
132 | 132 | $this->create_columns(); |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Timeouts. |
136 | - $this->verify_throttle = apply_filters( 'give_nl_verify_throttle', 300 ); |
|
137 | - $this->limit_throttle = apply_filters( 'give_nl_limit_throttle', 3 ); |
|
138 | - $this->token_expiration = apply_filters( 'give_nl_token_expiration', 7200 ); |
|
136 | + $this->verify_throttle = apply_filters('give_nl_verify_throttle', 300); |
|
137 | + $this->limit_throttle = apply_filters('give_nl_limit_throttle', 3); |
|
138 | + $this->token_expiration = apply_filters('give_nl_token_expiration', 7200); |
|
139 | 139 | |
140 | 140 | // Setup login. |
141 | 141 | $this->check_for_token(); |
142 | 142 | |
143 | - if ( $this->token_exists ) { |
|
144 | - add_filter( 'give_can_view_receipt', '__return_true' ); |
|
145 | - add_filter( 'give_user_pending_verification', '__return_false' ); |
|
146 | - add_filter( 'give_get_users_donations_args', array( $this, 'users_donations_args' ) ); |
|
143 | + if ($this->token_exists) { |
|
144 | + add_filter('give_can_view_receipt', '__return_true'); |
|
145 | + add_filter('give_user_pending_verification', '__return_false'); |
|
146 | + add_filter('give_get_users_donations_args', array($this, 'users_donations_args')); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | } |
@@ -158,23 +158,23 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @return bool |
160 | 160 | */ |
161 | - public function can_send_email( $donor_id ) { |
|
161 | + public function can_send_email($donor_id) { |
|
162 | 162 | |
163 | - $donor = Give()->donors->get_donor_by( 'id', $donor_id ); |
|
163 | + $donor = Give()->donors->get_donor_by('id', $donor_id); |
|
164 | 164 | |
165 | - if ( is_object( $donor ) ) { |
|
165 | + if (is_object($donor)) { |
|
166 | 166 | |
167 | - $email_throttle_count = (int) give_get_meta( $donor_id, '_give_email_throttle_count', true ); |
|
167 | + $email_throttle_count = (int) give_get_meta($donor_id, '_give_email_throttle_count', true); |
|
168 | 168 | |
169 | 169 | $cache_key = "give_cache_email_throttle_limit_exhausted_{$donor_id}"; |
170 | 170 | if ( |
171 | 171 | $email_throttle_count < $this->limit_throttle && |
172 | - true !== Give_Cache::get( $cache_key ) |
|
172 | + true !== Give_Cache::get($cache_key) |
|
173 | 173 | ) { |
174 | - give_update_meta( $donor_id, '_give_email_throttle_count', $email_throttle_count + 1 ); |
|
174 | + give_update_meta($donor_id, '_give_email_throttle_count', $email_throttle_count + 1); |
|
175 | 175 | } else { |
176 | - give_update_meta( $donor_id, '_give_email_throttle_count', 0 ); |
|
177 | - Give_Cache::set( $cache_key, true, $this->verify_throttle ); |
|
176 | + give_update_meta($donor_id, '_give_email_throttle_count', 0); |
|
177 | + Give_Cache::set($cache_key, true, $this->verify_throttle); |
|
178 | 178 | return false; |
179 | 179 | } |
180 | 180 | |
@@ -194,8 +194,8 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @return bool |
196 | 196 | */ |
197 | - public function send_email( $donor_id, $email ) { |
|
198 | - return apply_filters( 'give_email-access_email_notification', $donor_id, $email ); |
|
197 | + public function send_email($donor_id, $email) { |
|
198 | + return apply_filters('give_email-access_email_notification', $donor_id, $email); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -208,28 +208,28 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function check_for_token() { |
210 | 210 | |
211 | - $token = isset( $_GET['give_nl'] ) ? give_clean( $_GET['give_nl'] ) : ''; |
|
211 | + $token = isset($_GET['give_nl']) ? give_clean($_GET['give_nl']) : ''; |
|
212 | 212 | |
213 | 213 | // Check for cookie. |
214 | - if ( empty( $token ) ) { |
|
215 | - $token = isset( $_COOKIE['give_nl'] ) ? give_clean( $_COOKIE['give_nl'] ) : ''; |
|
214 | + if (empty($token)) { |
|
215 | + $token = isset($_COOKIE['give_nl']) ? give_clean($_COOKIE['give_nl']) : ''; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | // Must have a token. |
219 | - if ( ! empty( $token ) ) { |
|
219 | + if ( ! empty($token)) { |
|
220 | 220 | |
221 | - if ( ! $this->is_valid_token( $token ) ) { |
|
222 | - if ( ! $this->is_valid_verify_key( $token ) ) { |
|
221 | + if ( ! $this->is_valid_token($token)) { |
|
222 | + if ( ! $this->is_valid_verify_key($token)) { |
|
223 | 223 | return false; |
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | 227 | // Set Receipt Access Session. |
228 | - Give()->session->set( 'receipt_access', true ); |
|
228 | + Give()->session->set('receipt_access', true); |
|
229 | 229 | $this->token_exists = true; |
230 | 230 | // Set cookie. |
231 | - $lifetime = current_time( 'timestamp' ) + Give()->session->set_expiration_time(); |
|
232 | - @setcookie( 'give_nl', $token, $lifetime, COOKIEPATH, COOKIE_DOMAIN, false ); |
|
231 | + $lifetime = current_time('timestamp') + Give()->session->set_expiration_time(); |
|
232 | + @setcookie('give_nl', $token, $lifetime, COOKIEPATH, COOKIE_DOMAIN, false); |
|
233 | 233 | |
234 | 234 | return true; |
235 | 235 | } |
@@ -245,26 +245,26 @@ discard block |
||
245 | 245 | * |
246 | 246 | * @return bool |
247 | 247 | */ |
248 | - public function is_valid_token( $token ) { |
|
248 | + public function is_valid_token($token) { |
|
249 | 249 | |
250 | 250 | global $wpdb; |
251 | 251 | |
252 | 252 | // Make sure token isn't expired. |
253 | - $expires = date( 'Y-m-d H:i:s', time() - $this->token_expiration ); |
|
253 | + $expires = date('Y-m-d H:i:s', time() - $this->token_expiration); |
|
254 | 254 | |
255 | 255 | $email = $wpdb->get_var( |
256 | - $wpdb->prepare( "SELECT email FROM {$wpdb->donors} WHERE verify_key = %s AND verify_throttle >= %s LIMIT 1", $token, $expires ) |
|
256 | + $wpdb->prepare("SELECT email FROM {$wpdb->donors} WHERE verify_key = %s AND verify_throttle >= %s LIMIT 1", $token, $expires) |
|
257 | 257 | ); |
258 | 258 | |
259 | - if ( ! empty( $email ) ) { |
|
259 | + if ( ! empty($email)) { |
|
260 | 260 | $this->token_email = $email; |
261 | 261 | $this->token = $token; |
262 | 262 | return true; |
263 | 263 | } |
264 | 264 | |
265 | 265 | // Set error only if email access form isn't being submitted. |
266 | - if ( ! isset( $_POST['give_email'] ) && ! isset( $_POST['_wpnonce'] ) ) { |
|
267 | - give_set_error( 'give_email_token_expired', apply_filters( 'give_email_token_expired_message', __( 'Your access token has expired. Please request a new one below:', 'give' ) ) ); |
|
266 | + if ( ! isset($_POST['give_email']) && ! isset($_POST['_wpnonce'])) { |
|
267 | + give_set_error('give_email_token_expired', apply_filters('give_email_token_expired_message', __('Your access token has expired. Please request a new one below:', 'give'))); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | return false; |
@@ -283,25 +283,25 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @return void |
285 | 285 | */ |
286 | - public function set_verify_key( $donor_id, $email, $verify_key ) { |
|
286 | + public function set_verify_key($donor_id, $email, $verify_key) { |
|
287 | 287 | global $wpdb; |
288 | 288 | |
289 | - $now = date( 'Y-m-d H:i:s' ); |
|
289 | + $now = date('Y-m-d H:i:s'); |
|
290 | 290 | |
291 | 291 | // Insert or update? |
292 | 292 | $row_id = (int) $wpdb->get_var( |
293 | - $wpdb->prepare( "SELECT id FROM {$wpdb->donors} WHERE id = %d LIMIT 1", $donor_id ) |
|
293 | + $wpdb->prepare("SELECT id FROM {$wpdb->donors} WHERE id = %d LIMIT 1", $donor_id) |
|
294 | 294 | ); |
295 | 295 | |
296 | 296 | // Update. |
297 | - if ( ! empty( $row_id ) ) { |
|
297 | + if ( ! empty($row_id)) { |
|
298 | 298 | $wpdb->query( |
299 | - $wpdb->prepare( "UPDATE {$wpdb->donors} SET verify_key = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $verify_key, $now, $row_id ) |
|
299 | + $wpdb->prepare("UPDATE {$wpdb->donors} SET verify_key = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $verify_key, $now, $row_id) |
|
300 | 300 | ); |
301 | 301 | } // Insert. |
302 | 302 | else { |
303 | 303 | $wpdb->query( |
304 | - $wpdb->prepare( "INSERT INTO {$wpdb->donors} ( verify_key, verify_throttle) VALUES (%s, %s)", $verify_key, $now ) |
|
304 | + $wpdb->prepare("INSERT INTO {$wpdb->donors} ( verify_key, verify_throttle) VALUES (%s, %s)", $verify_key, $now) |
|
305 | 305 | ); |
306 | 306 | } |
307 | 307 | } |
@@ -316,21 +316,21 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @return bool |
318 | 318 | */ |
319 | - public function is_valid_verify_key( $token ) { |
|
319 | + public function is_valid_verify_key($token) { |
|
320 | 320 | /* @var WPDB $wpdb */ |
321 | 321 | global $wpdb; |
322 | 322 | |
323 | 323 | // See if the verify_key exists. |
324 | 324 | $row = $wpdb->get_row( |
325 | - $wpdb->prepare( "SELECT id, email FROM {$wpdb->donors} WHERE verify_key = %s LIMIT 1", $token ) |
|
325 | + $wpdb->prepare("SELECT id, email FROM {$wpdb->donors} WHERE verify_key = %s LIMIT 1", $token) |
|
326 | 326 | ); |
327 | 327 | |
328 | - $now = date( 'Y-m-d H:i:s' ); |
|
328 | + $now = date('Y-m-d H:i:s'); |
|
329 | 329 | |
330 | 330 | // Set token and remove verify key. |
331 | - if ( ! empty( $row ) ) { |
|
331 | + if ( ! empty($row)) { |
|
332 | 332 | $wpdb->query( |
333 | - $wpdb->prepare( "UPDATE {$wpdb->donors} SET verify_key = '', token = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $token, $now, $row->id ) |
|
333 | + $wpdb->prepare("UPDATE {$wpdb->donors} SET verify_key = '', token = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $token, $now, $row->id) |
|
334 | 334 | ); |
335 | 335 | |
336 | 336 | $this->token_email = $row->email; |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | * |
355 | 355 | * @return mixed |
356 | 356 | */ |
357 | - public function users_donations_args( $args ) { |
|
357 | + public function users_donations_args($args) { |
|
358 | 358 | $args['user'] = $this->token_email; |
359 | 359 | |
360 | 360 | return $args; |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | global $wpdb; |
376 | 376 | |
377 | 377 | // Create columns in donors table. |
378 | - $wpdb->query( "ALTER TABLE {$wpdb->donors} ADD `token` VARCHAR(255) CHARACTER SET utf8 NOT NULL, ADD `verify_key` VARCHAR(255) CHARACTER SET utf8 NOT NULL AFTER `token`, ADD `verify_throttle` DATETIME NOT NULL AFTER `verify_key`" ); |
|
378 | + $wpdb->query("ALTER TABLE {$wpdb->donors} ADD `token` VARCHAR(255) CHARACTER SET utf8 NOT NULL, ADD `verify_key` VARCHAR(255) CHARACTER SET utf8 NOT NULL AFTER `token`, ADD `verify_throttle` DATETIME NOT NULL AFTER `verify_key`"); |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | } |