<?php
/* Essential Grid support functions
------------------------------------------------------------------------------- */

// Theme init
if (!function_exists('healthcoach_essgrids_theme_setup')) {
	add_action( 'healthcoach_action_before_init_theme', 'healthcoach_essgrids_theme_setup', 1 );
	function healthcoach_essgrids_theme_setup() {
		// Register shortcode in the shortcodes list

		if (is_admin()) {
			add_filter( 'healthcoach_filter_importer_required_plugins',	'healthcoach_essgrids_importer_required_plugins', 10, 2 );
			add_filter( 'healthcoach_filter_required_plugins',				'healthcoach_essgrids_required_plugins' );
		}
	}
}


// Check if Ess. Grid installed and activated
if ( !function_exists( 'healthcoach_exists_essgrids' ) ) {
	function healthcoach_exists_essgrids() {
		return defined('EG_PLUGIN_PATH');
	}
}

// Filter to add in the required plugins list
if ( !function_exists( 'healthcoach_essgrids_required_plugins' ) ) {
	
	function healthcoach_essgrids_required_plugins($list=array()) {
		if (in_array('essgrids', healthcoach_storage_get('required_plugins'))) {
			$path = healthcoach_get_file_dir('plugins/install/essential-grid.zip');
			if (file_exists($path)) {
				$list[] = array(
					'name' 		=> esc_html__('Essential Grid', 'healthcoach'),
					'slug' 		=> 'essential-grid',
                    'version'	=> '2.3.6',
					'source'	=> $path,
					'required' 	=> false
					);
			}
		}
		return $list;
	}
}



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

// Check in the required plugins
if ( !function_exists( 'healthcoach_essgrids_importer_required_plugins' ) ) {
	
	function healthcoach_essgrids_importer_required_plugins($not_installed='', $list='') {
		if (healthcoach_strpos($list, 'essgrids')!==false && !healthcoach_exists_essgrids() )
			$not_installed .= '<br>'.esc_html__('Essential Grids', 'healthcoach');
		return $not_installed;
	}
}
?>