Title: sanitization_cb in PHP class
Last modified: July 17, 2017

---

# sanitization_cb in PHP class

 *  Resolved [Clifford Paulick](https://wordpress.org/support/users/cliffpaulick/)
 * (@cliffpaulick)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/sanitization_cb-in-php-class/)
 * Re: [https://github.com/CMB2/CMB2/wiki/Field-Parameters#sanitization_c](https://github.com/CMB2/CMB2/wiki/Field-Parameters#sanitization_c)
 *     ```
       $opts->add_field(
       	array(
       		'id'              => $this->field_prefix . 'item_class',
       		'name'            => __( 'Individual CSS Class', 'my-text-domain' ),
       		'type'            => 'text_medium',
       		'sanitization_cb' => array( $this, 'sanitize_css_classes' ),
       	)
       );
       ```
   
 * and then, in the same PHP class:
 *     ```
       protected function sanitize_css_classes( $value, $field_args, $field ) {
       	$classes = explode( ' ', $value );
   
       	$output = '';
       	foreach ( $classes as $_v ) {
       		$output .= ' ' . sanitize_html_class( $_v );
       	}
   
       	return $output;
       }
       ```
   
 * `$this->sanitize_css_classes()` is not getting called.
 * Shouldn’t this `sanitization_cb` work?
 * Thank you for the assistance.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 11 months ago](https://wordpress.org/support/topic/sanitization_cb-in-php-class/#post-9326148)
 * Curious if the `protected` part is playing a role in this issue. Change it to`
   public` and see if it works then. I’m suspecting scoping is playing a part, as
   logically the actual method use is later on.
    -  This reply was modified 8 years, 11 months ago by [Michael Beckwith](https://wordpress.org/support/users/tw2113/).
 *  Thread Starter [Clifford Paulick](https://wordpress.org/support/users/cliffpaulick/)
 * (@cliffpaulick)
 * [8 years, 11 months ago](https://wordpress.org/support/topic/sanitization_cb-in-php-class/#post-9326166)
 * Sure enough!
 * Sometimes you get so deep into something you don’t see the obvious. Yikes!
 * Thanks so much for the quick and excellent help! 🙂
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 11 months ago](https://wordpress.org/support/topic/sanitization_cb-in-php-class/#post-9326299)
 * Welcome 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘sanitization_cb in PHP class’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [8 years, 11 months ago](https://wordpress.org/support/topic/sanitization_cb-in-php-class/#post-9326299)
 * Status: resolved