Deprecated: Function create_function() is deprecated warning in WordPress debug

Home Page Forums WooCommerce Custom Tabs Deprecated: Function create_function() is deprecated warning in WordPress debug

Tagged: 

This topic contains 5 replies, has 4 voices, and was last updated by  WebshopLogic 1 month ago.

Viewing 6 posts - 1 through 6 (of 6 total)

  • Author

    Posts

  • #8847


    Benno

    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

    #8848


    WebshopLogic

    Keymaster

    You can ignore this message. It is only a warning, there is no problem with the functionality.

    #9698


    Stephan

    Participant

    We 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

    #9767


    Rob

    Participant

    Hi @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 Regards

    #10318


    Stephan

    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
                                    );
                            } 
    

    #10322


    WebshopLogic

    Keymaster

    New version (1.0.27) released in which the issue has been fixed.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Social media & sharing icons powered by UltimatelySocial