<?php

/**
 * Sidespied functions and definitions
 *
 * @package sidespied
 */

/**
 * 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 espied_setup() {

	/*
	 * Make theme available for translation.
	 * Translations can be filed in the /languages/ directory.
	 * If you're building a theme based on Espied, use a find and replace
	 * to change 'espied' to the name of your theme in all the template files
	 */
	load_theme_textdomain( 'sidespied', get_template_directory() . '/languages' );

	load_theme_textdomain( 'espied', get_template_directory() . '/languages' );

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

	add_theme_support( 'custom-background', apply_filters( 'sidespied_custom_background_args', array(
		'default-color' => '28bea1',
		'default-image' => '',
	) ) );

	/*
	 * 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 http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
	 */
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 1280 );
	add_image_size( 'portfolio-landscape', 480, 360, true );
	add_image_size( 'portfolio-portrait', 480, 640, true );
	add_image_size( 'portfolio-square', 480, 480, true );

	// This theme uses wp_nav_menu() in two locations.
	register_nav_menus( array(
		'primary' => __( 'Primary Menu', 'espied' ),
		'social'  => __( 'Social Links Menu', 'espied' ),
	) );

	// Enable support for Post Formats.
	add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'gallery' ) );

	// Enable support for HTML5 markup.
	add_theme_support( 'html5', array(
		'comment-list',
		'search-form',
		'comment-form',
		'gallery',
	) );

	// Remove default gallery style from pre 3.9.
	add_filter( 'use_default_gallery_style', '__return_false' );

	/*
	 * This theme styles the visual editor to resemble the theme style,
	 * specifically font, colors, icons, and column width.
	 */
	add_editor_style( array( 'editor-style.css', 'fonts/genericons.css', sidespied_noto_font_url() ) );
}
add_action( 'after_setup_theme', 'espied_setup' );

/**
 * Register Noto Google fonts for Espied.
 *
 * @return string
 */
function sidespied_noto_font_url() {
	$noto_font_url = '';

	/* translators: If there are characters in your language that are not supported
	   by Noto, translate this to 'off'. Do not translate into your own language. */
	if ( 'off' !== _x( 'on', 'Noto font: on or off', 'sidespied' ) ) {

		$noto_font_url = add_query_arg( 'family', urlencode( 'Noto Sans:400,700,400italic,700italic' ), "https://fonts.googleapis.com/css" );
	}

	return $noto_font_url;
}


remove_action( 'wp_enqueue_scripts', 'espied_scripts' );
/**
 * Enqueue scripts and styles.
 */
function sidespied_scripts() {

	wp_enqueue_style( 'sidespied-noto', sidespied_noto_font_url(), array(), null );

	wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.0.3' );

	wp_enqueue_style( 'sidespied-parent-style', get_template_directory_uri() . '/style.css' );
	wp_enqueue_style( 'sidespied-style', get_stylesheet_uri() );

	wp_dequeue_style( 'espied-style' );

	wp_enqueue_script( 'espied-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	wp_enqueue_script( 'espied-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20140304', true );

}
add_action( 'wp_enqueue_scripts', 'sidespied_scripts', 99 );