How to Save a Backslash () to CMB2 Meta Fields – Zao.is WordPress Plugin Development


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
Source: https://managewp.org/articles/15006/how-to-save-a-backslash-to-cmb2-meta-fields-zao-is-wordpress-plugin-development


Source: https://williechiu40.wordpress.com/2017/05/03/how-to-save-a-backslash-to-cmb2-meta-fields-zao-is-wordpress-plugin-development/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s