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 *