@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 1.4 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -defined( 'ABSPATH' ) or exit; |
|
| 13 | +defined('ABSPATH') or exit; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Class Give_Email_Access |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | function __construct() { |
| 31 | 31 | |
| 32 | 32 | // get it started |
| 33 | - add_action( 'init', array( $this, 'init' ) ); |
|
| 33 | + add_action('init', array($this, 'init')); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
@@ -39,30 +39,30 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | function init() { |
| 41 | 41 | |
| 42 | - $is_enabled = give_get_option( 'email_access' ); |
|
| 42 | + $is_enabled = give_get_option('email_access'); |
|
| 43 | 43 | |
| 44 | 44 | //Non-logged in users only |
| 45 | - if ( is_user_logged_in() || $is_enabled !== 'on' || is_admin() ) { |
|
| 45 | + if (is_user_logged_in() || $is_enabled !== 'on' || is_admin()) { |
|
| 46 | 46 | return; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | //Are db columns setup? |
| 50 | - $is_setup = give_get_option( 'email_access_installed' ); |
|
| 51 | - if ( empty( $is_setup ) ) { |
|
| 50 | + $is_setup = give_get_option('email_access_installed'); |
|
| 51 | + if (empty($is_setup)) { |
|
| 52 | 52 | $this->create_columns(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Timeouts |
| 56 | - $this->verify_throttle = apply_filters( 'give_nl_verify_throttle', 300 ); |
|
| 57 | - $this->token_expiration = apply_filters( 'give_nl_token_expiration', 7200 ); |
|
| 56 | + $this->verify_throttle = apply_filters('give_nl_verify_throttle', 300); |
|
| 57 | + $this->token_expiration = apply_filters('give_nl_token_expiration', 7200); |
|
| 58 | 58 | |
| 59 | 59 | // Setup login |
| 60 | 60 | $this->check_for_token(); |
| 61 | 61 | |
| 62 | - if ( $this->token_exists ) { |
|
| 63 | - add_filter( 'give_can_view_receipt', '__return_true' ); |
|
| 64 | - add_filter( 'give_user_pending_verification', '__return_false' ); |
|
| 65 | - add_filter( 'give_get_users_purchases_args', array( $this, 'users_purchases_args' ) ); |
|
| 62 | + if ($this->token_exists) { |
|
| 63 | + add_filter('give_can_view_receipt', '__return_true'); |
|
| 64 | + add_filter('give_user_pending_verification', '__return_false'); |
|
| 65 | + add_filter('give_get_users_purchases_args', array($this, 'users_purchases_args')); |
|
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
@@ -73,24 +73,24 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return bool |
| 75 | 75 | */ |
| 76 | - function can_send_email( $customer_id ) { |
|
| 76 | + function can_send_email($customer_id) { |
|
| 77 | 77 | global $wpdb; |
| 78 | 78 | |
| 79 | 79 | // Prevent multiple emails within X minutes |
| 80 | - $throttle = date( 'Y-m-d H:i:s', time() - $this->verify_throttle ); |
|
| 80 | + $throttle = date('Y-m-d H:i:s', time() - $this->verify_throttle); |
|
| 81 | 81 | |
| 82 | 82 | // Does a user row exist? |
| 83 | 83 | $exists = (int) $wpdb->get_var( |
| 84 | - $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}give_customers WHERE id = %d", $customer_id ) |
|
| 84 | + $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}give_customers WHERE id = %d", $customer_id) |
|
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | - if ( 0 < $exists ) { |
|
| 87 | + if (0 < $exists) { |
|
| 88 | 88 | $row_id = (int) $wpdb->get_var( |
| 89 | - $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}give_customers WHERE id = %d AND (verify_throttle < %s OR verify_key = '') LIMIT 1", $customer_id, $throttle ) |
|
| 89 | + $wpdb->prepare("SELECT id FROM {$wpdb->prefix}give_customers WHERE id = %d AND (verify_throttle < %s OR verify_key = '') LIMIT 1", $customer_id, $throttle) |
|
| 90 | 90 | ); |
| 91 | 91 | |
| 92 | - if ( $row_id < 1 ) { |
|
| 93 | - give_set_error( 'give_email_access_attempts_exhausted', __( 'Please wait a few minutes before requesting a new email access link.', 'give' ) ); |
|
| 92 | + if ($row_id < 1) { |
|
| 93 | + give_set_error('give_email_access_attempts_exhausted', __('Please wait a few minutes before requesting a new email access link.', 'give')); |
|
| 94 | 94 | |
| 95 | 95 | return false; |
| 96 | 96 | } |
@@ -106,38 +106,38 @@ discard block |
||
| 106 | 106 | * @param $customer_id |
| 107 | 107 | * @param $email |
| 108 | 108 | */ |
| 109 | - function send_email( $customer_id, $email ) { |
|
| 109 | + function send_email($customer_id, $email) { |
|
| 110 | 110 | |
| 111 | - $verify_key = wp_generate_password( 20, false ); |
|
| 111 | + $verify_key = wp_generate_password(20, false); |
|
| 112 | 112 | |
| 113 | 113 | // Generate a new verify key |
| 114 | - $this->set_verify_key( $customer_id, $email, $verify_key ); |
|
| 114 | + $this->set_verify_key($customer_id, $email, $verify_key); |
|
| 115 | 115 | |
| 116 | 116 | // Get the purchase history URL |
| 117 | - $page_id = give_get_option( 'history_page' ); |
|
| 117 | + $page_id = give_get_option('history_page'); |
|
| 118 | 118 | |
| 119 | - $access_url = add_query_arg( array( |
|
| 119 | + $access_url = add_query_arg(array( |
|
| 120 | 120 | 'give_nl' => $verify_key, |
| 121 | - ), get_permalink( $page_id ) ); |
|
| 121 | + ), get_permalink($page_id)); |
|
| 122 | 122 | |
| 123 | 123 | //Nice subject and message |
| 124 | - $subject = apply_filters( 'give_email_access_token_subject', sprintf( __( 'Your Access Link to %1$s', 'give' ), get_bloginfo( 'name' ) ) ); |
|
| 124 | + $subject = apply_filters('give_email_access_token_subject', sprintf(__('Your Access Link to %1$s', 'give'), get_bloginfo('name'))); |
|
| 125 | 125 | |
| 126 | - $message = __( 'You or someone in your organization requested an access link be sent to this email address. This is a temporary access link for you to view your donation information. Click on the link below to view:', 'give' ) . "\n\n"; |
|
| 126 | + $message = __('You or someone in your organization requested an access link be sent to this email address. This is a temporary access link for you to view your donation information. Click on the link below to view:', 'give')."\n\n"; |
|
| 127 | 127 | |
| 128 | - $message .= '<a href="' . esc_url( $access_url ) . '" target="_blank">' . __( 'Access My Donation Details', 'give' ) . ' »</a>'; |
|
| 128 | + $message .= '<a href="'.esc_url($access_url).'" target="_blank">'.__('Access My Donation Details', 'give').' »</a>'; |
|
| 129 | 129 | |
| 130 | 130 | $message .= "\n\n"; |
| 131 | 131 | $message .= "\n\n"; |
| 132 | - $message .= __( 'Sincerely,', 'give' ); |
|
| 133 | - $message .= "\n" . get_bloginfo( 'name' ) . "\n"; |
|
| 132 | + $message .= __('Sincerely,', 'give'); |
|
| 133 | + $message .= "\n".get_bloginfo('name')."\n"; |
|
| 134 | 134 | |
| 135 | - $message = apply_filters( 'give_email_access_token_message', $message ); |
|
| 135 | + $message = apply_filters('give_email_access_token_message', $message); |
|
| 136 | 136 | |
| 137 | 137 | |
| 138 | 138 | // Send the email |
| 139 | - Give()->emails->__set( 'heading', apply_filters( 'give_email_access_token_heading', __( 'Your Access Link', 'give' ) ) ); |
|
| 140 | - Give()->emails->send( $email, $subject, $message ); |
|
| 139 | + Give()->emails->__set('heading', apply_filters('give_email_access_token_heading', __('Your Access Link', 'give'))); |
|
| 140 | + Give()->emails->send($email, $subject, $message); |
|
| 141 | 141 | |
| 142 | 142 | } |
| 143 | 143 | |
@@ -147,24 +147,24 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | function check_for_token() { |
| 149 | 149 | |
| 150 | - $token = isset( $_GET['give_nl'] ) ? $_GET['give_nl'] : ''; |
|
| 150 | + $token = isset($_GET['give_nl']) ? $_GET['give_nl'] : ''; |
|
| 151 | 151 | |
| 152 | 152 | // Check for cookie |
| 153 | - if ( empty( $token ) ) { |
|
| 154 | - $token = isset( $_COOKIE['give_nl'] ) ? $_COOKIE['give_nl'] : ''; |
|
| 153 | + if (empty($token)) { |
|
| 154 | + $token = isset($_COOKIE['give_nl']) ? $_COOKIE['give_nl'] : ''; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if ( ! empty( $token ) ) { |
|
| 158 | - if ( ! $this->is_valid_token( $token ) ) { |
|
| 159 | - if ( ! $this->is_valid_verify_key( $token ) ) { |
|
| 157 | + if ( ! empty($token)) { |
|
| 158 | + if ( ! $this->is_valid_token($token)) { |
|
| 159 | + if ( ! $this->is_valid_verify_key($token)) { |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | $this->token_exists = true; |
| 165 | 165 | // Set cookie |
| 166 | - $lifetime = current_time( 'timestamp' ) + Give()->session->set_expiration_time(); |
|
| 167 | - @setcookie( 'give_nl', $token, $lifetime, COOKIEPATH, COOKIE_DOMAIN, false ); |
|
| 166 | + $lifetime = current_time('timestamp') + Give()->session->set_expiration_time(); |
|
| 167 | + @setcookie('give_nl', $token, $lifetime, COOKIEPATH, COOKIE_DOMAIN, false); |
|
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
@@ -175,18 +175,18 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return bool |
| 177 | 177 | */ |
| 178 | - function is_valid_token( $token ) { |
|
| 178 | + function is_valid_token($token) { |
|
| 179 | 179 | |
| 180 | 180 | global $wpdb; |
| 181 | 181 | |
| 182 | 182 | // Make sure token isn't expired |
| 183 | - $expires = date( 'Y-m-d H:i:s', time() - $this->token_expiration ); |
|
| 183 | + $expires = date('Y-m-d H:i:s', time() - $this->token_expiration); |
|
| 184 | 184 | |
| 185 | 185 | $email = $wpdb->get_var( |
| 186 | - $wpdb->prepare( "SELECT email FROM {$wpdb->prefix}give_customers WHERE token = %s AND verify_throttle >= %s LIMIT 1", $token, $expires ) |
|
| 186 | + $wpdb->prepare("SELECT email FROM {$wpdb->prefix}give_customers WHERE token = %s AND verify_throttle >= %s LIMIT 1", $token, $expires) |
|
| 187 | 187 | ); |
| 188 | 188 | |
| 189 | - if ( ! empty( $email ) ) { |
|
| 189 | + if ( ! empty($email)) { |
|
| 190 | 190 | $this->token_email = $email; |
| 191 | 191 | $this->token = $token; |
| 192 | 192 | |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | //Set error only if email access form isn't being submitted |
| 197 | - if ( ! isset( $_POST['give_email'] ) && ! isset( $_POST['_wpnonce'] ) ) { |
|
| 198 | - give_set_error( 'give_email_token_expired', apply_filters( 'give_email_token_expired_message', 'Sorry, your access token has expired. Please request a new one below:', 'give' ) ); |
|
| 197 | + if ( ! isset($_POST['give_email']) && ! isset($_POST['_wpnonce'])) { |
|
| 198 | + give_set_error('give_email_token_expired', apply_filters('give_email_token_expired_message', 'Sorry, your access token has expired. Please request a new one below:', 'give')); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | |
@@ -210,25 +210,25 @@ discard block |
||
| 210 | 210 | * @param $email |
| 211 | 211 | * @param $verify_key |
| 212 | 212 | */ |
| 213 | - function set_verify_key( $customer_id, $email, $verify_key ) { |
|
| 213 | + function set_verify_key($customer_id, $email, $verify_key) { |
|
| 214 | 214 | global $wpdb; |
| 215 | 215 | |
| 216 | - $now = date( 'Y-m-d H:i:s' ); |
|
| 216 | + $now = date('Y-m-d H:i:s'); |
|
| 217 | 217 | |
| 218 | 218 | // Insert or update? |
| 219 | 219 | $row_id = (int) $wpdb->get_var( |
| 220 | - $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}give_customers WHERE id = %d LIMIT 1", $customer_id ) |
|
| 220 | + $wpdb->prepare("SELECT id FROM {$wpdb->prefix}give_customers WHERE id = %d LIMIT 1", $customer_id) |
|
| 221 | 221 | ); |
| 222 | 222 | |
| 223 | 223 | // Update |
| 224 | - if ( ! empty( $row_id ) ) { |
|
| 224 | + if ( ! empty($row_id)) { |
|
| 225 | 225 | $wpdb->query( |
| 226 | - $wpdb->prepare( "UPDATE {$wpdb->prefix}give_customers SET verify_key = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $verify_key, $now, $row_id ) |
|
| 226 | + $wpdb->prepare("UPDATE {$wpdb->prefix}give_customers SET verify_key = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $verify_key, $now, $row_id) |
|
| 227 | 227 | ); |
| 228 | 228 | } // Insert |
| 229 | 229 | else { |
| 230 | 230 | $wpdb->query( |
| 231 | - $wpdb->prepare( "INSERT INTO {$wpdb->prefix}give_customers ( verify_key, verify_throttle) VALUES (%s, %s)", $verify_key, $now ) |
|
| 231 | + $wpdb->prepare("INSERT INTO {$wpdb->prefix}give_customers ( verify_key, verify_throttle) VALUES (%s, %s)", $verify_key, $now) |
|
| 232 | 232 | ); |
| 233 | 233 | } |
| 234 | 234 | } |
@@ -240,20 +240,20 @@ discard block |
||
| 240 | 240 | * |
| 241 | 241 | * @return bool |
| 242 | 242 | */ |
| 243 | - function is_valid_verify_key( $token ) { |
|
| 243 | + function is_valid_verify_key($token) { |
|
| 244 | 244 | global $wpdb; |
| 245 | 245 | |
| 246 | 246 | // See if the verify_key exists |
| 247 | 247 | $row = $wpdb->get_row( |
| 248 | - $wpdb->prepare( "SELECT id, email FROM {$wpdb->prefix}give_customers WHERE verify_key = %s LIMIT 1", $token ) |
|
| 248 | + $wpdb->prepare("SELECT id, email FROM {$wpdb->prefix}give_customers WHERE verify_key = %s LIMIT 1", $token) |
|
| 249 | 249 | ); |
| 250 | 250 | |
| 251 | - $now = date( 'Y-m-d H:i:s' ); |
|
| 251 | + $now = date('Y-m-d H:i:s'); |
|
| 252 | 252 | |
| 253 | 253 | // Set token |
| 254 | - if ( ! empty( $row ) ) { |
|
| 254 | + if ( ! empty($row)) { |
|
| 255 | 255 | $wpdb->query( |
| 256 | - $wpdb->prepare( "UPDATE {$wpdb->prefix}give_customers SET verify_key = '', token = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $token, $now, $row->id ) |
|
| 256 | + $wpdb->prepare("UPDATE {$wpdb->prefix}give_customers SET verify_key = '', token = %s, verify_throttle = %s WHERE id = %d LIMIT 1", $token, $now, $row->id) |
|
| 257 | 257 | ); |
| 258 | 258 | |
| 259 | 259 | $this->token_email = $row->email; |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @return mixed |
| 274 | 274 | */ |
| 275 | - function users_purchases_args( $args ) { |
|
| 275 | + function users_purchases_args($args) { |
|
| 276 | 276 | $args['user'] = $this->token_email; |
| 277 | 277 | |
| 278 | 278 | return $args; |
@@ -289,11 +289,11 @@ discard block |
||
| 289 | 289 | global $wpdb; |
| 290 | 290 | |
| 291 | 291 | //Create columns in customers table |
| 292 | - $query = $wpdb->query( "ALTER TABLE {$wpdb->prefix}give_customers 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`" ); |
|
| 292 | + $query = $wpdb->query("ALTER TABLE {$wpdb->prefix}give_customers 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`"); |
|
| 293 | 293 | |
| 294 | 294 | //Columns added properly |
| 295 | - if ( $query ) { |
|
| 296 | - give_update_option( 'email_access_installed', 1 ); |
|
| 295 | + if ($query) { |
|
| 296 | + give_update_option('email_access_installed', 1); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | } |