1

I have a theme mod with multiple options and currently adding sanitizing options to those choices. This is my code I'm using:

$wp_customize->add_section( 'twsa_feed' , array(
'title'       => __( 'RSS Feed settings','rss_feed'),
'priority'    => 30,
'description' => 'Your RSS feed settings',
) );
$wp_customize->add_setting( 'short-show-name' );
$wp_customize->add_control( 'short-show-name', array (
'label' => 'Show name',
'description' => 'Abbreviated show name, not the full name',
'section' => 'twsa_feed',
'type' => 'textbox',
'sanitize_callback' => 'twsa_sanitize_text',
));
$wp_customize->add_setting( 'show-category' );
$wp_customize->add_control( 'show-category', array (
'label' => 'Category',
'description' => 'What category does your show belong to? (not really important to stick to certain categories, can make one up)',
'section' => 'twsa_feed',
'type' => 'textbox',
'sanitize_callback' => 'twsa_sanitize_text',
));
$wp_customize->add_setting( 'author-name' );
$wp_customize->add_control( 'author-name', array (
'label' => 'Author name',
'description' => 'Must be a name',
'section' => 'twsa_feed',
'type' => 'textbox',
'sanitize_callback' => 'twsa_sanitize_text',
));
$wp_customize->add_setting( 'author-email' );
$wp_customize->add_control( 'author-email', array (
'label' => 'Author e-mail',
'description' => 'e-mail address',
'section' => 'twsa_feed',
'type' => 'textbox',
'sanitize_callback' => 'twsa_sanitize_text',
));
$wp_customize->add_setting( 'itunes-subtitle' );
$wp_customize->add_control( 'itunes-subtitle', array (
'label' => 'iTunes subtitle',
'description' => 'Short description of show',
'section' => 'twsa_feed',
'type' => 'textbox',
'sanitize_callback' => 'twsa_sanitize_text',
));

This is the function I use to sanitize the data:

function twsa_sanitize_text( $input ) {
return wp_kses_post( force_balance_tags( $input ) );
};

Is it OK to use one function to sanitize multiple text fields or do I need to create a function for each text field?

Thanks

  • 1
    your inputs are all the same (textbox) and most likely return the same type of data ( some human-readable text ), so i don't think you need different functions. One will do it all, unless you have checkbox, radio buttons, HTML input, etc. – Jack Johansson Jun 10 '17 at 10:38
  • 1
    Of course it's ok! If they're all sanitized in the same way, then that's exactly the intention of a function - reuse. – TheDeadMedic Jun 10 '17 at 12:10
  • Can one of you move your comment to an answer? – Gregory Schultz Jun 10 '17 at 14:39
1

As i can see, your inputs are all the same (textbox) and most likely return the same type of data ( some human-readable text ), so i don't think you need different functions.

One will do it all, unless you have checkbox, radio buttons, HTML input, etc which might need different types of sanitation (such as allowing some special HTML tags).

Your Answer

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

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