wordpress コアの autop 関数を使用して、改行を textareas から<p>
s および<br>
s に自動的に変換し、ライブラリ フォルダーで使用することにしました。
(ちなみに、Laravelにはこれを行うためのネイティブな方法はありませんよね?もしそうなら、私は本当にばかげていると思います)
だからmyproject/application/libraries/formatting.php
私は次のものを持っています:
class Formatting {
public function autop($pee, $br = true) {
[wpautop's code here]
}
}
そしてそれを次のように呼び出します
Formatting::autop($text);
したがって、このエラーが返されます
preg_replace_callback(): Requires argument 2, '_autop_newline_preservation_helper', to be a valid callback
次のブロックと関係があります
if ( $br ) {
$pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', '_autop_newline_preservation_helper', $pee);
$pee = preg_replace('|(?<!<br />)\s*\n|', "<br />\n", $pee); // optionally make line breaks
$pee = str_replace('<WPPreserveNewline />', "\n", $pee);
}
この機能が彼のためにそこにあることを要求する
function _autop_newline_preservation_helper( $matches ) {
return str_replace("\n", "<WPPreserveNewline />", $matches[0]);
}
この関数は、単一の改行を<br>
タグに変換する責任があるようです。ブロックを削除すると、コードは機能しますが、二重のif
改行でのみ機能します。<br>
この関数のコードを autop 関数と同じファイルに単純に追加すると、同じエラーが返されます。_autop_newline_preservation_helper
関数を含める適切な方法がわかりません。どうすればよいですか?