Skip to content

Instantly share code, notes, and snippets.

@Digiover
Last active June 7, 2023 08:35
Show Gist options
  • Save Digiover/b4586b4b470933c534eb4d5d2c90d628 to your computer and use it in GitHub Desktop.
Save Digiover/b4586b4b470933c534eb4d5d2c90d628 to your computer and use it in GitHub Desktop.
Executes an OPTIMIZE TABLE statement on all WordPress MySQL database tables, for instance from within a plugin: https://www.saotn.org/optimize-wordpress-mysql-tables-cron/
/**
* Executes an OPTIMIZE TABLE statement on all WordPress database
* tables.
*/
public static function saotn_wpdb_optimizer() {
global $wpdb;
$tables = $wpdb->get_col( "SHOW TABLES" );
foreach ( $tables as $table ) {
$wpdb->query( "OPTIMIZE TABLE $table" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment