我在评论中有一个主题,我确实在像这样的少数情况下添加了“type”=>“select”部分。
$wp_customize->add_setting( \'personal_lite_post_link\', array(
\'default\' => \'enable\',
\'sanitize_callback\' => \'personal_lite_select_callback\'
) );
$wp_customize->add_control(\'postlink-options\', array(
\'label\' => esc_html__(\'Post navigation\', \'personal-lite\'),
\'section\' => \'personal_lite_post\',
\'settings\' => \'personal_lite_post_link\',
\'type\' => \'select\',
\'choices\' => array(\'enable\' => esc_html__(\'Enable\', \'personal-lite\'), \'disable\' => esc_html__(\'Disable\', \'personal-lite\'))
) );
像这样消毒
function personal_lite_select_callback($input) {
$valid = array(
\'lightslategrey\' => esc_html__(\'Grey\', \'personal-lite\'),
\'seagreen\' => esc_html__(\'Green\', \'personal-lite\'),
\'enable\' => esc_html__(\'Enable\', \'personal-lite\'),
\'disable\' => esc_html__(\'Disable\', \'personal-lite\'),
);
if (array_key_exists($input, $valid)) {
return $input;
} else {
return \'\';
}
}
现在,审阅者要求将消毒分为两个功能?如何做到这一点?
以下是评论员的确切说法。
I\'m a fan of whitelisting for sanitization. However, this function should be broken into two separate functions:
Only some settings can have some of those keys. Make sure the setting is valid by using the appropriate whitelist function for that setting.
如何解决这个问题?请帮帮我。