Our WP Debug is report that ‘Function create_function() is deprecated’. Any idea how to rewrite this code to not include create_function ?
self::register_form_init_scripts( $form, $field_values, $ajax );
if ( apply_filters( 'gform_init_scripts_footer', false ) ) {
add_action( 'wp_footer', create_function( '', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');' ), 20 );
add_action( 'gform_preview_footer', create_function( '', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');' ) );
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You no longer need to use create_function you can instead just use an anonymous function:
add_action( 'gform_preview_footer', create_function( '', 'GFFormDisplay::footer_init_scripts(' . $form['id'] . ');' ) );
Should be:
add_action( 'gform_preview_footer', function() use ($form){
GFFormDisplay::footer_init_scripts($form['id']);
});
https://www.php.net/manual/en/functions.anonymous.php
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0