<?php
/*
Plugin Name: ACF Forms
Description: Description
Plugin URI: http://#
Author: Author
Author URI: http://#
Version: 1.0
License: GPL2
Text Domain: Text Domain
Domain Path: Domain Path
*/
require_once(__DIR__ . '/inc/form.php');

add_action( 'wp_head', 'imark_form_recaptcha_js');
function imark_form_recaptcha_js() {
	echo '<script src="https://www.google.com/recaptcha/api.js?hl=iw"></script>';
}

add_filter('acf/validate_value/name=required', 'required_validate_value', 10, 4);
function required_validate_value( $valid, $value, $field, $input ){
	// bail early if value is already invalid
	if( !$valid ) {
		
		return $valid;
	}
	
	if ( $value == 'null' ) {
		$valid = 'יש לבחור ערך.';
	}
	
	
	// return
	return $valid;
}

add_filter('acf/validate_value/name=element_type', 'element_type_validate_value', 10, 4);
function element_type_validate_value( $valid, $value, $field, $input ){
	// bail early if value is already invalid
	if( !$valid ) {
		
		return $valid;
	}
	
	if ( $value == 'null' ) {
		$valid = 'יש לבחור ערך.';
	}
	
	
	// return
	return $valid;
}


if( ! class_exists('imark_admin_field_group') ) :

class imark_admin_field_group {
	
	
	/*
	*  __construct
	*
	*  This function will setup the class functionality
	*
	*  @type	function
	*  @date	5/03/2014
	*  @since	5.0.0
	*
	*  @param	n/a
	*  @return	n/a
	*/
	
	function __construct() {
		
		// actions
		add_action('init',                                               array($this, 'add_builder'));	
		
	}

	function add_builder() {
		$cap = acf_get_setting('capability');
		// register post type 'imark-forms'
		register_post_type('imark-forms', array(
			'labels'			=> array(
			    'name'					=> __( 'Form Builder', 'acf' ),
				'singular_name'			=> __( 'Form Builder', 'acf' ),
			    'add_new'				=> __( 'Add New' , 'acf' ),
			    'add_new_item'			=> __( 'Add New Field Group' , 'acf' ),
			    'edit_item'				=> __( 'Edit Field Group' , 'acf' ),
			    'new_item'				=> __( 'New Field Group' , 'acf' ),
			    'view_item'				=> __( 'View Field Group', 'acf' ),
			    'search_items'			=> __( 'Search Field Groups', 'acf' ),
			    'not_found'				=> __( 'No Field Groups found', 'acf' ),
			    'not_found_in_trash'	=> __( 'No Field Groups found in Trash', 'acf' ), 
			),
			'public'			=> false,
			'show_ui'			=> true,
			'_builtin'			=> false,
			'capability_type'	=> 'post',
			'capabilities'		=> array(
				'edit_post'			=> $cap,
				'delete_post'		=> $cap,
				'edit_posts'		=> $cap,
				'delete_posts'		=> $cap,
			),
			'hierarchical'		=> true,
			'rewrite'			=> false,
			'query_var'			=> false,
			'supports' 			=> array('title'),
			'show_in_menu'		=> true,
		));

	}
	
}

// initialize
new imark_admin_field_group();

endif;

?>
