Home Page › Forums › WooCommerce Custom Tabs › Deprecated: Function create_function() is deprecated warning in WordPress debug › Reply To: Deprecated: Function create_function() is deprecated warning in WordPress debug
Participant
We 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
);
}