简体   繁体   English

自从9.1.2起,在已上传的文件中,WordPress似乎用破折号替换了所有下划线。 我该如何删除?

[英]Wordpress seems to replace all underscores with dashes since 9.1.2 in uploaded files. How can I remove this?

I have noticed that it seems like that Wordpress is replacing all underscores with dashes in uploaded file names since the lastest update (9.1.2). 我注意到,自从最近一次更新(9.1.2)以来,Wordpress似乎正在将所有下划线替换为上载文件名中的破折号。 However, I need the underscores in the file names to be kept. 但是,我需要保留文件名中的下划线。

I found a plugin that I modified but it doesn't seem to help.. See the code below. 我找到了修改后的插件,但似乎无济于事。请参见下面的代码。

function mfl_make_filename_lowercase($filename) {
    $info = pathinfo($filename);
    $ext  = empty($info['extension']) ? '' : '.' . $info['extension'];
    $name = basename($filename, $ext);
    $name = preg_replace('/-/', '_', $name);
    return strtolower($name) . $ext;
}
add_filter('sanitize_file_name', 'mfl_make_filename_lowercase', 10);

I have looked around quite a bit, I have checked the formatting.php in wp-includes and changed the preg_replace to '_' instead of '-' where I found it. 我环顾了四周,我检查了wp-includes中的formatting.php,并将preg_replace更改为“ _”而不是在找到它的“-”。 I have done the same in files.php in wp-admin/includes. 我已经在wp-admin / includes中的files.php中完成了同样的操作。

I must be missing something. 我肯定错过了什么。 Or is it simply not possible? 还是根本不可能? Please help! 请帮忙!

Google treats - as word separator, but not _. Google将-视为单词分隔符,而不是_。 Here is an article that explains it. 这是一篇解释它的文章

But if you still looking for a solution here is the answer 但是,如果您仍在寻找解决方案,这里就是答案

check out wp-includes/formatting.php 查看wp-includes / formatting.php

on line 1241 you will get sanitize_title_with_dashes function find 在1241行,您将获得sanitize_title_with_dashes函数查找

$title = strtolower($title);
$title = preg_replace('/&.+?;/', '', $title); // kill entities
$title = str_replace('.', '-', $title);
$title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
$title = preg_replace('/\s+/', '-', $title);
$title = preg_replace('|-+|', '-', $title);
$title = trim($title, '-');

swap out the dashes by underscore 用下划线替换破折号

Note that any posts you've created before this change, and rely on the %postname% permalink structure tag, will be broken. 请注意,您在此更改之前创建的所有依赖%postname%永久链接结构标记的帖子都会被破坏。

In that case you'll need to go back and republish those post so the dashes are swapped out for the underscores. 在这种情况下,您需要返回并重新发布这些帖子,以便将下划线替换为下划线。 Or just write yourself a little SQL to replace them. 或者只是编写一些SQL来代替它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM