I finally figured this out. The Custom Meta Boxes and Fields plugin has a sanitize setting where you can add your own sanitize function or use one of the default wordpress sanitize functions. In my case, WordPress already has a sanitize function that does exactly what I wanted. See the code below, specifically the line
“‘sanitization_cb’ => ‘sanitize_html_class’,”
array(
'name' => __( 'Custom Body Class', 'cmb' ),
'id' => $prefix . 'wnd_bodyclass',
'type' => 'text_medium',
'sanitization_cb' => 'sanitize_html_class', // custom sanitization callback. see this page for details: https://codex.wordpress.org/Function_Reference/sanitize_text_field
),
array(
'name' => __( 'Custom Post Class', 'cmb' ),
'id' => $prefix . 'wnd_postclass',
'type' => 'text_medium',
),
Related Posts:
- Individual Widgets per Page
- Apply the_content filter to a custom field with multiple values
- Meta Query with AND & OR?
- Problem with serialized arrays in custom meta
- Adding another state (spam, reject, approve) to wordpress comments?
- WP doesn’t show Array Custom Fields?
- Filter archive.php by custom meta
- How do I search an array stored in a custom-field using WP_Query?
- Get updated meta data after save_post hook
- Custom text-only header
- How to save custom fields for attachments
- How to get a meta value from all post
- Adding existing user custom field value to a woocommerce product [closed]
- How to save values of a custom input field on the Network > Site Info screen
- How to reload the role specific registration form on validation errors?
- Exclude custom post type from search by custom field value?
- Currency (price) formating on custom fields
- Adding Custom Text Area to WooCommerce Product
- Get multiple custom field values in a $wpdb query [duplicate]
- add meta box using function.php
- Order by value in serialized custom field
- Custom image sizes for custom field media uploads
- converting custom field date format
- How do I exclude posts by custom field value?
- Buddypress Add unserialized Profile Fields in Members Loop [closed]
- Add Paypal Button programmatically
- How do I use wp_query for WordPress search?
- Nav Menu – Add class based on meta keys
- Eliminating the appearance of a specific custom field in a post
- Conditionally hide or show woocommerce product variation in fontend by custom field
- query usermeta from custom field
- Creating author profiles with extra fields and exporting that data?
- Modifying custom order item meta from admin order view
- Let users track progress by entering a number daily in profile?
- WooCommerce – Adding Custom Fields To Invoice
- Changing themes… and need to move Custom Field content into another field
- Filter Posts on Custom Fields and Show them on a new Page
- Removing link ” from ” on meta_value in custom feilds
- How to add a custom field in the advanced menu properties?
- $form_fields from attachment_fields_to_edit returning empty array
- How to link keywords in custom fields?
- Meta query with multiple custom fields for archives page ordering problem
- filter custom field values $min $max
- Custom Fields – How to create a list from multi-line entries of a single value
- Adding custom field to post object from custom table
- Auto embeding Vimeo/Youtube in custom fields (tinyMCE editor)
- How do I use “if field exists” with $curauth?
- Using abs() with custom field in orderby statement
- Can’t save custom field on registration page
- custom field (video/audio url) and embed functionality
- Read more to open external link
- Custom metabox not displaying multiselect data in edit mode
- How to validate select field in post meta?
- check for duplicate user meta data before updating
- WP Cli – post add meta in xargs after wp post generate – add multiple fields
- Anyone know how to use ACF and show custom fields for logged in users only on a post? [closed]
- How to redirect to home page according to a specific page custom fields value and user name
- How to use pre_get_posts to alter posts_per_page of category pages, where ‘posts_per_page’ will be dynamic
- Displaying pages with a specific custom meta
- How to print the Custom fields values [closed]
- How to validation for sanitize_URL?
- How can I output the custom fields wrapping with HTML
- Custom metabox not working
- How to get custom image field of specific post id
- Populate wordpress menu with link to custom field value (file download)
- Selectively hiding or allowing thumbnails of featured images on front page
- wp_get_attachment_image_src() with advanced custom fields returning empty
- How to update custom field of a posts in a particular category
- Woocommerce products search with custom fields
- Convert author metadata to a custom field
- Custom pages or Custom Posts
- get_avatar filter is not working as per requirement
- Is it possible to add Term Meta Fields to a WooCommerce Attribute?
- Saving Custom Field that includes Quotation marks
- WordPress Admin – Automatically Sort Custom Posts by Custom Field Date Value in d-m-Y Fomat
- how to execute custom field for structured data?
- Saving custom form data
- select user with all meta field and field value. I am use Below Query for this ,So any of know another way to fast query instead of below query?
- Retrieve Google API JSON data and store as WordPress Custom Fields
- register_form, custom field not submitted on first try
- meta_query ‘compare’ => ‘!=’ not working
- Echo out custom fields in comments
- Why WordPress takes time to make request to save post?
- Show comon custom field results?
- Make custom user_meta as permalink for post
- Creating Structured Documents (books) in WordPress?
- Filter query based on date in custom field
- Display Child Page with custom fields within Parent Page
- Convert all dates in field to Unix time, except those already in Unix time
- Custom fields: my custom checkbox area doesn’t seem to work
- get_post_custom_values not working
- Pagination not displaying correct number of pages
- Show div based on custom meta value
- add multiple values (array) to post meta_input
- Assign class to Drop Down Selections in WooCommerce Products Custom Fields
- Show/Hide Featured Image or replace it with custom field [closed]
- Add CSS class to posts with certain meta key
- Match submitted array fields with the MYSQL database fields to update them correctly in PHP
- Best way for managing images of ads banners
- Crop custom image size vs actual size