You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

remove-ansi-sql-mode.php 1.1KB

  1. <?php
  2. /*
  3. Plugin Name: Remove ANSI SQL_MODE
  4. Version: 1.0
  5. Description: Removes the 'ANSI' SQL MODE if it exists as it contains 'ONLY_FULL_GROUP_BY' since MySQL 5.7.5. See https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_ansi
  6. Author: Richard Cagle
  7. Author URI: https://richardleecagle.com
  8. */
  9. class Remove_Ansi_Sql_Mode {
  10. static function init(){
  11. add_action('init', array( __CLASS__, 'strip_ansi_mode' ) );
  12. }
  13. static function strip_ansi_mode(){
  14. global $wpdb;
  15. // Copied from /wp-includes/wp-db.php
  16. $incompatible_modes = array(
  17. 'NO_ZERO_DATE',
  18. 'ONLY_FULL_GROUP_BY',
  19. 'STRICT_TRANS_TABLES',
  20. 'STRICT_ALL_TABLES',
  21. 'TRADITIONAL',
  22. 'ANSI' // Adding ANSI
  23. );
  24. $sql_modes = explode(',', $wpdb->get_col( "SELECT @@SESSION.sql_mode" )[0]);
  25. foreach ($sql_modes as $key => $value) {
  26. if(in_array($value, $incompatible_modes)){
  27. unset($sql_modes[$key]);
  28. }
  29. }
  30. $wpdb->set_sql_mode($sql_modes);
  31. }
  32. }
  33. Remove_Ansi_Sql_Mode::init();