<?php
/* WPBakery PageBuilder support functions
------------------------------------------------------------------------------- */

// Theme init
if (!function_exists('healthcoach_vc_extensions_bundle_theme_setup')) {
	add_action( 'healthcoach_action_before_init_theme', 'healthcoach_vc_extensions_bundle_theme_setup', 1 );
	function healthcoach_vc_extensions_bundle_theme_setup() {
		if (is_admin()) {
			add_filter( 'healthcoach_filter_importer_required_plugins',		'healthcoach_vc_extensions_bundle_importer_required_plugins', 10, 2 );
			add_filter( 'healthcoach_filter_required_plugins',					'healthcoach_vc_extensions_bundle_required_plugins' );
		}
	}
}

// Check if WPBakery PageBuilder installed and activated
if ( !function_exists( 'healthcoach_exists_vc_extensions_bundle' ) ) {
	function healthcoach_exists_vc_extensions_bundle() {
		return class_exists('VC_Extensions_CQBundle');
	}
}

// Filter to add in the required plugins list
if ( !function_exists( 'healthcoach_vc_extensions_bundle_required_plugins' ) ) {
	
	function healthcoach_vc_extensions_bundle_required_plugins($list=array()) {
		if (in_array('vc_extensions_bundle', healthcoach_storage_get('required_plugins'))) {
			$path = healthcoach_get_file_dir('plugins/install/vc-extensions-bundle.zip');
			if (file_exists($path)) {
				$list[] = array(
					'name' 		=> 'WPBakery PageBuilder Extensions All In One',
					'slug' 		=> 'vc-extensions-bundle',
                    'version'	=> '3.5.4',
					'source'	=> $path,
					'required' 	=> false
				);
			}
		}
		return $list;
	}
}



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

// Check VC in the required plugins
if ( !function_exists( 'healthcoach_vc_extensions_bundle_importer_required_plugins' ) ) {
	
	function healthcoach_vc_extensions_bundle_importer_required_plugins($not_installed='', $list='') {
		
		if (!healthcoach_exists_vc_extensions_bundle() )		
			$not_installed .= '<br>WPBakery PageBuilder Extensions All In One';
		return $not_installed;
	}
}
?>