WordPress で “(ダブル・クォーテーション)や’(シングル・クォーテーション)が自動的に全角になってしまう
自分のブログに書いたソースコードをコピペしたら使えなかった。
どうやら”(ダブル・クォーテーション)と’(シングル・クォーテーション)が、記事を投稿すると全角になってしまうようだ。
Webを検索するとたくさんの先人の皆さんがいらっしゃったが、WordPress 2.8.4 でもこの仕様は同じだった。
WordPress 2.8.4 では、wp-includes ディレクトリにある formatting.php の70行目にある、preg_replace の行をコメントアウト
過去の記事で、全角になってしまった " (ダブル・クォーテーション)や '(シングル・クォーテーション)も、編集し直さなくてもこれで元に戻る。
if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0}
&& empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) { // If it’s not a tag
// static strings
$curl = str_replace($static_characters, $static_replacements, $curl);
// regular expressions
// $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
} else {
preg_replace は、PHP の関数で、 $curl の中身を検索して、$dynamic_characters 正規表現に一致するものを、 $dynamic_replacements に置き換えている。
【preg_replace】 http://cai.cs.shinshu-u.ac.jp/sugsi/Lecture/php/manual/function.preg-replace.html
この部分の変数は、WordPress 2.8.4 では formatting.php の58~60行目に記述があった。 array 定義されている。

実際には、ダブル・クォーテーションやシングル・クォーテーション以外にも幾つかの文字を置き換えている。
正規表現を管理人の知識では読むと時間がかかりそうなので、とりあえず単にコメントアウトして様子見。。
WordPress 2.9 での追記
WordPress 2.9 では、formatting.php のコメントアウト対象の preg_replace の行は、86行目でした。
if ( !empty($curl) && '<' != $curl{0} && '[' != $curl{0}
&& empty($no_texturize_shortcodes_stack) && empty($no_texturize_tags_stack)) {
// This is not a tag, nor is the texturization disabled
// static strings
$curl = str_replace($static_characters, $static_replacements, $curl);
// regular expressions
// $curl = preg_replace($dynamic_characters, $dynamic_replacements, $curl);
} elseif (!empty($curl)) {
コメントを残す
コメントを RSS 2.0で購読