Support » Plugin: Code Snippets » deprecated php function

  • Resolved vikiv

    (@vikiv)


    Hi, I’m using this snippet but I discovered that create_function() is deprecated. I have not found a solution to fix the problem. Any help will be greatly appreciated!

    if ( !current_user_can(‘administrator’) ) {
    add_action( ‘init’, create_function( ‘$a’, “remove_action( ‘init’, ‘wp_version_check’ );” ), 2 );
    add_filter( ‘pre_option_update_core’, create_function( ‘$a’, “return null;” ) );
    }

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

    (@bungeshea)

    Hey,

    Yes, create_function() has been deprecated and it’s not recommended to use it in newer versions of PHP.

    Fortunately, PHP 5.3 and later includes a better feature called anonymous functions. You can read more about them on the PHP documentation, but here’s an example of your code converted to use an anonymous function:

    if ( ! current_user_can( 'administrator' ) ) {
    	
    	add_action( 'init', function () {
    		remove_action( 'init', 'wp_version_check' );
    	}, 2 );
    
     
    	add_filter( 'pre_option_update_core', function ( $a ) {
    		return null;
    	} );
    }

    Thanks a Million!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.