Skip to content

Commit 6f64e74

Browse files
committed
Merge pull request alleyinteractive#417 from firejdl/options-sanitize-not-closure
Make `Fieldmanager_Options::$sanitize` a non-closure function
2 parents ece9394 + 4cfc7ff commit 6f64e74

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

php/class-fieldmanager-options.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,20 @@ public function __construct( $label = '', $options = array() ) {
6565
fm_add_style( 'fm_options_css', 'css/fieldmanager-options.css' );
6666

6767
// Sanitization
68-
$this->sanitize = function( $value ) {
69-
if ( isset( $value ) && is_array( $value ) && !empty( $value ) ) {
70-
return array_map( 'sanitize_text_field', $value );
71-
} else {
72-
return sanitize_text_field( $value );
73-
}
74-
};
68+
$this->sanitize = array( $this, 'sanitize' );
69+
}
70+
71+
/**
72+
* Sanitize function that can handle arrays as well as string values.
73+
* @param array|string $value
74+
* @return array|string Sanitized $value
75+
*/
76+
public function sanitize( $value ) {
77+
if ( isset( $value ) && is_array( $value ) && ! empty( $value ) ) {
78+
return array_map( 'sanitize_text_field', $value );
79+
} else {
80+
return sanitize_text_field( $value );
81+
}
7582
}
7683

7784
/**

0 commit comments

Comments
 (0)