
WPホームページ研究所運営サポートチーム監修のオムスビ(@OMUSUVIcom)です。
本日はエラー対策の業務メモです。ワードプレスで運営中のサイトに下記エラーが出た際の対策です。
Warning: Parameter 2 to ACF_custom_searchadd() expected to be a reference, value given in /home/account/example.com/public_html/wp-includes/class-wp-hook.php on line 288
この手のエラーはfunctions.php内の記述内容(文法)に問題があります。表示されるパターンは以下です。
・レンタルサーバーの引越後に表示されるようになった
・何もしていないのにある日突然エラーが表示された
・プラグインをアップデートしてからずっと表示されている
ちなみに「class-wp-hook.php」の288行目が該当するソースコードが下記。
public function apply_filters( $value, $args ) {
if ( ! $this->callbacks ) {
return $value;
}
$nesting_level = $this->nesting_level++;
$this->iterations[ $nesting_level ] = array_keys( $this->callbacks );
$num_args = count( $args );
do {
$this->current_priority[ $nesting_level ] = current( $this->iterations[ $nesting_level ] );
$priority = $this->current_priority[ $nesting_level ];
foreach ( $this->callbacks[ $priority ] as $the_ ) {
if ( ! $this->doing_action ) {
$args[0] = $value;
}
// Avoid the array_slice if possible.
if ( $the_['accepted_args'] == 0 ) {
$value = call_user_func( $the_['function'] );
} elseif ( $the_['accepted_args'] >= $num_args ) {
$value = call_user_func_array( $the_['function'], $args );
} else {
$value = call_user_func_array( $the_['function'], array_slice( $args, 0, (int) $the_['accepted_args'] ) );
}
}
} while ( false !== next( $this->iterations[ $nesting_level ] ) );
unset( $this->iterations[ $nesting_level ] );
unset( $this->current_priority[ $nesting_level ] );
$this->nesting_level--;
return $value;
}
そして288行目の1文は以下です。
$value = call_user_func_array( $the_['function'], $args );
可能性が高いのは「PHPのバージョン」が変わってPHPの記述が「文法エラー扱い」になっているパターン。以下はfunctions.phpの処理です。エラーは「class-wp-hook.php」でも原因はfunctions.phpにあります。
function ACF_custom_searchadd( $where, &$wp_query ) {
//ここに処理を書きます
}
こういった書き方ですね。現在動作しているPHPバージョンによっては「&」が邪魔をしてしまいます。PHPがモジュール版で動いているか、CGI版で動いているかにもよっても処理が変わります。原因は複合的です。
function ACF_custom_searchadd( $where, $wp_query ) {
//ここに処理を書きます
}
PHP7.4のCGI版なら上記の書き方に修正すればOKです。
最新式の無料プラグインを事前公開
WordPressは公式サイトに登録済みのプラグインだけで全機能を補足しきれません。当サイトでは使いやすさを追求した魅惑的なプラグインを無料でダウンロードいただけます。運営ホームページのマーケティング力をさらに高めるチャンスです。まずは無料でDLしてお試しくださいませ。
→ 改良されたプラグインを確認する