Forked from florianbrinkmann/utf8-to-utf8mb4.php
Last active
February 18, 2021 00:38
-
-
Save dgaidula/7d85add50b35c5b47aff5ec2098ac037 to your computer and use it in GitHub Desktop.
Based on the Gist by Carl Alexander (https://gist.github.com/carlalexander/4106cfaaf405cec454ba195631bcb6bc), found via http://wordpress.stackexchange.com/a/244992/112824
This file contains hidden or 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
| <?php | |
| /* | |
| Plugin Name: UTF8mb4-convert | |
| Version: 1.0 | |
| */ | |
| function update_db_to_utf8mb4() { | |
| if ( ! isset( $_GET['update-utf8mb4'] ) ) { | |
| 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment