PHP Fatal error: Uncaught Error: Call to undefined function create_function()

Solution to PHP Fatal error call to undefined create_function()
Reading Time: 2 minutes

PHP Fatal error: Uncaught Error: Call to undefined function create_function() in /Users/napoleon/Sites/pfswp22/wp-content/themes/material/framework/widget-social-links.php:166

PHP Fatal error:  Uncaught Error: Call to undefined function create_function() in /Users/napoleon/Sites/pfswp22/wp-content/themes/material/framework/widget-social-links.php:166
Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.

Root cause of the problem:

create_function() is depriciated from PHP 7.2

Reason for getting Undefined function:

  1. PHP is not able to understand or get the definition of the function. It could be because of a misspelling.
  2. Or you could be calling a function that is an api of an extension. If the extension is not installed its quite possible to get the function undefined error.
    One example for this is, if you have not installed php curl extension i don’t mean the curl commandline tool which is completely different.
    When you try to call the function curl_init(), Its quite possible to get the error Call to undefined function curl_init()

It could be because of your theme not supporting in your current PHP Version above PHP 7.2

Solution:

  1. Try deactivating the theme.
  2. If you are not able to do it on the browser
  3. take backup of the entire wordpress folder
  4. rename the active theme folder to ‘foldername-old’ or delete the active theme that is having the problem.
  5. Install wp cli , WP CLI is a very useful commandline tool that helps you to do debugging for many of the wordpress related problems.

Using WP CLI to solve __Call to undefined function create_function()__

in your command line

$ wp theme list
+------------------------+----------+--------+---------+
| name                   | status   | update | version |
+------------------------+----------+--------+---------+
| material-design-google | inactive | none   | 0.4.0   |
| materialis             | inactive | none   | 1.1.16  |
| twentynineteen         | inactive | none   | 2.1     |
| twentytwenty           | inactive | none   | 1.8     |
| twentytwentyone        | inactive | none   | 1.4     |
+------------------------+----------+--------+---------+

# Now choose a different theme that is working or you can 
# Switch to one of the default theme wordpress comes with.
$ wp theme activate twentytwenty 
Success: Switched to 'twentytwenty' theme.

Thats all. You are done. Hope that solves your problem.