處理 sanitize_title()

去WordPress官方網站寫了一則留言,人家說,去臭蟲回報系統反應,應該比較有效。

留言內容如下:

The sanitize_title() function of WordPress 1.2 can not handle No-English characters well, especially the Asian characters such as Chinese, Japanese and Korean. If you generate a post-slug with a Chinese entry title, the post-slug will be all blank. However, WP system does not check such situation. For example, in post.php, it says:

if (empty($post_name))
$post_name = sanitize_title($post_title);
else
$post_name = sanitize_title($post_name);

The developers may not notice that after this progress, the $post_name maybe still empty. It’s an annoying problem for Non-English users to use the permalink function of WordPress. Althoght you can set the post-slug manually, you can not alter the $category_nicename of each category and $user_niceame for the authors. I think there must be more checks, for example, I added some codes to the post.php:

if (empty($post_name))
$post_name = sanitize_title($post_title);
else
$post_name = sanitize_title($post_name);

if (empty($post_name)) {
$post_ID = $wpdb->get_var("SELECT ID FROM $tableposts ORDER BY ID DESC LIMIT 1");
$post_name = "post-".$post_ID + 1;
}

If the $post_name is still empty after filling the sanitized data, just fill in something somehow. I filled it with the ID of each post just because each blog entry must have an ID. I hope that the official developers may notice this problem and contain some solution to solve this problem in the very next release. 🙂