Last active
June 7, 2023 08:35
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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