1

as a noob I managed out to create a custom selectbox control for categories in customizer. But now I am trying to find a clever 'sanitize_callback' function in order to ensure security. Here is my approach so far:

function bloook_sanitize_category_select( $cat_id, $setting) {
    $cat_id = absint($cat_id);
    return is_string(get_the_category_by_ID( $cat_id )) ? $cat_id :  $setting->default;
}

But I am not convinced that this is a satisfactory. The functionality is still fine, but how do I test the security?

So I wonder if someone is out there who can help. Many thanks in advance.

  • what you are not sure? – TrubinE Mar 1 '17 at 12:32
  • WordPress offers a lot of sanitization/escape functions. Check here: codex.wordpress.org/Data_Validation – Laxmana Mar 1 '17 at 12:32
  • looks all good. – majick Mar 1 '17 at 15:45
  • @TurbinE: Thank you and sorry for my English. I am not sure if my code is secure, because I don't know how to test the security. My PHP skills are not very sophisticated. I found a lot of tutorials for making a category field in customizer I did not find one with a 'sanitize_callback' for it. So I made my own as shown above in the hope that if its lousy or riskiy someone might give me a hint... . – Friedrich Siever Mar 1 '17 at 18:01
  • @majick: Thanks to your comment I am feeling better with it. Thank you. – Friedrich Siever Mar 1 '17 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.