• Resolved madmax4ever

    (@madmax4ever)


    Hello,

    On a staging site (luckily) I discovered that this plugin:

    • if activated when WooCommerce is not activated
    • if active but WooCommerce gets deactivated

    crashes the website. The following fatal error occurs:

    PHP Fatal error:  Uncaught Error: Class "KP_Api" not found in /home/<my_wp_path>/wp-content/plugins/klarna-payments-for-woocommerce/klarna-payments-for-woocommerce.php:141
    Stack trace:
    #0 /home/<my_wp_path>/wp-includes/class-wp-hook.php(308): WC_Klarna_Payments->init()
    #1 /home/<my_wp_path>/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
    #2 /home/<my_wp_path>/wp-includes/plugin.php(517): WP_Hook->do_action()
    #3 /home/<my_wp_path>/wp-settings.php(486): do_action()#4 /home/<my_wp_path>/wp-config.php(192): require_once('/home/<my_wp_path>/...')
    #5 /home/<my_wp_path>/wp-load.php(50): require_once('/home/<my_wp_path>/...')
    #6 /home/<my_wp_path>/wp-admin/admin.php(34): require_once('/home/<my_wp_path>/...')
    #7 /home/<my_wp_path>/wp-admin/plugins.php(10): require_once('/home/<my_wp_path>/...')
    #8 {main}
      thrown in /home/<my_wp_path>/wp-content/plugins/klarna-payments-for-woocommerce/klarna-payments-for-woocommerce.php on line 141

    You should definitely add some verifications to know whether your needed prerequisites you rely on are installed and loaded or not…

    In fact, you added some verification in include_files function and simply return if class WC_Payment_Gateway doesn’t exist (which is the case if WooCommerce is not loaded at this exact moment). But when returning in such case (AND NOT CHECKING ANY RETURN VALUE) you have not loaded any file (and in particular class-kp-api.php) but want nonetheless to create a new KP_API instance… which crashes everything (NB: KP_Session is also concerned, of course…).

    A plugin should definitely not crash a website just like that! You should check whether include_files succeeded or failed.

    By the way, this may be the real reason to issues like this one or this one as WooCommerce may stealthily appear unloaded during upgrade…

    Could you add the needed verifications please ?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Plugin crashes website’ is closed to new replies.