Changeset 2406067
- Timestamp:
- 10/25/2020 04:08:30 AM (5 years ago)
- Location:
- in-stock-mailer-for-woocommerce/trunk
- Files:
-
- 5 edited
-
in-stock-mailer-for-wc.php (modified) (2 diffs)
-
includes/api-manager.php (modified) (3 diffs)
-
includes/in-stock-manager.php (modified) (4 diffs)
-
includes/update-manager.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
in-stock-mailer-for-woocommerce/trunk/in-stock-mailer-for-wc.php
r2405747 r2406067 8 8 * Text Domain: in-stock-mailer-for-wc 9 9 * Domain Path: /languages/ 10 * Version: 2. 0.210 * Version: 2.1.0 11 11 * WC requires at least: 3.5 12 12 * WC tested up to: 4.6.1 … … 24 24 } 25 25 26 define( 'ISM_VERSION', '2. 0.2' );26 define( 'ISM_VERSION', '2.1.0' ); 27 27 define( 'ISM_DOMAIN', 'in-stock-mailer-for-wc' ); 28 28 define( 'ISM_FILE_PATH', __FILE__ ); -
in-stock-mailer-for-woocommerce/trunk/includes/api-manager.php
r2405747 r2406067 233 233 234 234 public function validate_email($email) { 235 $getEmail = s anitize_email( $this->get_user_email($email) );235 $getEmail = strtolower(sanitize_email( $this->get_user_email($email)) ); 236 236 if ( $getEmail && 237 237 is_email( $getEmail ) && … … 248 248 // Checks if email is valid and honeypot field was sent and it is empty 249 249 if ( $email && ( isset( $request['hname'] ) && empty( $request['hname'] ) ) ) { 250 $request['email'] = strtolower( $email );250 $request['email'] = $email; 251 251 return true; 252 252 } … … 379 379 380 380 public function add_alert_request( WP_REST_Request $data) { 381 global $wpdb, $table_prefix; 381 382 382 $product_id = intval($data['product_id']); 383 383 $email = $data['email']; 384 384 $consent = rest_sanitize_boolean($data['mchimp_consent']) ? 1 : 0; 385 385 386 $tblname = self::table_name; 387 $wp_table = $table_prefix . $tblname; 388 389 $sql = "INSERT INTO $wp_table ( product_id, email, consent, sent_id ) VALUES ( %d, %s, %d, null ) ON DUPLICATE KEY UPDATE product_id = %d"; 390 $sql = $wpdb->prepare( $sql, $product_id, $email, $consent, $product_id ); 391 $wpdb->query($sql); 392 393 return array('action'=> 'add' ); 386 if ( !self::has_user_request ($email, $product_id)) { 387 self::add_user_request($email, $product_id, $consent); 388 } 389 390 return array( 'action'=> 'add' ); 394 391 } 395 392 -
in-stock-mailer-for-woocommerce/trunk/includes/in-stock-manager.php
r2405747 r2406067 209 209 } 210 210 211 public static function has_user_request($email, $product_id) { 212 213 global $wpdb, $table_prefix; 214 $tblname = self::table_name; 215 $wp_table = $table_prefix . $tblname; 216 217 $sql = "SELECT id FROM $wp_table WHERE email = %s AND product_id = %d AND sent_id IS NULL"; 218 $sql = $wpdb->prepare( $sql, [ $email, $product_id ] ); 219 return $wpdb->get_var($sql) ? true : false; 220 221 } 222 211 223 public static function remove_user_request($id) { 212 224 global $wpdb, $table_prefix; … … 222 234 $prepare_ph = rtrim($prepare_ph, ','); 223 235 224 $sql = $wpdb->prepare(" DELETE FROM $wp_table WHERE email = %s AND product_id IN ( $prepare_ph) ", $prepare_val );236 $sql = $wpdb->prepare(" DELETE FROM $wp_table WHERE email = %s AND product_id IN ( ". $prepare_ph ." ) ", $prepare_val ); 225 237 return $wpdb->query($sql); 238 } 239 240 public static function add_user_request($email, $product_id, $consent) { 241 242 global $wpdb, $table_prefix; 243 $tblname = self::table_name; 244 $wp_table = $table_prefix . $tblname; 245 246 $sql = "INSERT INTO $wp_table ( product_id, email, consent, sent_id ) VALUES ( %d, %s, %d, null ) ON DUPLICATE KEY UPDATE product_id = %d"; 247 $sql = $wpdb->prepare( $sql, $product_id, $email, $consent, $product_id ); 248 return $wpdb->query($sql); 249 226 250 } 227 251 … … 231 255 $wp_table = $table_prefix . $tblname; 232 256 233 $placeholders = '';257 $placeholders = ''; 234 258 $values = $request_ids; 235 259 foreach ( $request_ids as $value ) { … … 238 262 $placeholders = rtrim($placeholders, ','); 239 263 array_unshift( $values, $email_id ); 240 $sql = $wpdb->prepare(" UPDATE $wp_table SET sent_id = %d WHERE id IN ( $placeholders) ", $values );264 $sql = $wpdb->prepare(" UPDATE $wp_table SET sent_id = %d WHERE id IN ( ". $placeholders ." ) ", $values ); 241 265 return $wpdb->query($sql); 242 266 } -
in-stock-mailer-for-woocommerce/trunk/includes/update-manager.php
r2405747 r2406067 70 70 } 71 71 72 // Future versions check template 73 // if ( $version < '2.0.2' ) { 72 // Removes duplicates from table, fixed in 2.1.0 73 if ( $version < '2.1.0' ) { 74 75 $tblname = self::table_name; 76 $wp_table = $table_prefix . $tblname; 77 78 $sql = "SELECT email, product_id, COUNT(*) AS c FROM {$wp_table} WHERE sent_id IS NULL GROUP BY email, product_id HAVING c > 1"; 79 $wpdb->suppress_errors( true ); 80 $duplicates = $wpdb->get_results( $sql ); 81 82 if ( $duplicates ) { 83 // Prevents system crash lock on failure 84 update_option( 'ism_version', '2.1.0' ); 85 86 foreach ( $duplicates as $duplicate ) { 87 $sql = "DELETE FROM {$wp_table} WHERE email = %s AND product_id = %d LIMIT 1"; 88 $sql = $wpdb->prepare( $sql, [$duplicate->email, intval($duplicate->product_id)] ); 89 $wpdb->query( $sql ); 90 } 91 } 92 93 $wpdb->suppress_errors( false ); 94 } 95 96 // // Updates from this version 97 // if ( $version < '2.1.0' ) { 74 98 // 75 99 // } 76 100 101 77 102 update_option( 'ism_version', ISM_VERSION ); 78 79 103 } 80 104 -
in-stock-mailer-for-woocommerce/trunk/readme.txt
r2405747 r2406067 5 5 Requires at least: 4.9 6 6 Tested up to: 5.5.1 7 Stable tag: 2. 0.27 Stable tag: 2.1.0 8 8 Requires PHP: 5.6.4 9 9 License: GPLv2 or later … … 72 72 73 73 == Changelog == 74 75 = 2.1.0 = 76 * Fixes a database bug. 77 * This update will fix a known issue for those pending emails that are not being sent automatically or manually. 74 78 75 79 = 2.0.2 =
Note: See TracChangeset
for help on using the changeset viewer.