<?php
/* Contact Form 7 support functions
------------------------------------------------------------------------------- */

// Theme init
if (!function_exists('healthcoach_contact_form_7_theme_setup')) {
    add_action( 'healthcoach_action_before_init_theme', 'healthcoach_contact_form_7_theme_setup', 1 );
    function healthcoach_contact_form_7_theme_setup() {
        if (healthcoach_exists_contact_form_7()) {
            add_action( 'healthcoach_action_add_styles', 	'healthcoach_contact_form_7_frontend_scripts' );
        }
        if (is_admin()) {
            add_filter( 'healthcoach_filter_required_plugins', 'healthcoach_contact_form_7_required_plugins' );
        }
    }
}

// Check if Instagram Widget installed and activated
if ( !function_exists( 'healthcoach_exists_contact_form_7' ) ) {
    function healthcoach_exists_contact_form_7() {
        return class_exists('WPCF7');
    }
}

// Filter to add in the required plugins list
if ( !function_exists( 'healthcoach_contact_form_7_required_plugins' ) ) {

    function healthcoach_contact_form_7_required_plugins($list=array()) {
        if (in_array('contact-form-7', (array)healthcoach_storage_get('required_plugins')))
            $list[] = array(
                'name'         => esc_html__('Contact Form 7', 'healthcoach'),
                'slug'         => 'contact-form-7',
                'required'     => false
            );
        return $list;
    }
}

// Enqueue custom styles
if ( !function_exists( 'healthcoach_contact_form_7_frontend_scripts' ) ) {
    
    function healthcoach_contact_form_7_frontend_scripts() {
        if (file_exists(healthcoach_get_file_dir('css/plugin.contact-form-7.css')))
            wp_enqueue_style( 'healthcoach-plugin-contact-form-7',  healthcoach_get_file_url('css/plugin.contact-form-7.css'), array(), null );
    }
}
?>
