你会有这样的虫子。因为你没有用sanitize_title()
.
并且您没有检查wp_unique_term_slug()
错误测试:
在名称中添加空格,然后查看带空格的slug在添加sanitize_title()
添加带逗号的术语5,5添加带空格的术语5 5结果重复所以只需像这样解决这个问题:
add_action(\'wp_insert_term_data\', \'slug_save_term_callback\', 10, 3 );
function slug_save_term_callback($data, $taxonomy, $args) {
$name = $data[\'name\'];
$name = wp_unique_term_slug(sanitize_title(str_replace(\',\', \'-\', $name)), (object) $args);
$data[\'slug\'] = $name;
return $data;
}