我可以在多个主题修改文本框上使用相同的清理功能吗?

时间:2017-06-10 作者:Gregory Schultz

我有一个具有多个选项的主题模块,目前正在为这些选项添加消毒选项。这是我正在使用的代码:

$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\',
));
这是我用来清理数据的函数:

function twsa_sanitize_text( $input ) {
return wp_kses_post( force_balance_tags( $input ) );
};
是否可以使用一个函数来清理多个文本字段,还是需要为每个文本字段创建一个函数?

谢谢

1 个回复
最合适的回答,由SO网友:Johansson 整理而成

正如我所看到的,您的输入都是相同的(文本框),并且很可能返回相同类型的数据(一些人类可读的文本),因此我认为您不需要不同的函数。

除非您有复选框、单选按钮、HTML输入等可能需要不同类型的卫生设施(例如允许使用一些特殊的HTML标记),否则您可以做到这一切。

结束

相关推荐