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

// Theme init
if (!function_exists('writer_ancora_instagram_widget_theme_setup')) {
	add_action( 'writer_ancora_action_before_init_theme', 'writer_ancora_instagram_widget_theme_setup', 1 );
	function writer_ancora_instagram_widget_theme_setup() {
		if (writer_ancora_exists_instagram_widget()) {
			add_action( 'writer_ancora_action_add_styles', 						'writer_ancora_instagram_widget_frontend_scripts' );
		}
		if (is_admin()) {
			add_filter( 'writer_ancora_filter_required_plugins',					'writer_ancora_instagram_widget_required_plugins' );
		}
	}
}

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

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

// Enqueue custom styles
if ( !function_exists( 'writer_ancora_instagram_widget_frontend_scripts' ) ) {
	function writer_ancora_instagram_widget_frontend_scripts() {
		if (file_exists(writer_ancora_get_file_dir('css/plugin.instagram-widget.css')))
			wp_enqueue_style( 'writer-ancora-plugin-instagram-widget-style',  writer_ancora_get_file_url('css/plugin.instagram-widget.css'), array(), null );
	}
}
?>