0

How can I find out what section each input is in when viewing the $input array passed to the sanitize_callback function defined in register_setting()?

I suppose one option is to include the section as part of the field name and can then extract it. E.g. name="section^field" and then in the sanitize_callback:

foreach($input as $name => $val) {
    $parts = explode('^', $name);
    $section = $parts[0];
    $field = $parts[1];
    // do more stuff here
}

But this feels a little hacky. Is there a better way?

1 Answer 1

1

Unfortunately if you look at the source the only thing that happens there is:

add_filter( "sanitize_option_{$option_name}", $sanitize_callback );

There is no opportunity to pass along or retrieve any extra information.

On a larger scale I would say if you need section-specific sanitize then use section-specific callbacks. Even if considerable parts are shared with class based code it should be easy enough to neatly organize.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.