Permalink
Browse files

Change the way the 'cmb_validate_'. $field['type'] filter works.

Is now passed a null value vs saved value. If null is returned, default sanitization will follow. THIS IS A BREAKING CHANGE.
  • Loading branch information...
1 parent fb4d03d commit 90f67ac049f7e14f5f142db50a7ecc07822686d2 @jtsternberg jtsternberg committed Jan 30, 2014
Showing with 22 additions and 24 deletions.
  1. +22 −24 helpers/cmb_Meta_Box_Sanitize.php
View
46 helpers/cmb_Meta_Box_Sanitize.php
@@ -182,35 +182,33 @@ public static function textarea( $meta ) {
public function __call( $name, $arguments ) {
list( $meta_value, $field ) = $arguments;
+ $object_type = cmb_Meta_Box::get_object_type();
+ $object_id = cmb_Meta_Box::get_object_id();
+
+ // Allow field type validation via filter
+ $updated = apply_filters( 'cmb_validate_'. $field['type'], null, $meta_value, $object_id, $field, $object_type );
+
+ if ( null != $updated ) {
+ return $updated;
+ }
+
+ // we'll fallback to 'sanitize_text_field', or 'wp_kses_post`
+ switch ( $field['type'] ) {
+ case 'wysiwyg':
+ case 'textarea_small':
+ $cb = array( 'cmb_Meta_Box_Sanitize', 'textarea' );
+
+ default:
+ $cb = 'sanitize_text_field';
+ }
+
// Handle repeatable fields array
if ( is_array( $meta_value ) ) {
foreach ( $meta_value as $key => $value ) {
- // Allow field type validation via filter
- $updated = apply_filters( 'cmb_validate_'. $field['type'], $value, cmb_Meta_Box::get_object_id(), $field, cmb_Meta_Box::get_object_type() );
-
- if ( $updated === $value ) {
- // If nothing changed, we'll fallback to 'sanitize_text_field'
- $updated = sanitize_text_field( $value );
- }
- $meta_value[ $key ] = $updated;
+ $meta_value[ $key ] = call_user_func( $cb, $value );
}
} else {
-
- switch ( $field['type'] ) {
- case 'wysiwyg':
- case 'textarea_small':
- return self::textarea( $meta_value );
-
- default:
- // Allow field type validation via filter
- $updated = apply_filters( 'cmb_validate_'. $field['type'], $meta_value, cmb_Meta_Box::get_object_id(), $field, cmb_Meta_Box::get_object_type() );
- if ( $updated === $meta_value ) {
- // If nothing changed, we'll fallback to 'sanitize_text_field'
- return sanitize_text_field( $meta_value );
- }
- return $updated;
- }
-
+ $meta_value = call_user_func( $cb, $meta_value );
}
return $meta_value;

0 comments on commit 90f67ac

Please sign in to comment.