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

// Theme init priorities:
// 9 - register other filters (for installer, etc.)
if ( ! function_exists( 'tourimo_instagram_feed_theme_setup9' ) ) {
	add_action( 'after_setup_theme', 'tourimo_instagram_feed_theme_setup9', 9 );
	function tourimo_instagram_feed_theme_setup9() {
		if ( tourimo_exists_instagram_feed() ) {
			add_action( 'wp_enqueue_scripts', 'tourimo_instagram_responsive_styles', 2000 );
			add_filter( 'tourimo_filter_merge_styles_responsive', 'tourimo_instagram_merge_styles_responsive' );
		}
		if ( is_admin() ) {
			add_filter( 'tourimo_filter_tgmpa_required_plugins', 'tourimo_instagram_feed_tgmpa_required_plugins' );
		}
	}
}

// Filter to add in the required plugins list
if ( ! function_exists( 'tourimo_instagram_feed_tgmpa_required_plugins' ) ) {
	
	function tourimo_instagram_feed_tgmpa_required_plugins( $list = array() ) {
		if ( tourimo_storage_isset( 'required_plugins', 'instagram-feed' ) && tourimo_storage_get_array( 'required_plugins', 'instagram-feed', 'install' ) !== false ) {
			$list[] = array(
				'name'     => tourimo_storage_get_array( 'required_plugins', 'instagram-feed', 'title' ),
				'slug'     => 'instagram-feed',
				'required' => false,
			);
		}
		return $list;
	}
}

// Check if Instagram Feed installed and activated
if ( ! function_exists( 'tourimo_exists_instagram_feed' ) ) {
	function tourimo_exists_instagram_feed() {
		return defined( 'SBIVER' );
	}
}

// Enqueue responsive styles for frontend
if ( ! function_exists( 'tourimo_instagram_responsive_styles' ) ) {
	
	function tourimo_instagram_responsive_styles() {
		if ( tourimo_is_on( tourimo_get_theme_option( 'debug_mode' ) ) ) {
			$tourimo_url = tourimo_get_file_url( 'plugins/instagram/instagram-responsive.css' );
			if ( '' != $tourimo_url ) {
				wp_enqueue_style( 'tourimo-instagram-responsive', $tourimo_url, array(), null );
			}
		}
	}
}

// Merge responsive styles
if ( ! function_exists( 'tourimo_instagram_merge_styles_responsive' ) ) {
	
	function tourimo_instagram_merge_styles_responsive( $list ) {
		$list[] = 'plugins/instagram/instagram-responsive.css';
		return $list;
	}
}

