Deprecated: Functio...
 

Deprecated: Function create_function() is deprecated  


Alan
Posts: 35
 Alan
(@alan)
Eminent Member
Joined: 2 months ago

Post PHP 7.2 version upgrade, my php script in WordPress 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.

1 Reply
admin
Posts: 93
Admin
(@mjv119gmail-com)
Member
Joined: 5 years ago

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

Leave a reply


 
Preview 0 Revisions Saved
Share: