• Resolved musicman847

    (@musicman847)


    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

    (@bungeshea)

    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 instead.

    Thread Starter musicman847

    (@musicman847)

    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

    (@bungeshea)

    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

    (@musicman847)

    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.