• Resolved RalphGL

    (@ralphgl)


    Deprecated: Function create_function() is deprecated in /var/www/html/wp-content/plugins/code-snippets/php/snippet-ops.php(361) : eval()’d code on line 8

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    This is a problem with your code. You shouldn’t be using create_function(), instead use anonymous functions.

    If you find the snippet that uses create_function() and post the relevant part here, I can show you how to update it.

    Thread Starter RalphGL

    (@ralphgl)

    Thank you Shea, and sorry for my topic here. This is NOT a Code Snippet-fault!
    The deprecated funktion was used in code i used for sorting the sites:

    function sort_my_sites($blogs) {
    $f = create_function(‘$a,$b’,’return strcasecmp($a->blogname,$b->blogname);’);
    uasort($blogs, $f);
    return $blogs;
    }
    add_filter(‘get_blogs_of_user’,’sort_my_sites’);

    Sorry, my php skills are very bad.

    Plugin Author Shea Bunge

    (@bungeshea)

    Here’s how you could rewrite that to work with newer versions of PHP:

    add_filter( 'get_blogs_of_user', function ( $blogs ) {
    
    	uasort( $blogs, function ( $a, $b ) {
    		return strcasecmp( $a->blogname, $b->blogname );
    	} );
    
    	return $blogs;
    } );
    Thread Starter RalphGL

    (@ralphgl)

    thx – your snippet works fine on my multisite now!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Used Function create_function() is deprecated’ is closed to new replies.