From e1f274af387f4ff1263d514a75f8e0873eb8428b Mon Sep 17 00:00:00 2001 From: Julien Liabeuf Date: Tue, 11 Oct 2016 19:55:05 +0700 Subject: [PATCH] Add method to increment the app password count - see #30 --- includes/class-recovery-key.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/includes/class-recovery-key.php b/includes/class-recovery-key.php index 59bc940..7b8149c 100644 --- a/includes/class-recovery-key.php +++ b/includes/class-recovery-key.php @@ -282,6 +282,33 @@ public function delete_key( $id ) { } + /** + * Increment the use count for a key + * + * @since 1.2 + * + * @param int $key_id ID of the key to increment + * + * @return false|int New count + */ + public function increment_count( $key_id ) { + + global $wpdb; + + $key = $this->get_key_by( 'ID', $key_id ); + + if ( empty( $key ) ) { + return false; + } + + $count = (int) $key[0]['count']; + $count++; + $update = $wpdb->update( wpga_recovery_keys_table, array( 'count' => $count ), array( 'ID' => $key_id ), array( '%s' ), array( '%s' ) ); + + return false === $update ? false : $count; + + } + /** * Run a query on the recovery keys table *