WordPress 7.2 adds NO_BACKSLASH_ESCAPES to the list of SQL modes that WordPress doesn’t support. WordPress already turns off some modes, such as STRICT_ALL_TABLES, TRADITIONAL and ANSI, when it connects to the database. This mode is now on that list too.
Why this change?
WordPress uses the backslash character (\) to escape special characters in SQL queries. When NO_BACKSLASH_ESCAPES is on, MySQL MySQL is a relational database management system. A database is a structured collection of data where content, configuration and other options are stored. https://www.mysql.com reads the backslash as a normal character, not as an escape character. Queries with escaped values can then fail or return the wrong data.
Some hosts or server setups may turn this mode on. Before this change, sites on those servers could have hard-to-find database problems.
For more details, see Ticket #66185.
What changes?
When WordPress connects to the database, wpdb::set_sql_mode() now removes NO_BACKSLASH_ESCAPES from the session’s SQL modes. This affects only the WordPress database connection. It doesn’t change the server’s global settings.
Most sites won’t notice any difference.
What if I need this mode?
If your site really needs NO_BACKSLASH_ESCAPES, you can keep it with the existing incompatible_sql_modes filter Filters are one of the two types of Hooks https://codex.wordpress.org/Plugin_API/Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike Actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output.:
add_filter( 'incompatible_sql_modes', function ( $modes ) {
return array_diff( $modes, array( 'NO_BACKSLASH_ESCAPES' ) );
} );
WordPress connects to the database before plugins load, so add this code in a db.php drop-in. Code in a normal plugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party. or a must-use plugin runs too late.
Please note that WordPress Core Core is the set of software required to run WordPress. The Core Development Team builds WordPress. may not work correctly with this mode turned on.
Props to @mcsf for reviewing this post.
#7-2, #dev-notes, #dev-notes-7-2, #database