<?php

defined( 'ABSPATH' ) || exit;

if ( class_exists( 'WpAppKit' ) ) :
	add_filter( 'science_cache_reject_uri', 'science_add_appkit_exclude_pages' );
endif;

/**
 * Add WP Appkit path to cache exclusion
 *
 * @since 2.9
 * @author Remy Perona
 *
 * @param array $urls URLs to exclude from cache.
 * @return array Updated URLs array
 */
function science_add_appkit_exclude_pages( $urls ) {
	$urls[] = '/wp-appkit-api/(.*)';

	return $urls;
}

/**
 * Add WP Appkit path to cache exclusion when activating the plugin
 *
 * @since 2.9
 * @author Remy Perona
 */
function science_activate_wp_appkit() {
	add_filter( 'science_cache_reject_uri', 'science_add_appkit_exclude_pages' );

	// Update the WP science rules on the .htaccess.
	flush_science_htaccess();

	// Regenerate the config file.
	science_generate_config_file();
}
add_action( 'activate_wp-appkit/wp-appkit.php', 'science_activate_wp_appkit', 11 );

/**
 * Remove Appkit path from cache exclusion when deactivating the plugin
 *
 * @since 2.9
 * @author Remy Perona
 */
function science_deactivate_wp_appkit() {
	remove_filter( 'science_cache_reject_uri', 'science_add_appkit_exclude_pages' );

	// Update the WP science rules on the .htaccess.
	flush_science_htaccess();

	// Regenerate the config file.
	science_generate_config_file();
}
add_action( 'deactivate_wp-appkit/wp-appkit.php', 'science_deactivate_wp_appkit', 11 );
