pre要素の中はpとかbrが付かないので、script要素も同じルールを適用すればいいかも、と思いformatting.phpのfunction wpautop()の所を見る。80~81行目に
if (strpos($pee, '<pre') !== false) $pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</pre>' ", $pee);`</pre>
という部分があったので、ここのpreをscriptに書き換えたものを追記したらうまくいった。
このままだとWPのバージョンアップの時に上書きされてしまうので、昨日作ったプラグインの中に入れてみた。動作の流れがよく分からないけど、とりあえずうまく動く。
<pre>`<?php/*Plugin Name: ScriptShieldPlugin URI: http:/hogehoge.com/Description: stop wpautop in ScriptTags.Version: 0.1Author: oreAuthor URI: http:/hogehoge.com/*/$scriptshield = new ScriptShield();add_filter('the_content', array(&$scriptshield, 'delete_paragraph'));add_filter('the_excerpt', array(&$scriptshield, 'delete_paragraph'));unset($scriptshield);class ScriptShield { function delete_paragraph($content) { $content = preg_replace('|<p><script([^>]*)>|i', "<script$1>", $content); $content = str_replace('</script></p>', '</script>', $content); if (strpos($content, '<script') !== false) $content = preg_replace('!(<script.*?>)(.*?)</script>!ise', " stripslashes('$1') . stripslashes(clean_pre('$2')) . '</script>' ", $content); return $content; } }?>
BBcodeもどきを使うと、プラグインを使わなくなったときにゴミになるし嫌だな…と思っていたので、とりあえずこれを使ってみることにします。
本当はデフォルトで対応してくれてると助かるんだけど、scriptの中にpを入れる理由が何かあるんだろうか。その辺がわからないから、その内地雷踏みそうで怖い。それみたことかーッ!と誰かに言われそうだ。