| @@ -475,13 +475,20 @@ | ||
| 475 | 475 | $this->app_db->flush(); |
| 476 | 476 | return $response; |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - // get last entry id | |
| 479 | + /** | |
| 480 | + * Get last inserted id | |
| 481 | + * | |
| 482 | + * @return int | |
| 483 | + */ | |
| 480 | 484 | public function lastId() |
| 481 | 485 | { |
| 482 | 486 | $sql = "SELECT id FROM {$this->table_name} |
| 483 | 487 | ORDER BY id DESC LIMIT 1"; |
| 484 | - $result = $this->execute($sql)->getResult()[0]; | |
| 485 | - return $result->id; | |
| 488 | + $result = $this->execute($sql)->getResult(); | |
| 489 | + if (is_wp_error($result)) { | |
| 490 | + return 0; | |
| 491 | + } | |
| 492 | + return $result[0]->id; | |
| 486 | 493 | } |
| 487 | 494 | } |