wordpress phpバージョンアップで本文が消えたときの対処方法


PHP5.4からphp.7.4に変更したら、wordpressの本文だけが消えた。

対象方法のメモ書き

php5.4を使っていて、7.2の際にアップデートしたときに本文が消えた。

そのときは、細かく調査する暇がなかったので、phpバージョンを戻して終了していた。

さすがに、セキュリティ的に問題なのでアップデートして、不具合に対処することにした。

 

プラグインの有効化から、brBRbrプラグイン を停止すると不具合が解消した。

brBRbrプラグイン が、php7以降に対応出来ていないらしい。

 

<?php
/*
Plugin Name:brBrbr
Plugin URI:http://camcam.info/wordpress/101/
Description:Line feed is converted to &lt;br /&gt;.
Version:2.0
Author:CamCam
Author URI:http://camcam.info/
*/

remove_filter(‘the_content’,’wpautop’);
add_filter(‘the_content’,’brBrbr’);

remove_filter(‘comment_text’, ‘wpautop’, 30);
add_filter(‘comment_text’,’brBrbr’,30);

function brBrbr($brbr) {
$brbr = str_replace(array(“\r\n”, “\r”), “\n”, $brbr); // cross-platform newlines
$brbr = str_replace(“\n”, “<br />\n”, $brbr); // cross-platform newlines
$brbr = preg_replace(‘!(</?(?:table|img|thead|tfoot|caption|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|textarea|input|blockquote|address|p|math|script|h[1-6])[^>]*>)\s*<br />!’, “$1”, $brbr);
$brbr = preg_replace(‘|<blockquote([^>]*)>|i’, “</p>\n<blockquote$1><p>”, $brbr);
$brbr = str_replace(‘</blockquote>’, “</p></blockquote>\n<p>”, $brbr);
$brbr = preg_replace(‘/(<pre.*?>)(.*?)<\/pre>/ise’, “clr_br(‘$0’)”, $brbr);
$brbr = preg_replace(‘/(<script.*?>)(.*?)<\/script>/ise’, “clr_br(‘$0’)”, $brbr);
$brbr = preg_replace(‘/(<form.*?>)(.*?)<\/form>/ise’, “clr_br(‘$0’)”, $brbr);
$brbr=”<p>\n”.$brbr.”</p>\n”;
return $brbr;
}

function clr_br($str){
$str = str_replace(“<br />”,””,$str);
$str = str_replace(‘\”‘,’”‘,$str);
return $str;
}

?><

とあるのを、赤字の3行を下記のように書き換える。

$brbr = preg_replace_callback(‘/(<pre.*?>)(.*?)<\/pre>/is’, function($m) {return clr_br($m[0]);}, $brbr);
$brbr = preg_replace_callback(‘/(<script.*?>)(.*?)<\/script>/is’, function($m) {return clr_br($m[0]);}, $brbr);
$brbr = preg_replace_callback(‘/(<form.*?>)(.*?)<\/form>/is’, function($m) {return clr_br($m[0]);}, $brbr);

更新すると本文が表示されるようになった

Leave a comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


 

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)