Title: Function create_function() is deprecated in 7.2+
Last modified: January 18, 2021

---

# Function create_function() is deprecated in 7.2+

 *  Resolved [musicman847](https://wordpress.org/support/users/musicman847/)
 * (@musicman847)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/function-create_function-is-deprecated-in-7-2/)
 * I require PHP 7.2 or greater for some plugins to work. Is Function create_function()
   deprecated in 7.2+? I’m getting the following error:
 * [18-Jan-2021 21:31:08 UTC] PHP Deprecated: Function create_function() is deprecated
   in /home/mywebsite/public_html/wp-content/plugins/code-snippets/php/snippet-ops.
   php(446) : eval()’d code on line 3

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/function-create_function-is-deprecated-in-7-2/#post-13932221)
 * Code Snippets doesn’t use `create_function` anywhere in the plugin. The current
   version should be compatible with PHP 5.2, though the upcoming v3 release will
   require 5.6. PHP 7 is not required.
 * The reason why you are receiving an error is because you are using `create_function`
   in one of your snippets. I recommend rewriting the code to use [anonymous functions](https://www.php.net/manual/en/functions.anonymous.php)
   instead.
 *  Thread Starter [musicman847](https://wordpress.org/support/users/musicman847/)
 * (@musicman847)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/function-create_function-is-deprecated-in-7-2/#post-13934847)
 * Awe I see. Thank you!! Can you recommend how I might rewrite this using an anonymous
   function?
 * add_filter(‘single_template’, create_function(
    ‘$the_template’, ‘foreach( (array)
   get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . “/single-{$cat-
   >term_id}.php”) ) return TEMPLATEPATH . “/single-{$cat->term_id}.php”; } return
   $the_template;’) );
 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/function-create_function-is-deprecated-in-7-2/#post-13936217)
 * You can do so like this:
 *     ```
       add_filter( 'single_template', function ( $the_template ) {
       	foreach ( (array) get_the_category() as $cat ) {
       		if ( file_exists( TEMPLATEPATH . "/single-{$cat->term_id}.php" ) ) {
       			return TEMPLATEPATH . "/single-{$cat->term_id}.php";
       		}
       	}
       	return $the_template;
       } );
       ```
   
 *  Thread Starter [musicman847](https://wordpress.org/support/users/musicman847/)
 * (@musicman847)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/function-create_function-is-deprecated-in-7-2/#post-13936460)
 * Awesome! Thank you for your help 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Function create_function() is deprecated in 7.2+’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [musicman847](https://wordpress.org/support/users/musicman847/)
 * Last activity: [5 years, 4 months ago](https://wordpress.org/support/topic/function-create_function-is-deprecated-in-7-2/#post-13936460)
 * Status: resolved