<?php

namespace ProudNerds\Plugins;

use ProudNerds\Trait\Initializable;

/**
 * Nelio AB Testing Helper class
 * This class allows Nelio AB Testing to work with our theme.
 *
 * It provides a hook that disables the use of the control ID in the alternative.
 * This is needed because Nelio AB Testing uses the control ID to determine if the alternative is the same as the control. // NOSONAR
 *
 * The class is based on code located in public/content/plugins/nelio-ab-testing/includes/hooks/compat/divi/load.php which // NOSONAR
 * requires the same updates to work with our theme.
 */
class NelioABTesting
{
    use Initializable;

    private function __construct()
    {
        if (!is_plugin_active('nelio-ab-testing/nelio-ab-testing.php')) {
            return;
        }

        // We use after_theme_setup which is the first hook we can use after this theme is loaded and runs before any templating. // NOSONAR
        add_action('after_setup_theme', [$this, 'pluginsLoaded']);
    }

    /**
     * Add hooks to the Nelio AB Testing plugin.
     */
    public function pluginsLoaded()
    {
        add_filter('nab_use_control_id_in_alternative', '__return_false');
    }
}
