Home Forums Programming Deprecated: Function create_function() is deprecated – WordPress

  • Author
    Posts
  • Jeevitha Gopinath
    Member
    Post count: 1

    Post PHP 7.2 version upgrade, my php script in WodPress throwing an error as mentioned below.

    Line Thrown the Error:

    add_action('widgets_init', create_function('', 'return register_widget("music_post_widget");'));

    Error:

    Deprecated: Function create_function() is deprecated in /folder/file.php on 2

    I think create_function() is deprecated in PHP 7.2 version.

     

  • admin
    Keymaster
    Post count: 111

    create_function method is deprecated in Php v7.2. So you have to make your code compatible with Php version greater than 7.2.

    Good news is that there is an easy solution for this.

    Replace your below line

    add_action('widgets_init', create_function('', 'return register_widget("music_post_widget");'));

    With

    function sampleFunction ()
    {
    return register_widget('music_post_widget');
    }
    add_action ('widgets_init', 'sampleFunction ');

    music_post_widget is the word you have to copy from the line 1.

Reply To: Deprecated: Function create_function() is deprecated – WordPress
Your information: