Cannot redeclare class Stripe\Stripe

Description: when installing WP Full Pay results in a fatal error this article can help you resolve the issue.


What happened?

You are installing WP Full Pay, and Wordpress displays one of the following fatal errors:

“Fatal error: Cannot redeclare class Stripe\Stripe in /wp-content/plugins//classes/stripe/lib/Stripe.php on line 6”

“Fatal error: Another plugin has loaded an incompatible Stripe API client. Deactivate all other Stripe plugins, and try to activate Full Stripe again.”

Why is it happening?

WP Full Pay loads its own copy of the Stripe PHP client library, and another plugin tries to do the same, and PHP throws an error.

The error is the result of a fundamental flaw in WordPress’ design: there is no central management for PHP libraries used by several plugins.

How to solve?

There are cases when this issue can be resolved, in other cases there is no solution. It depends on the Stripe PHP client library versions required by the conflicting plugins, and on the loading order of the plugins.

You can resolve the issue (if possible) by taking the following steps:

  1. Find out the PHP client library required by WP Full Pay
  2. Find out the PHP client library required by the other plugin
  3. Determine the loading order of the conflicting plugins

1. Find out the PHP client library required by WP Full Pay

WP Full Pay defines the version number in the wp-full-stripe.php file in the root of the plugin directory, you just have to find the WP_FULL_STRIPE_API_VERSION constant in the file (see last line of the code snippet):


<?php
/*
Plugin Name: WP Full Stripe
Plugin URI: https://paymentsplugin.com
Description: Complete Stripe payments integration for Wordpress
Author: Mammothology
Version: 4.1.0
Author URI: https://paymentsplugin.com
Text Domain: wp-full-stripe
Domain Path: /languages
*/

define( 'WP_FULL_STRIPE_MIN_PHP_VERSION', '5.5.0' );
define( 'WP_FULL_STRIPE_MIN_WP_VERSION', '4.0.0' );
define( 'WP_FULL_STRIPE_STRIPE_API_VERSION', '6.27.0' );

2. Find out the PHP client library required by the other plugin

For the other plugins, the safest bet is to find the VERSION file in the Stripe PHP library directory.

3. Determine the loading order of the conflicting plugins

The loading order is determined by the alphabetical order of the plugin slugs.

Decision matrix based on your findings

Armed with the version numbers and loading order, consider the following cases:

  1. The other plugin is loaded first, and it requires an older Stripe version than WP Full Pay 

    In this case there is no solution. The oher plugin has to load the Stripe library, but it will be too old for WP Full Pay.

  2. The other plugin is loaded first, and it requires a newer Stripe version than WP Full Pay

    This might work, you have to comment out loading the Stripe library in the /wp-full-stripe.php file in the root folder of WP Full Pay (see next section).

  3. WP Full Pay is loaded first, and it requires an older Stripe version than the other Pay

    In this case there is no solution. WP Full Pay has to load the Stripe library, but it will be too old for the other plugin.

  4. WP Full Pay is loaded first, and it requires a newer Stripe version than the other plugin

    This might work, you have to comment out loading the Stripe library in the other plugin.

How not to load the Stripe PHP client library of WP Full Pay

You have to comment out the code which verifies the version number of the Stripe PHP library if it’s already loaded.

It’s in the wp-full-stripe.php file:

<?php
//Stripe PHP library
if ( ! class_exists( '\Stripe\Stripe' ) ) {
	require_once( dirname( __FILE__ ) . '/vendor/stripe/stripe-php/init.php' );
} else {
	if ( substr( \Stripe\Stripe::VERSION, 0, strpos( \Stripe\Stripe::VERSION, '.' ) ) != substr( WP_FULL_STRIPE_STRIPE_API_VERSION, 0, strpos( WP_FULL_STRIPE_STRIPE_API_VERSION, '.' ) ) ) {
		$reflector = new ReflectionClass( '\Stripe\Stripe' );
		wp_die( plugin_basename( __FILE__ ) . ': ' . __( 'Another plugin has loaded an incompatible Stripe API client. Deactivate all other Stripe plugins, and try to activate Full Stripe again.', 'wp-full-stripe' ) . ' ' . \Stripe\Stripe::VERSION . ' != ' . WP_FULL_STRIPE_STRIPE_API_VERSION . ', ' . $reflector->getFileName() );
	}
}

Comment out the statements in the “else” block:


<?php
//Stripe PHP library
if ( ! class_exists( '\Stripe\Stripe' ) ) {
	require_once( dirname( __FILE__ ) . '/vendor/stripe/stripe-php/init.php' );
} else {
  /*
	if ( substr( \Stripe\Stripe::VERSION, 0, strpos( \Stripe\Stripe::VERSION, '.' ) ) != substr( WP_FULL_STRIPE_STRIPE_API_VERSION, 0, strpos( WP_FULL_STRIPE_STRIPE_API_VERSION, '.' ) ) ) {
		$reflector = new ReflectionClass( '\Stripe\Stripe' );
		wp_die( plugin_basename( __FILE__ ) . ': ' . __( 'Another plugin has loaded an incompatible Stripe API client. Deactivate all other Stripe plugins, and try to activate Full Stripe again.', 'wp-full-stripe' ) . ' ' . \Stripe\Stripe::VERSION . ' != ' . WP_FULL_STRIPE_STRIPE_API_VERSION . ', ' . $reflector->getFileName() );
	}
  */
}

IMPORTANT: WP Full Pay installations using a Stripe PHP library versions other than the exact version required by the plugin are not supported by Mammothology.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us