<?php
/**
 * growup functions and definitions
 *
 * @package growup
 */

if ( ! function_exists( 'growup_setup' ) ) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function growup_theme_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on growup, use a find and replace
		 * to change 'growup' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'growup', get_template_directory() . '/languages' );

		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support( 'title-tag' );

		/*
		 * Enable support for Post Thumbnails on posts and pages.
		 *
		 * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		 */
		add_theme_support( 'post-thumbnails' );
		add_image_size( 'growup_image', 350,260, true );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'menu-1' => esc_html__( 'Primary', 'growup' ),
		) );

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		add_theme_support( 'html5', array(
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		) );

		// Set up the WordPress core custom background feature.
		add_theme_support( 'custom-background', apply_filters( 'growup_custom_background_args', array(
			'default-color' => '#22262C',
			'default-image' => get_template_directory_uri().'/img/bg.jpeg',
		) ) );
		// Heading Image Size
		  add_theme_support( 'custom-header', apply_filters( 'growup_custom_header_args', array(
				'width'                  => 1200,
				'height'                 => 240,
				'flex-height'            => true,
			) ) );	
			
		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support( 'custom-logo', array('height'=> 250,'width'=> 250,'flex-width'  => true,	'flex-height' => true,) );
	}
	add_editor_style( array( 'css/editor-style.css', growup_google_fonts_url() ) );
endif;
add_action( 'after_setup_theme', 'growup_theme_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $content_width
 */
function growup_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'growup_content_width', 640 );
}
add_action( 'after_setup_theme', 'growup_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function growup_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar', 'growup' ),
		'id'            => 'sidebar-1',
		'description'   => esc_html__( 'Add widgets here.', 'growup' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footercol1', 'growup' ),
		'id'            => 'footer-1',
		'description'   => esc_html__( 'Frist Footer section widgets.', 'growup' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footercol2', 'growup' ),
		'id'            => 'footer-2',
		'description'   => esc_html__( 'Second Footer section widgets.', 'growup' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );   
	register_sidebar( array(
		'name'          => esc_html__( 'Footercol3', 'growup' ),
		'id'            => 'footer-3',
		'description'   => esc_html__( 'Third Footer section widgets.', 'growup' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );    
        
}
add_action( 'widgets_init', 'growup_widgets_init' );


/**
 * Register Google Fonts
 */
function growup_google_fonts_url() {
	$fonts_url = '';    
	$font_families[] = 'Lato:200,300,300i,400,400i,500,600,700';	 
	$font_families[] = 'Open+Sans:400italic,700italic,400,700';	 
	$font_families[] = 'Roboto:400italic,700italic,400,700';	 
	$query_args = array(
	'family' => urlencode( implode( '|', $font_families ) ),
	'subset' => urlencode( 'latin,latin-ext' ),
	);        
                
	$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
	return esc_url_raw( $fonts_url );	
}

/**** Enqueue scripts and styles. **********/
function growup_scripts() {
	//Css Files
	wp_enqueue_style( 'growup-google-fonts', growup_google_fonts_url(), array(), null );
	wp_enqueue_style('bootstrap' , get_template_directory_uri(). '/css/bootstrap.min.css');
	wp_enqueue_style('font-awesome' , get_template_directory_uri(). '/css/font-awesome.css');
	wp_enqueue_style('meanmenu' , get_template_directory_uri(). '/css/meanmenu.css');
	wp_enqueue_style('growup-style', get_stylesheet_uri() );
	wp_enqueue_style('growup-slider' , get_template_directory_uri(). '/css/slider-style.css');
    
    //JS files
	wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '6857', true );
	wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.bundle.min.js', array('jquery'), '6857', true );
	wp_enqueue_script( 'jquery-meanmenu', get_template_directory_uri() . '/js/jquery.meanmenu.js', array('jquery'), '6857', true );
	wp_enqueue_script( 'growup-main', get_template_directory_uri() . '/js/main.js', array('jquery'), '6857', true );
	
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'growup_scripts' );

// modify search widget
function growup_my_search_form( $form ) {
	$form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url(home_url( '/' )) . '" >
				<div class="input-group">
					<input type="text" value="' . get_search_query() . '" name="s" id="s" class="form-control search_field" placeholder="' . esc_attr__('Search...' , 'growup') .'">
					<span class="input-group-btn">
						<button class="btn btn-default search_btn" type="submit"><i class="fa fa-search"></i></button>
					</span>
				</div>
			</form>';
	return $form;
}
add_filter( 'get_search_form', 'growup_my_search_form' );


// comment box title change
add_filter( 'comment_form_defaults', 'growup_remove_comment_form_allowed_tags' );

function growup_remove_comment_form_allowed_tags( $defaults ) {

	$defaults['comment_notes_after'] = '';
	$defaults['comment_notes_before'] = '';
	return $defaults;
}

function growup_comment_reform ($arg) {

	$arg['title_reply'] = esc_html__('Write your comment Here','growup');
	$arg['comment_field'] = '<div class="row"><div class="form-group col-md-12"><textarea id="comment" class="comment_field form-control" name="comment" cols="77" rows="3" placeholder="'. esc_attr__("Write your Comment", "growup").'" aria-required="true"></textarea></div></div>';
	return $arg;

}

add_filter('comment_form_defaults','growup_comment_reform');


// comment form modify
function growup_modify_comment_form_fields($fields){
	$commenter = wp_get_current_commenter();
	$req	   = get_option( 'require_name_email' );

	$fields['author'] = '<div class="row"><div class="form-group col-md-4"><input type="text" name="author" id="author" value="'. esc_attr( $commenter['comment_author'] ) .'" placeholder="'. esc_attr__("Your Name *", "growup").'" size="22" tabindex="1"'. ( $req ? 'aria-required="true"' : '' ).' class="input-name form-control" /></div>';
	$fields['email'] = '<div class="form-group col-md-4"><input type="text" name="email" id="email" value="'. esc_attr( $commenter['comment_author_email'] ) .'" placeholder="'.esc_attr__("Your Email *", "growup").'" size="22" tabindex="2"'. ( $req ? 'aria-required="true"' : '' ).' class="input-email form-control"  /></div>';	
	$fields['url'] = '<div class="form-group col-md-4"><input type="text" name="url" id="url" value="'. esc_attr( $commenter['comment_author_url'] ) .'" placeholder="'. esc_attr__("Website", "growup").'" size="22" tabindex="2"'. ( $req ? 'aria-required="false"' : '' ).' class="input-url form-control"  /></div></div>';

	return $fields;
}

add_filter('comment_form_default_fields','growup_modify_comment_form_fields');


/***** Custom template tags for this theme. ********/
require get_template_directory() . '/inc/template-tags.php';

/*** Functions which enhance the theme by hooking into WordPress. ******/
require get_template_directory() . '/inc/template-functions.php';

/*** Customizer additions */
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/custom-functions.php';

/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}
