Skip to content

Instantly share code, notes, and snippets.

@florianbrinkmann
Created March 23, 2017 14:17
Show Gist options
  • Save florianbrinkmann/c3f57dd7c26328d7b4de04e696091eee to your computer and use it in GitHub Desktop.
Save florianbrinkmann/c3f57dd7c26328d7b4de04e696091eee to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: UTF8mb4-convert
Version: 1.0
*/
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' );
global $wpdb;
if ( is_multisite() ) {
$tables = $wpdb->tables( 'blog' );
} else {
$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' );
@chrisdavidmiles
Copy link

Is the get parameter a typo on line 8? It's written as bm4 instead of mb4 (multi-byte 4). I suppose it doesn't matter as long as you use the same query string when calling the function on your site, but I think this is a typo.

@florianbrinkmann
Copy link
Author

A little late, but: yes, it is a typo :)

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