Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions conversion-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ public function __construct() {

$this->define_constants();
$this->init_hooks();
$this->includes();
$this->init_classes();
// Defer heavy includes and class instantiation until WP 'init'
add_action( 'init', array( $this, 'includes' ), 10 );
add_action( 'init', array( $this, 'init_classes' ), 20 );

register_activation_hook( __FILE__, array( $this, 'activate' ) );
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

activate() never fires on plugin activation — register_activation_hook is now too late.

WordPress fires activate_{plugin_basename} during the activation request, immediately after loading the plugin file but before plugins_loaded. Since the constructor (and therefore register_activation_hook) is now deferred to plugins_loaded, the activation callback is never registered when the activate_ hook fires. activate() — which writes wcct_installed and wcct_version options — is silently skipped on every fresh install or re-activation.

Move register_activation_hook outside the constructor, to file scope where it executes at require-time:

🐛 Proposed fix

Remove it from the constructor:

  public function __construct() {
      require_once __DIR__ . '/vendor/autoload.php';

      $this->define_constants();
      $this->init_hooks();
      // Defer heavy includes and class instantiation until WP 'init'
      add_action( 'init', array( $this, 'includes' ), 10 );
      add_action( 'init', array( $this, 'init_classes' ), 20 );

-     register_activation_hook( __FILE__, array( $this, 'activate' ) );

      // Add High Performance Order Storage Support
      add_action( 'before_woocommerce_init', [ $this, 'declare_woocommerce_feature_compatibility' ] );

      do_action( 'wcct_loaded' );
  }

Register it at file scope, alongside the plugins_loaded hook:

  function wcct_init() {
      return WeDevs_WC_Conversion_Tracking::init();
  }

  // Instantiate plugin on 'plugins_loaded' to allow localization to be registered
  add_action( 'plugins_loaded', 'wcct_init' );
+ register_activation_hook( __FILE__, function() {
+     wcct_init()->activate();
+ } );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@conversion-tracking.php` at line 83, The register_activation_hook call is
being registered inside the class constructor (which runs on plugins_loaded), so
the activate() callback (which sets wcct_installed and wcct_version) is missed
during the activation request; move the register_activation_hook out of the
constructor to file scope so it runs at require-time (before plugins_loaded) and
binds activate() correctly, keeping the plugins_loaded add_action for normal
initialization inside the constructor.


Expand Down Expand Up @@ -191,7 +192,8 @@ public function init_hooks() {
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
add_action( 'admin_notices', array( $this, 'happy_addons_ads_banner' ) );

$this->init_tracker();
// Defer tracker initialization until after localization and integrations
add_action( 'init', array( $this, 'init_tracker' ), 30 );
}

/**
Expand Down Expand Up @@ -363,8 +365,8 @@ function wcct_init() {
return WeDevs_WC_Conversion_Tracking::init();
}

// WeDevs_WC_Conversion_Tracking
wcct_init();
// Instantiate plugin on 'plugins_loaded' to allow localization to be registered
add_action( 'plugins_loaded', 'wcct_init' );

/**
* Manage Capability
Expand Down