Title: Plugin crashes website
Last modified: June 26, 2023

---

# Plugin crashes website

 *  Resolved [madmax4ever](https://wordpress.org/support/users/madmax4ever/)
 * (@madmax4ever)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/plugin-crashes-website-5/)
 * 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:
 *     ```wp-block-code
       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](https://plugins.trac.wordpress.org/browser/klarna-payments-for-woocommerce/trunk/klarna-payments-for-woocommerce.php#L271)
   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](https://plugins.trac.wordpress.org/browser/klarna-payments-for-woocommerce/trunk/klarna-payments-for-woocommerce.php#L139))
   you have not loaded any file (and in particular [class-kp-api.php](https://plugins.trac.wordpress.org/browser/klarna-payments-for-woocommerce/trunk/klarna-payments-for-woocommerce.php#L287))
   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](https://wordpress.org/support/topic/error-plugin-23/)
   or [this one](https://wordpress.org/support/topic/class-kp_api-not-found/) as
   WooCommerce may stealthily appear unloaded during upgrade…
 * Could you add the needed verifications please ?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [louisekrokedil](https://wordpress.org/support/users/louisekrokedil/)
 * (@louisekrokedil)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/plugin-crashes-website-5/#post-16865603)
 * Hi,
   Thanks for great feedback, we have created a task for this internally and
   will fix this.
 *  Plugin Support [Andreas – Krokedil](https://wordpress.org/support/users/boozebrorsan/)
 * (@boozebrorsan)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/plugin-crashes-website-5/#post-17119403)
 * This should be fixed now in version 3.2.2

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Plugin crashes website’ is closed to new replies.

 * ![](https://ps.w.org/klarna-payments-for-woocommerce/assets/icon-256x256.png?
   rev=3174333)
 * [Klarna for WooCommerce](https://wordpress.org/plugins/klarna-payments-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/klarna-payments-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/klarna-payments-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/klarna-payments-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/klarna-payments-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/klarna-payments-for-woocommerce/reviews/)

 * 2 replies
 * 3 participants
 * Last reply from: [Andreas – Krokedil](https://wordpress.org/support/users/boozebrorsan/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/plugin-crashes-website-5/#post-17119403)
 * Status: resolved