<?php
/* Mail Chimp support functions
------------------------------------------------------------------------------- */

// Theme init
if (!function_exists('healthcoach_mailchimp_theme_setup')) {
	add_action( 'healthcoach_action_before_init_theme', 'healthcoach_mailchimp_theme_setup', 1 );
	add_action('healthcoach_action_add_styles', 				'healthcoach_mailchimp_frontend_scripts' );
	function healthcoach_mailchimp_theme_setup() {

		if (is_admin()) {
			add_filter( 'healthcoach_filter_importer_required_plugins',		'healthcoach_mailchimp_importer_required_plugins', 10, 2 );
			add_filter( 'healthcoach_filter_required_plugins',					'healthcoach_mailchimp_required_plugins' );
		}
	}
}

// Check if Instagram Feed installed and activated
if ( !function_exists( 'healthcoach_exists_mailchimp' ) ) {
	function healthcoach_exists_mailchimp() {
		return function_exists('mc4wp_load_plugin');
	}
}

// Filter to add in the required plugins list
if ( !function_exists( 'healthcoach_mailchimp_required_plugins' ) ) {
	
	function healthcoach_mailchimp_required_plugins($list=array()) {
		if (in_array('mailchimp', healthcoach_storage_get('required_plugins')))
			$list[] = array(
				'name' 		=> esc_html__('MailChimp for WP', 'healthcoach'),
				'slug' 		=> 'mailchimp-for-wp',
				'required' 	=> false
			);
		return $list;
	}
}


// Enqueue WooCommerce custom styles
if ( !function_exists( 'healthcoach_mailchimp_frontend_scripts' ) ) {
	function healthcoach_mailchimp_frontend_scripts() {
			if (file_exists(healthcoach_get_file_dir('css/plugin.mailchimp.css')))
				wp_enqueue_style( 'healthcoach-plugin-mailchimp-style',  healthcoach_get_file_url('css/plugin.mailchimp.css'), array(), null );
	}
}


// One-click import support
//------------------------------------------------------------------------

// Check Mail Chimp in the required plugins
if ( !function_exists( 'healthcoach_mailchimp_importer_required_plugins' ) ) {
	
	function healthcoach_mailchimp_importer_required_plugins($not_installed='', $list='') {
		if (healthcoach_strpos($list, 'mailchimp')!==false && !healthcoach_exists_mailchimp() )
			$not_installed .= '<br>' . esc_html__('Mail Chimp', 'healthcoach');
		return $not_installed;
	}
}
?>