wpdb = $wpdb; $this->table_list = $table_list; } /** * @return bool */ public function is_valid() { if ( ! $this->wpdb->has_cap( 'utf8mb4' ) ) { return false; } $chunks = array(); foreach ( $this->table_list->get_tables() as $table ) { $chunks[] = $this->get_unique_collation_list_from_table( $table ); } $collations = call_user_func_array( 'array_merge', $chunks ); $collations = array_unique( $collations ); return count( $collations ) < 2; } /** * @param string $table * * @return array */ private function get_unique_collation_list_from_table( $table ) { $columns = $this->wpdb->get_results( "SHOW FULL COLUMNS FROM `{$table}` WHERE Collation LIKE 'utf8mb4%'" ); return array_unique( wp_list_pluck( $columns, 'Collation' ) ); } }