Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "Constant WCCT_VERSION already defined" in WooCommerce Conversion Tracking plugin #57

Open
andersonnarciso opened this issue Dec 13, 2024 · 0 comments

Comments

@andersonnarciso
Copy link

andersonnarciso commented Dec 13, 2024

Hey guys! How are u?

I am encountering an error while using the WooCommerce Conversion Tracking plugin. The issue arises from the redefinition of the constant WCCT_VERSION, resulting in the following warning in the PHP error log:

[13-Dec-2024 15:09:41 UTC] PHP Warning: Constant WCCT_VERSION already defined in /nvme3/user/public_html/wp-content/plugins/woocommerce-conversion-tracking/conversion-tracking.php on line 153

The problem originates in the define_constants method, where multiple constants are defined without checking if they are already defined.

Location of the issue:
File: conversion-tracking.php
Method: define_constants

Current Code:

public function define_constants() {
define( 'WCCT_VERSION', $this->version );
define( 'WCCT_FILE', FILE );
define( 'WCCT_PATH', dirname( WCCT_FILE ) );
define( 'WCCT_INCLUDES', WCCT_PATH . '/includes' );
define( 'WCCT_URL', plugins_url( '', WCCT_FILE ) );
define( 'WCCT_ASSETS', WCCT_URL . '/assets' );
}

The constants are being redefined without verification, causing the error when the plugin or its components are loaded multiple times.

Proposed Solution:

Update the define_constants method to check if each constant is already defined before defining it. Here's a corrected version of the method:

public function define_constants() {
if ( ! defined( 'WCCT_VERSION' ) ) {
define( 'WCCT_VERSION', $this->version );
}

if ( ! defined( 'WCCT_FILE' ) ) {
    define( 'WCCT_FILE', __FILE__ );
}

if ( ! defined( 'WCCT_PATH' ) ) {
    define( 'WCCT_PATH', dirname( WCCT_FILE ) );
}

if ( ! defined( 'WCCT_INCLUDES' ) ) {
    define( 'WCCT_INCLUDES', WCCT_PATH . '/includes' );
}

if ( ! defined( 'WCCT_URL' ) ) {
    define( 'WCCT_URL', plugins_url( '', WCCT_FILE ) );
}

if ( ! defined( 'WCCT_ASSETS' ) ) {
    define( 'WCCT_ASSETS', WCCT_URL . '/assets' );
}

}

Steps to Reproduce the Issue:

Activate the WooCommerce Conversion Tracking plugin in WordPress.
Monitor the PHP error logs or enable debug mode (WP_DEBUG).
The error occurs whenever the define_constants method attempts to redefine constants that already exist.
Environment:

WordPress Version: 6.7.1
PHP Version: 8+
WooCommerce Conversion Tracking Version: 2.1.0
Active Theme: WoodMart

Impact:
The error does not break the plugin's core functionality but pollutes the error logs and may cause compatibility issues with other plugins or themes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant