<?php
/**
* Theme functions and definitions
*/

/**
* Sets up theme defaults and registers support for various WordPress features.
*/
if ( ! function_exists( 'motivate_theme_setup' ) ):
function motivate_theme_setup() {
	
	/**
	* Make theme available for translation
	* Translations can be filed in the /languages/ directory
	*/
	load_theme_textdomain( 'motivate', get_template_directory() . '/languages' );

	/**
	* Add default posts and comments RSS feed links to head
	*/
	add_theme_support( 'automatic-feed-links' );
	
	/**
	* Enable support for Post Thumbnails
	*/
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 60, 60 );
	add_image_size( 'motivate-post', 980, '', true );
	add_image_size( 'motivate-post-big', 650, 325, true );
	add_image_size( 'motivate-post-square', 980, 980, true );
	add_image_size( 'motivate-mini-square', 300, 300, true );
	add_image_size( 'motivate-single', 1200, 600, true );
	add_image_size( 'motivate-post-mini', 230, 160, true );
	add_image_size( 'motivate-500', 500, 320, true );
	add_image_size( 'motivate-700', 700, '', true );
	add_image_size( 'motivate-hpblog', 300, 200, true );
	/**
	* Register menu locations
	*/
	register_nav_menus( array(
			'nav-site-header' => esc_html__( 'Site Header Menu', 'motivate' ),
			'nav-site-footer' => esc_html__( 'Site Footer Menu', 'motivate' ),
	));
	
	/*
	 * This theme styles the visual editor to resemble the theme style,
	 * specifically font, colors, and column width.
	 */
	add_editor_style( array( 'css/editor-style.css' ) );

  /*
   * 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 HTML5 markup
	add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ));

	// Add support for custom logo
	add_theme_support( 'custom-logo' );

	// Selective Refresh for Widgets
	add_theme_support( 'customize-selective-refresh-widgets' );

	// This theme uses its own gallery styles.
	add_filter( 'use_default_gallery_style', '__return_false' );	


	
}
endif;
add_action( 'after_setup_theme', 'motivate_theme_setup' );

/**
 * Set the content width based on the theme's design and stylesheet.
 *
 */
if ( ! isset( $content_width ) )
  $content_width = 592; 

/**
 * Enqueues styles for front-end.
 */
function motivate_theme_styles() {

	/*
	 * Loads our main stylesheet.
	 */
	wp_enqueue_style( 'at-theme-style', get_stylesheet_directory_uri() . '/css/style.css' );

}
add_action( 'wp_enqueue_scripts', 'motivate_theme_styles' );


/**
 * Enqueues scripts for front-end.
 */
 
function motivate_theme_scripts() {
	
	/*
	* Load our main theme JavaScript file
	*/
	wp_enqueue_script('motivate_theme_js', get_template_directory_uri() . '/js/js.js', array( 'jquery' ), false, true);
	
	/*
	* Adds JavaScript to pages with the comment form to support
	* sites with threaded comments (when in use).
	*/
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
			wp_enqueue_script( 'comment-reply' );
	}	
	
}
add_action('wp_enqueue_scripts', 'motivate_theme_scripts');

/**
 * Register widget area.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_sidebar
 */
function motivate_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar -- Blog', 'motivate' ),
		'id'            => 'sidebar-archive',
		'description'   => '',
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h4 class="widget__title"><span>',
		'after_title'   => '</span></h4>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar -- Post', 'motivate' ),
		'id'            => 'sidebar-post',
		'description'   => '',
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h4 class="widget__title"><span>',
		'after_title'   => '</span></h4>',
	) );
	

 // First footer widget area, located in the footer. Empty by default.
  register_sidebar( array(
      'name' => esc_html__( 'First Footer Widget Area', 'motivate' ),
      'id' => 'first-footer-widget-area',
      'description' => esc_html__( 'The first footer widget area', 'motivate' ),
      'before_widget' => '<div id="%1$s" class="at_widget %2$s">',
      'after_widget'  => '</div>',
      'before_title'  => '<h5 class="at_footer_title"> <span>',
      'after_title'   => '</span></h5>',
  ) );

  // Second Footer Widget Area, located in the footer. Empty by default.
  register_sidebar( array(
      'name' => esc_html__( 'Second Footer Widget Area', 'motivate' ),
      'id' => 'second-footer-widget-area',
      'description' => esc_html__( 'The second footer widget area', 'motivate' ),
      'before_widget' => '<div id="%1$s" class="at_widget %2$s">',
      'after_widget'  => '</div>',
      'before_title'  => '<h5 class="at_footer_title"> <span>',
      'after_title'   => '</span></h5>',
  ) );

  // Third Footer Widget Area, located in the footer. Empty by default.
  register_sidebar( array(
      'name' => esc_html__( 'Third Footer Widget Area', 'motivate' ),
      'id' => 'third-footer-widget-area',
      'description' => esc_html__( 'The third footer widget area', 'motivate' ),
      'before_widget' => '<div id="%1$s" class="at_widget %2$s">',
      'after_widget'  => '</div>',
      'before_title'  => '<h5 class="at_footer_title"> <span>',
      'after_title'   => '</span></h5>',
  ) );

  // Fourth Footer Widget Area, located in the footer. Empty by default.
  register_sidebar( array(
      'name' => esc_html__( 'Fourth Footer Widget Area', 'motivate' ),
      'id' => 'fourth-footer-widget-area',
      'description' => esc_html__( 'The fourth footer widget area', 'motivate' ),
      'before_widget' => '<div id="%1$s" class="at_widget %2$s">',
      'after_widget'  => '</div>',
      'before_title'  => '<h5 class="at_footer_title"> <span>',
      'after_title'   => '</span></h5>',
  ) );
}
add_action( 'widgets_init', 'motivate_widgets_init' );


/**
* Comment Functions
*/
require get_parent_theme_file_path("inc/comment-functions.php");


/**
* Customizer Functions
*/
require get_parent_theme_file_path("inc/customizer.php");

/**
* TGM Functions
*/
require get_parent_theme_file_path("inc/tgm.php");

/**
* Template Functions
*/
require get_parent_theme_file_path("inc/template-tags.php");

/**
* Widgets Functions
*/
require get_parent_theme_file_path("inc/widgets/widget-about.php");
require get_parent_theme_file_path("inc/widgets/widget-posts.php");
require get_parent_theme_file_path("inc/widgets/widget-social.php");
require get_parent_theme_file_path("inc/widgets/widget-banner.php");


/**
* Demo Importer
*/
require get_parent_theme_file_path("ocdi/demo-importer.php");



// Change default widget tag cloud settings
add_filter('widget_tag_cloud_args','motivate_set_tag_cloud_args');
function motivate_set_tag_cloud_args($args) {
	$args['largest'] = 17;
	$args['smallest'] = 11;
	$args['unit'] = 'px';
	return $args;
}


/**
 * Modify default excerpt length
 */
function motivate_excerpt_length( $length ) {
	return 30;
}
add_filter( 'excerpt_length', 'motivate_excerpt_length', 999 );

function motivate_excerpt_more( $more ) {
	return '...';
}
add_filter('excerpt_more', 'motivate_excerpt_more');


//Remove Icegram welcome scren

function motivate_remove_icegram_welcome() {
	global $Icegram;
remove_action( 'admin_init', array( $Icegram, 'welcome' ) );
}
add_action( 'plugins_loaded', 'motivate_remove_icegram_welcome', 1 );
