<type>

Filter the value before it is saved.

Description

apply_filters( '<type>', (null) $null, (mixed) $sanitizer_value, (int) $this_object_id, (array) $this_args, (object) $sanitizer ); 

The dynamic portion(s) of the hook name refer to the field type.

Passing a non-null value to the filter will short-circuit saving the field value, saving the passed value instead.

Parameters (5)

0. $null (null) => null
Sanitization/Validation override value to return. Default false to skip it.
1. $sanitizer_value (mixed)
The value to be saved to this field.
2. $this_object_id (int)
The ID of the object where the value will be saved
3. $this_args (array)
The current field's arguments
4. $sanitizer (object)
This CMB2_Sanitize object

Usage

To run the hook, copy the example below.
  1. $null = apply_filters( '{$type}', $null, $sanitizer_value, $this_object_id, $this_args, $sanitizer ); 
  2.  
  3. if ( !empty( $null ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the <type> callback 
  2. function filter_type( $null, $sanitizer_value, $this_object_id, $this_args, $sanitizer ) { 
  3. // make filter magic happen here... 
  4. return $null
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( "{$type}", 'filter_type', 10, 5 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( "{$type}", 'filter_type', 10, 5 ); 

Defined (3)

The filter is defined in the following location(s).

/includes/CMB2_Field.php  
  1. $override_value = apply_filters( "cmb2_sanitize_{$this->type()}", null, $sanitizer->value, $this->object_id, $this->args(), $sanitizer ); 
  1. $esc = apply_filters( "cmb2_types_esc_{$this->type()}", null, $meta_value, $this->args(), $this ); 
  1. $pre_output = apply_filters( "cmb2_pre_field_display_{$this->type()}", null, $this, $display );