Thanks a lot for this Florian! It pointed me towards the right direction.

Somehow after a server upgrade I ended up not being able to save posts that had emojis in the editor... Somehow, my wp tables had a utf8mb3 encoding. So I used your plugin as a starting point and modified the maybe_convert_table_to_utf8mb4( ) to make it work with utf8mb3 encoding. I ended up with smth like this in case anyone has the same issue:

add_action( 'wp_loaded', 'update_db_to_utf8mb4' );
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 ) {
global $wpdb;

$results = $wpdb->get_results( "SHOW FULL COLUMNS FROM `$table`" );
if ( ! $results ) {
break;
}

foreach ( $results as $column ) {
if ( $column->Collation ) {
list( $charset ) = explode( '_', $column->Collation );
$charset = strtolower( $charset );
if ( 'utf8' !== $charset && 'utf8mb3' !== $charset && 'utf8mb4' !== $charset ) {
// Don't upgrade tables that have non-utf8 columns.
break;
}
}
}

$table_details = $wpdb->get_row( "SHOW TABLE STATUS LIKE '$table'" );
if ( ! $table_details ) {
break;
}

$table_charset = strtolower( $table_details->Collation );
if ( 'utf8mb4_unicode_520_ci' === $table_charset ) {
continue;
}

$wpdb->query( "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci" );
}
}

Thanks again

P.S. still using your very nice lazy load plugin 🙂