Skip to content

Instantly share code, notes, and snippets.

@carlalexander
Last active March 28, 2024 10:53
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save carlalexander/4106cfaaf405cec454ba195631bcb6bc to your computer and use it in GitHub Desktop.
Save carlalexander/4106cfaaf405cec454ba195631bcb6bc to your computer and use it in GitHub Desktop.
<?php
function update_db_to_utf8mb4() {
if (!isset($_GET['update-utf8bm4'])) {
return;
}
require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
/** WordPress Administration API */
require_once(ABSPATH . 'wp-admin/includes/admin.php');
/** WordPress Schema API */
require_once(ABSPATH . 'wp-admin/includes/schema.php');
$tables = $wpdb->tables('all');
if (!wp_should_upgrade_global_tables()) {
$global_tables = $wpdb->tables('global');
$tables = array_diff_assoc($tables, $global_tables);
}
foreach ($tables as $table) {
maybe_convert_table_to_utf8mb4($table);
}
}
add_action('wp_loaded', 'update_db_to_utf8mb4');
@eloone
Copy link

eloone commented Jun 20, 2017

Is it intended that in !isset($_GET['update-utf8bm4']) it is update-utf8bm4 and not update-utf8mb4?
Anyone using this script should pay attention to that.

@jordan26
Copy link

Would be handy to update this to account for multisite too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment