| @@ -162,18 +162,41 @@ | ||
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | 164 | * Delete given countdown and IP entry. |
| 165 | 165 | * |
| 166 | - * @param $countdown_id | |
| 166 | + * @param $campaignId | |
| 167 | + * @param null|string $ipAddress | |
| 167 | 168 | * |
| 168 | 169 | * @return void |
| 169 | 170 | */ |
| 170 | - public function forget($countdown_id) | |
| 171 | + public function forget($campaignId, $ipAddress = null) | |
| 171 | 172 | { |
| 172 | 173 | global $wpdb; |
| 174 | + $where = [ | |
| 175 | + 'countdown_id' => $campaignId, | |
| 176 | + ]; | |
| 177 | + if ($ipAddress !== null) { | |
| 178 | + $where['client_ip_address'] = $ipAddress; | |
| 179 | + } | |
| 180 | + $wpdb->delete($this->table, $where); | |
| 181 | + if ($ipAddress === null) { | |
| 182 | + if ( ! $this->has_entries()) { | |
| 183 | + $this->clear_scheduled_destroy(); | |
| 184 | + } | |
| 185 | + } | |
| 173 | 186 | |
| 174 | - $delete = $wpdb->delete($this->table, compact('countdown_id')); | |
| 187 | + } | |
| 175 | 188 | |
| 189 | + function forgetAll($ipAddress = null) | |
| 190 | + { | |
| 191 | + global $wpdb; | |
| 192 | + if ($ipAddress !== null) { | |
| 193 | + $where['client_ip_address'] = $ipAddress; | |
| 194 | + $wpdb->delete($this->table, $where); | |
| 195 | + } | |
| 196 | + else{ | |
| 197 | + $wpdb->query("delete from {$this->table}"); | |
| 198 | + } | |
| 176 | 199 | if ( ! $this->has_entries()) { |
| 177 | 200 | $this->clear_scheduled_destroy(); |
| 178 | 201 | } |
| 179 | 202 | } |