sanitize_user
函数具有sanitize_user
滤器该过滤器为您提供$username、$raw\\u username、$strictsanitize_user
根据内联文档,希望您返回$username:
/**
* Filters a sanitized username string.
*
* @since 2.0.1
*
* @param string $username Sanitized username.
* @param string $raw_username The username prior to sanitization.
* @param bool $strict Whether to limit the sanitization to specific characters. Default false.
*/
您可以执行以下操作:
function wpse_283736_sanitize_user_filter($username){
// do your sanitization with $username
return $username;
}
add_filter(\'sanitize_user\', \'wpse_283736_sanitize_user_filter\');
或者像这样
function wpse_283736_sanitize_user_filter($username, $raw_username, $strict){
// do your sanitization with $username or maybe $raw_username
return $username; // or return $raw_username;
}
add_filter(\'sanitize_user\', \'wpse_283736_sanitize_user_filter\', 10, 3);
你可以钓到
pre_user_login
过滤器,在上可用
wp_insert_user
函数,用于Woocommerce用户注册过程。
$pre_user_login = apply_filters( \'pre_user_login\', $sanitized_user_login );
function wpse_283736_pre_user_login_filter($sanitized_user_login){
// do your sanitization with $sanitized_user_login
return $sanitized_user_login;
}
add_filter(\'pre_user_login\', \'wpse_283736_pre_user_login_filter\', 10, 3);
如果您不熟悉WordPress过滤器,我建议您先阅读以下参考资料: