WordPress Ping Optimizerのインストールとエラーが出た時の対処法

WordPress Ping Optimizerとは

記事を公開した時にはpingを送信して伝えることで、他サイトからユーザに連絡することができる。

SEOとしてなくてはならないもの。

ただ、wordpressのpingは記事を更新するたびに送信していると、googleからスパム扱いされる可能性があるらしい

それの回避として、Pingの送信は記事の公開時に一度しか行われない。

 

適応してみると画面崩れが起こるケースがある

いざ、プラグインを適応してみると、ページ上部に予期せぬ崩れが。

コードを見てみると

<b>Warning</b>: count(): Parameter must be an array or an object that implements Countable in <b>/省略/wordpress-ping-optimizer/cbnet-ping-optimizer.php</b> on line <b>533</b

WordPress Ping Optimizerでエラーが発生している。

533行目はこちら

「 $pingCount=count($this->cbnetpo_future_pings);」

 

原因

phpのバージョンを7.2以上にあげるとcountの仕様が変更されていて起こるらしい

count()の引数がnullだった場合、warningを出す仕様に変更された。

 

対処方法

そのため、引数のチェックを行ってから実行する仕様に変更
※とりあえずの対応なので動作未確認。エラーは出なくなりました。
※自己責任で変更お願いします。

if (is_array($this->cbnetpo_future_pings)) {
$pingCount=count($this->cbnetpo_future_pings);
}
// $pingCount=count($this->cbnetpo_future_pings);

 

 


Fatal error: Uncaught Error: Call to undefined function set_post_views() in /home/jszk/desnote.com/public_html/wpjs/wp-content/themes/the-thor-child/single.php:658 Stack trace: #0 /home/jszk/desnote.com/public_html/wpjs/wp-includes/template-loader.php(78): include() #1 /home/jszk/desnote.com/public_html/wpjs/wp-blog-header.php(19): require_once('/home/jszk/desn...') #2 /home/jszk/desnote.com/public_html/index.php(17): require('/home/jszk/desn...') #3 {main} thrown in /home/jszk/desnote.com/public_html/wpjs/wp-content/themes/the-thor-child/single.php on line 658