Hacker News new | ask | show | jobs
by Ayesh 2639 days ago
While I don't disagree that this is horrible, perhaps the $tables array is hardcoded array.
2 comments

  global $wpdb;
  $prefix = str_replace('_', '\_', $wpdb->prefix);
  $tables = $wpdb->get_col("SHOW TABLES LIKE '{$prefix}%'");
  foreach ($tables as $table) {
   $wpdb->query("DROP TABLE $table");
  }
Essentially for those who aren't familiar with WordPress databases - this drops all tables relating to the WordPress install
It is not, you can check the post for the full context.
Or, better still, an Archive.org snapshot of the commit that added this very code: https://web.archive.org/web/20190331195338/bitbucket.org/pip...

(As a resident geek, I was asked to look into this by a friend)

For good measure, the commit seems to be removed from the original repo.
It's pretty much the same as if it was hardcoded, it drops all tables that have a name starting with the WP prefix. It's extremely ugly, but it's not unsafe (if your plan is removing all WP related tables from the DB).