Home Page › Forums › WooCommerce Custom Tabs › Deprecated: Function create_function() is deprecated warning in WordPress debug
Tagged: deprecated
- This topic has 5 replies, 4 voices, and was last updated 4 years, 6 months ago by WebshopLogic.
-
AuthorPosts
-
Participant
Does this need to be fixed or can I ignore this??
Deprecated: Function create_function() is deprecated in /public_html/wp-content/plugins/woocommerce-custom-tabs-pro/woocommerce-custom-tabs-pro.php on line 275
KeymasterYou can ignore this message. It is only a warning, there is no problem with the functionality.
ParticipantWe are currently on php 7.1 on a live site using woocommerce-custom-tabs-pro plugin. Soon we will migrate to php 7.2, so from then, the warning will appear in the front-end. Thus, we need this deprecation function to be replaced so the user is not visualising this warning.
We propose a solution attached to this comment.
Please, consider applying those changes.
Thank you
ParticipantHi @WebshopLogic ,
We know it’s only a warning, but warnings very soon become issues as time goes on!
Is this deprecated line being replaced in a future update
Kind RegardsParticipantWe are upgrading our servers PHP version to 7.3 (soon 7.4) and git the same PHP notice:
Deprecated: Function create_function() is deprecated in /Users/joan/Sites/netzstrategen/wopa/htdocs/local-plugins/woocommerce-custom-tabs-pro/woocommerce-custom-tabs-pro.php on line 276
Our proposed solution is to substitute the
create_function()
call with an anonymous function. I.e. Change lines 272-276 in file woocommerce-custom-tabs-pro/woocommerce-custom-tabs-pro.php:
Before//callback is a dynamic function, it is call $this->woocommerce_tab_content function with $tab_code parameter $tabs[ $product_tabpage_post -> post_name ] = array( 'title' => do_shortcode( $tab_custom_title == '' ? $product_tabpage_post -> post_title : $tab_custom_title ), 'priority' => $priority, 'callback' => create_function('', 'global $wct; $wct->woocommerce_tab_content("' . $product_tabpage_post -> post_name . '", ' . $product_tabpage_post->ID . ');' ),
After
//callback is a dynamic function, it is call $this->woocommerce_tab_content function with $tab_code parameter $callback = function($post_name, $post_id) { global $wct; $wct->woocommerce_tab_content($post_name, $post_id); }; $tabs[ $product_tabpage_post -> post_name ] = array( 'title' => do_shortcode( $tab_custom_title == '' ? $product_tabpage_post -> post_title : $tab_custom_title ), 'priority' => $priority, 'callback' => $callback($product_tabpage_post->post_name, $product_tabpage_post->ID) );
As a diff:
diff --git a/woocommerce-custom-tabs-pro/woocommerce-custom-tabs-pro.php b/woocommerce-custom-tabs-pro/woocommerce-custom-tabs-pro.php index 5fd17560..9d0356de 100644 --- a/local-plugins/woocommerce-custom-tabs-pro/woocommerce-custom-tabs-pro.php +++ b/local-plugins/woocommerce-custom-tabs-pro/woocommerce-custom-tabs-pro.php @@ -269,11 +269,15 @@ class WCT { //x$priority = $priority_field_object['value']; $priority = get_field('priority', $product_tabpage_post->ID, false); - //callback is a dynamic function, it is call $this->woocommerce_tab_content function with $tab_code parameter + //callback is a dynamic function, it is call $this->woocommerce_tab_content function with $tab_code parameter^M + $callback = function($post_name, $post_id) {^M + global $wct;^M + $wct->woocommerce_tab_content($post_name, $post_id);^M + };^M $tabs[ $product_tabpage_post -> post_name ] = array( 'title' => do_shortcode( $tab_custom_title == '' ? $product_tabpage_post -> post_title : $tab_custom_title ), 'priority' => $priority, - 'callback' => create_function('', 'global $wct; $wct->woocommerce_tab_content("' . $product_tabpage_post -> post_name . '", ' . $product_tabpage_post->ID . ');' ), + 'callback' => $callback($product_tabpage_post->post_name, $product_tabpage_post->ID)^M ); }
-
AuthorPosts
- You must be logged in to reply to this topic.