#66185 closed defect (bug) (fixed)
Add NO_BACKSLASH_ESCAPES to wpdb::$incompatible_modes
| Reported by: | tyxla | Owned by: | tyxla |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Database | Version: | trunk |
| Severity: | normal | Keywords: | has-patch has-unit-tests needs-docs |
| Cc: | Focuses: |
Description
When the MySQL/MariaDB NO_BACKSLASH_ESCAPES SQL mode is enabled, the backslash (\) is treated as an ordinary character inside string literals instead of as an escape character.
WordPress assumes backslash escaping in many places, both in core and in the plugin/theme ecosystem. With this mode active, a literal such as 'It\'s' is no longer read as It's. The quote ends the string early, and the query either fails with a syntax error or stores or matches the wrong value.
This is a long-known incompatibility that has come up several times over the years: #2820, #3286, #57149.
wpdb::set_sql_mode() already strips SQL modes that WordPress is known not to support, through wpdb::$incompatible_modes:
protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL', 'ANSI', );
NO_BACKSLASH_ESCAPES is not on that list. If the server or a hosting environment sets it globally, WordPress keeps it for the session, and queries fail.
To fix this, we should add NO_BACKSLASH_ESCAPES to wpdb::$incompatible_modes, so WordPress removes it from the session SQL mode like the other modes it doesn't support. Sites that really need the mode can still re-enable it with the existing incompatible_sql_modes filter.
Change History (7)
This ticket was mentioned in PR #13758 on WordPress/wordpress-develop by @tyxla.
6 weeks ago
#2
- Keywords has-patch has-unit-tests added; needs-patch removed
@therssoftware commented on PR #13758:
6 weeks ago
#3
Tested this locally on PHP 8.3 with MySQL 8.0.
- Before the PR: Calling
$wpdb->set_sql_mode( [ 'NO_BACKSLASH_ESCAPES' ] )leftNO_BACKSLASH_ESCAPESactive in the sessionsql_mode. - With the PR applied: It gets stripped out from the session by
wpdb::set_sql_mode(), matching the other incompatible modes. - Also verified that filtering
incompatible_sql_modesstill allows overriding this if a site explicitly needs it. - All 508 tests in
tests/phpunit/tests/db.phppass cleanly (727 assertions).
Looks good to merge!
Use of AI Tools
AI assistance: Yes (formatting aid; tests run and verified locally by me).
#6
@
5 weeks ago
- Keywords needs-docs needs-dev-note added
Thanks @tyxla! As this is a breaking change, this should get announced on make/core to ensure folks are aware. Also, adding needs docs, but I think this might be in hosting docs rather than something the documentation team maintains.
#7
@
4 weeks ago
- Keywords needs-dev-note removed
Good call, @jorbin, thanks!
Make post published: https://make.wordpress.org/core/2026/10/09/no_backslash_escapes-sql-mode-is-now-turned-off-by-default-in-wordpress-7-2/
Not sure what's the process for the hosting docs though - any recommendations?
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Trac ticket: https://core.trac.wordpress.org/ticket/66185
Adds
NO_BACKSLASH_ESCAPESto the list of SQL modes that WordPress does not support (wpdb::$incompatible_modes).When this mode is on, MySQL treats the backslash (
\) as a normal character, not as an escape character. WordPress expects backslash escaping, so queries with escaped values can fail. This is a known problem (see #2820, #3286, #57149).With this change,
wpdb::set_sql_mode()removesNO_BACKSLASH_ESCAPESfrom the session, like it already does for the other unsupported modes. Sites that need the mode can still allow it with theincompatible_sql_modesfilter.The existing
test_set_incompatible_sql_mode()test now also checks thatNO_BACKSLASH_ESCAPESis removed.