<?php
/**
 * Healthcoach Framework: Theme options custom fields
 *
 * @package	healthcoach
 * @since	healthcoach 1.0
 */

// Disable direct call
if ( ! defined( 'ABSPATH' ) ) { exit; }


/* Theme setup section
-------------------------------------------------------------------- */

if ( !function_exists( 'healthcoach_options_custom_theme_setup' ) ) {
	add_action( 'healthcoach_action_before_init_theme', 'healthcoach_options_custom_theme_setup' );
	function healthcoach_options_custom_theme_setup() {

		if ( is_admin() ) {
			add_action("admin_enqueue_scripts",	'healthcoach_options_custom_load_scripts');
		}
		
	}
}

// Load required styles and scripts for custom options fields
if ( !function_exists( 'healthcoach_options_custom_load_scripts' ) ) {
	function healthcoach_options_custom_load_scripts() {
		wp_enqueue_script( 'healthcoach-options-custom-script',	healthcoach_get_file_url('core/core.options/js/core.options-custom.js'), array(), null, true );	
	}
}


// Show theme specific fields in Post (and Page) options
if ( !function_exists( 'healthcoach_show_custom_field' ) ) {
	function healthcoach_show_custom_field($id, $field, $value) {
		$output = '';
		switch ($field['type']) {
			case 'reviews':
				$output .= '<div class="reviews_block">' . trim(healthcoach_reviews_get_markup($field, $value, true)) . '</div>';
				break;
	
			case 'mediamanager':
				wp_enqueue_media( );
				$output .= '<a id="'.esc_attr($id).'" class="button mediamanager healthcoach_media_selector"
					data-param="' . esc_attr($id) . '"
					data-choose="'.esc_attr(isset($field['multiple']) && $field['multiple'] ? esc_html__( 'Choose Images', 'healthcoach') : esc_html__( 'Choose Image', 'healthcoach')).'"
					data-update="'.esc_attr(isset($field['multiple']) && $field['multiple'] ? esc_html__( 'Add to Gallery', 'healthcoach') : esc_html__( 'Choose Image', 'healthcoach')).'"
					data-multiple="'.esc_attr(isset($field['multiple']) && $field['multiple'] ? 'true' : 'false').'"
					data-linked-field="'.esc_attr($field['media_field_id']).'"
					>' . (isset($field['multiple']) && $field['multiple'] ? esc_html__( 'Choose Images', 'healthcoach') : esc_html__( 'Choose Image', 'healthcoach')) . '</a>';
				break;
		}
		return apply_filters('healthcoach_filter_show_custom_field', $output, $id, $field, $value);
	}
}
?>