Fatal error: Uncaught Error: Call to undefined function create_function()の対応

概要説明

PHPを最新にする際に対応が必要となるエラーの一つ。非推奨の書き方を残しているとバージョンアップの際に関数自体が削除されてしまい、PHP切り替えの時にエラーになることがあります。

functions.php
// エラーになる記述
add_action('widgets_init', create_function('', 'return register_widget('Sample_Widget_Item');'));

記述を変更することで解決(無名関数)

functions.php
// エラーにならない書き方
add_action('widgets_init', function(){register_widget('Sample_Widget_Item');});

PHPのバージョンを変更する場合は、動かなくなったりする処理があるので要注意です。

PHP7.2~PHP8.0の場合のエラー

Deprecated: Function create_function() is deprecated in

こちらも同様の修正で対応ができます
create_function()は、PHP7.2から非推奨になっています

ログの確認について

WordPress Developer Resources

関連機能

  1. this will throw an Error in a future version of PHPの対応

  2. WordPress 「現在メンテナンス中のため、しばらくの間ご利用いただけません。」画面を解除する方法

  3. Notice: Undefined index: post_typeの対応

サイドバー

よく使うカスタマイズ

最近の記事

アニメの名言集

ダメージゼロは何倍してもゼロ!

痛いのは嫌なので防御力に極振りしたいと思います。
by メイプル

Profile

PAGE TOP
Amazon プライム対象