Support » Plugin: ReferralCandy for WooCommerce » Version 2.0.0 breaks the WooCommerce Integrations tab

  • Resolved Lucas Karpiuk

    (@karpstrucking)


    In version 2.0.0 a new class file was added and the way in which these are being included was changed to use the autoload_classes() function. However, this function is called via the woocommerce_integrations hook, which is a filter hook expecting an array of integrations to be returned. This is removing the integrations of all other plugins from being loaded into this filter.

    Relevant changes:

    
    Index: referralcandy-for-woocommerce/trunk/woocommerce-referralcandy.php
    ===================================================================
    --- a/referralcandy-for-woocommerce/trunk/woocommerce-referralcandy.php
    +++ b/referralcandy-for-woocommerce/trunk/woocommerce-referralcandy.php
    @@ -7,5 +7,5 @@
      * Author URI: http://www.referralcandy.com
      * Text Domain: woocommerce-referralcandy
    - * Version: 1.3.7
    + * Version: 2.0.0
      *
      * This program is free software: you can redistribute it and/or modify
    @@ -36,7 +36,6 @@
                 public function init() {
                     if (class_exists('WC_Integration')) {
    -                    include_once 'includes/class-wc-referralcandy-integration.php';
    -
    -                    add_filter('woocommerce_integrations', array($this, 'add_integration'));
    +                    add_action('woocommerce_integrations', 'autoload_classes');
    +                    add_filter('woocommerce_integrations', [$this, 'add_integration']);
                     } else {
                         add_action('admin_notices', 'missing_prerequisite_notification');
    @@ -54,4 +53,14 @@
     
             $WC_Referralcandy = new WC_Referralcandy(__FILE__);
    +    }
    +
    +    function autoload_classes() {
    +        $files = scandir(dirname(__FILE__) . '/includes');
    +        $valid_extensions = ['php'];
    +        foreach ($files as $index => $file) {
    +            if (in_array(pathinfo($file)['extension'], $valid_extensions)) {
    +                require_once('includes/' . pathinfo($file)['basename']);
    +            }
    +        }
         }
    

    Fix

    To fix this you can either roll back to a previous version of the plugin from a backup or patch the plugin manually until fixed by the author in a future version – to patch manually, replace the add_action() call on line 39 with a call to the autoload_classes() function:

    
    public function init() {
        if (class_exists('WC_Integration')) {
            autoload_classes();
            add_filter('woocommerce_integrations', [$this, 'add_integration']);
        } else {
            add_action('admin_notices', 'missing_prerequisite_notification');
        }
    
        load_plugin_textdomain('woocommerce-referralcandy', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    }
    
Viewing 1 replies (of 1 total)
  • Plugin Author ReferralCandy

    (@referralcandy)

    Hi Lucas!

    Thank you for catching this and putting up a topic for others to see. We have updated the plugin with the proposed fix and the integration page should be working fine now for the new version(v2.0.1). 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Version 2.0.0 breaks the WooCommerce Integrations tab’ is closed to new replies.