• Resolved MaryMak

    (@maxms)


    Hello,

    I am using Braintree for WooCommerce plugin as well as another for paid memberships. When they are both loaded, neither checks to see whether it is already loaded and so it results in a fatal error because the function is being declared twice.

    Wondering if it is possible to enclose the require_once function in an if statement?

    if ( ! function_exists( 'requireDependencies' ) ) {
          	require_once( '../lib/Braintree.php' );
          }

    Here is the error:

    Fatal error: Cannot declare class Braintree, because the name is already in use in /home/customer/www/hearthandstonelht.com/public_html/wp-content/plugins/restrict-content-pro/includes/libraries/braintree/lib/Braintree.php on line 13

    Please advise on an update or interim fix. Thank you!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Payment Plugins

    (@mrclayton)

    Hi @maxms,

    Are you using a very old version of the plugin? Our plugin does not use a function called requireDependencies.

    Here is the code as of the most recent version (it’s been like this for 2 years though)

    if ( ! function_exists( 'requireBraintreeProDependencies' ) ) {
    
    	function requireBraintreeProDependencies()
    	{
    		$requiredExtensions = array (
    				'xmlwriter', 
    				'openssl', 
    				'dom', 
    				'hash', 
    				'curl' 
    		);
    		foreach ( $requiredExtensions as $ext ) {
    			if ( ! extension_loaded( $ext ) ) {
    				throw new Braintree_Exception( 'The Braintree library requires the ' . $ext . ' extension.' );
    			}
    		}
    	}
    }

    Your error message says the following: atal error: Cannot declare class Braintree,

    Can you please provide the content of the restrict-content-pro/includes/libraries/braintree/lib/Braintree.php file?

    Thanks,

    Thread Starter MaryMak

    (@maxms)

    Hello,

    The “requireDependencies” function was just an example of a suggested fix but it looks like you already have something like that in place. Here is the RCP code:

    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php');
    
    if (version_compare(PHP_VERSION, '5.4.0', '<')) {
        throw new Braintree_Exception('PHP version >= 5.4.0 required');
    }
    
    class Braintree {
        public static function requireDependencies() {
            $requiredExtensions = ['xmlwriter', 'openssl', 'dom', 'hash', 'curl'];
            foreach ($requiredExtensions AS $ext) {
                if (!extension_loaded($ext)) {
                    throw new Braintree_Exception('The Braintree library requires the ' . $ext . ' extension.');
                }
            }
        }
    }
    
    Braintree::requireDependencies();
    

    Thank you!

    Plugin Author Payment Plugins

    (@mrclayton)

    @maxms,

    Our plugin doesn’t have a class just called “Braintree.” Can you please provide the entire error message? It should contain the location of where the exception was thrown.

    Kind Regards,

    Thread Starter MaryMak

    (@maxms)

    CRITICAL Cannot declare class Braintree, because the name is already in use in /home/customer/www/hearthandstonelht.com/public_html/wp-content/plugins/restrict-content-pro/includes/libraries/braintree/lib/Braintree.php on line 13

    I’ve got RCP looking at it too. It may be on their end. WooCommerce is working fine when Braintree is not enabled for RCP. I will let you know what they say.

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Braintree Fatal error plugin conflict’ is closed to new replies.