• Resolved Clifford Paulick

    (@cliffpaulick)


    Re: 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

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter Clifford Paulick

    (@cliffpaulick)

    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

    (@tw2113)

    The BenchPresser

    Welcome 🙂

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

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