<?php

defined( 'ABSPATH' ) || exit;

/**
 * Compatibility with WeePie Cookie Allow
 *
 * @since 2.9
 */
if ( class_exists( 'WpieCookieAllow' ) ) :
	add_action( 'update_option_wpca_settings_general', 'science_after_update_wp_cookie_allow_options', 10, 2 );
	add_action( 'update_option_wpca_settings_style', 'science_after_update_wp_cookie_allow_options', 10, 2 );
	add_action( 'update_option_wpca_settings_content', 'science_after_update_wp_cookie_allow_options', 10, 2 );
	add_action( 'update_option_wpca_settings_consent_log', 'science_after_update_wp_cookie_allow_options', 10, 2 );
endif;

/**
 * Update .htaccess & config files when the "Enabled" and "Autoblock" options are turned on.
 *
 * @since 2.9
 * @author Remy Perona
 *
 * @param array $old_value Previous values for the plugin options.
 * @param array $value New values for the plugin options.
 */
function science_after_update_wp_cookie_allow_options( $old_value, $value ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
	// clear the cache because WeePie Cookie Allow plugin settings might have been changed.
	science_clean_domain();
}

/**
 * Add cookies when we activate the plugin.
 *
 * @since 2.9
 * @author Remy Perona
 */
function science_activate_wp_cookie_allow() {
	// clear the cache because plugin might be enabled already before.
	science_clean_domain();
}
add_action( 'activate_wp-cookie-allow/wp-cookie-allow.php', 'science_activate_wp_cookie_allow', 11 );

/**
 * Remove cookies when we deactivate the plugin
 *
 * @since 2.9
 * @author Remy Perona
 */
function science_deactivate_wp_cookie_allow() {
	// clear the cache because the bar/box and other WeePie Cookie Allow plugin frontend HTML is not needed anymore.
	science_clean_domain();
}
add_action( 'deactivate_wp-cookie-allow/wp-cookie-allow.php', 'science_deactivate_wp_cookie_allow', 11 );
