筛选器正在将标题转换为小写sanitize_title
// in wp-includes/default-filters.php
add_filter( \'sanitize_title\', \'sanitize_title_with_dashes\', 10, 3 );
// it means => calling sanitize_title_with_dashes() in wp-includes/formatting.php
下面是关于可以做什么、推荐的和不推荐的方法的解释
不建议您删除此过滤器,但not recommmended由于此筛选器用于转换带破折号的标题,因此您可以查看源代码以供参考。
// in theme\'s php
remove_filter( \'sanitize_title\', \'sanitize_title_with_dashes\', 10 );
建议在不影响原始功能的情况下,添加带有自定义检查的过滤器“sanitize_title”
// load later than the original filters
add_filter( \'sanitize_title\', \'ws365107_custom_sanitize_title\', 15, 3 );
function ws365107_custom_sanitize_title( $title, $raw_title, $context ) {
// may make use of the $_POST object data to check if it adding
// for original design $context = \'save\' could distinguish, however, theme developers usually don\'t place this $context argument, so it render the argument useless
if( $context === \'save\' ) {
}
// check by action if action = createuser from user-new.php, avoid affecting other situation
// please adjust if use in other situations
if( isset( $_REQUEST ) && isset($_REQUEST[\'action\']) ) {
// custom logic in checking user name using $raw_title
$title = $raw_title;
return $title;
}
// return original title for other situations
return $title;
}
扩展阅读: