Recently, we had a user request that their backslashes be preserved when saving their CMB2 fields. Typically, when a user wants non-standard sanitization, our canned response is to use the provided field parameter sanitization override, 'sanitization_cb'. If you’re not aware of this field parameter (and it’s cousin, 'escape_cb'), let me explain a bit. By default, CMB2 does quite a bit of heavy-lifting for you when it comes to sanitizing your users’ input, as well as escaping that value for proper display. This is just one of the aspects of CMB2 that I appreciate; that I don’t have to “think” about the sanitization/escaping of my fields. “It just works.” Except, of course, when it doesn’t. There is no way CMB2 can adapt to every scenario developers may use it for, and until AI has fully commandeered our society, I don’t foresee that happening. In the meantime, we built a way to handle those edge-case scenarios on your own. Yep, that handy override has existed in CMB2 for over four (!) years, but it is a bit obscure, because, fortunately, you’ll almost never need it. Back to the issue at hand. As I mentioned, this particular
Share This