<?php
/* Instagram Widget support functions
------------------------------------------------------------------------------- */

// Theme init
if (!function_exists('healthcoach_instagram_widget_theme_setup')) {
	add_action( 'healthcoach_action_before_init_theme', 'healthcoach_instagram_widget_theme_setup', 1 );
	function healthcoach_instagram_widget_theme_setup() {
		if (healthcoach_exists_instagram_widget()) {
			add_action( 'healthcoach_action_add_styles', 						'healthcoach_instagram_widget_frontend_scripts' );
		}
		if (is_admin()) {
			add_filter( 'healthcoach_filter_importer_required_plugins',		'healthcoach_instagram_widget_importer_required_plugins', 10, 2 );
			add_filter( 'healthcoach_filter_required_plugins',					'healthcoach_instagram_widget_required_plugins' );
		}
	}
}

// Check if Instagram Widget installed and activated
if ( !function_exists( 'healthcoach_exists_instagram_widget' ) ) {
	function healthcoach_exists_instagram_widget() {
		return function_exists('wpiw_init');
	}
}

// Filter to add in the required plugins list
if ( !function_exists( 'healthcoach_instagram_widget_required_plugins' ) ) {
	
	function healthcoach_instagram_widget_required_plugins($list=array()) {
		if (in_array('instagram_widget', healthcoach_storage_get('required_plugins')))
			$list[] = array(
					'name' 		=> esc_html__('Instagram Widget', 'healthcoach'),
					'slug' 		=> 'wp-instagram-widget',
					'required' 	=> false
				);
		return $list;
	}
}

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



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

// Check Instagram Widget in the required plugins
if ( !function_exists( 'healthcoach_instagram_widget_importer_required_plugins' ) ) {
	
	function healthcoach_instagram_widget_importer_required_plugins($not_installed='', $list='') {
		if (healthcoach_strpos($list, 'instagram_widget')!==false && !healthcoach_exists_instagram_widget() )
			$not_installed .= '<br>' . esc_html__('WP Instagram Widget', 'healthcoach');
		return $not_installed;
	}
}
?>