• Hi,

    This is a potential feature request.

    It’d be massively useful to add an $args element of this function, so that you can send arguments to the callback function.

    Currently you have to create a separate function to sanitize each field with different requirements (eg max 30 characters, only numeric etc) whereas this information could easily be passed by arguments to the function.

    Even just sending the option name would be useful, so you could set up an array that stores the sanitize requirements for each option field.

    Cheers,

    Olly

Viewing 2 replies - 1 through 2 (of 2 total)
  • I couldn’t agree more! My plugin settings are three different types of data (a title, page IDs and hex color codes) and I am tearing my hair out trying to figure out how to validate all three with one function, not knowing which type it is supposed to be.

    I suppose that this function call was solely meant to sanitize potentially malicious code, but it seems like that is the point of using the Settings API in the first place and that this function call should be more flexible (or at least pass parameters) so that the programmers can use it to validate specific types of data (eg dates vs hex codes vs product ids vs titles, string length, etc).

    This lack of flexibility makes it too tempting to register each type of option in a different option row in the database — it seems to be the only work around to be able to sanitize/validate specific types of option inputs.

    If anyone knows if there is already a way to pass an argument to that function please let me know! I looked in the plugin.php code and it did not seem like there was …

    Thanks!

    Ok … what I read in wrox press “developing professional wp plugins” is that this function is passed the POST data from the option settings form that you create … so you should be able to access the individual fields from your settings form.

    my_validate_options_function ($the_form_data) {
    //set a new array for validated data
    $valid = array();

    … do something to $the_form_data[‘my_form_field’] to validate it …
    … then add it to the $valid array
    return the valid array
    }

    Since WP will ignore any options that are not specifically registered, you can just work with the form fields that you have defined and not worry about other crap that spoofed forms may send.

    I hope that makes sense … and that I’m right!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘register setting callback function’ is closed to new replies.