<?php
/* 	D5 CORPORATE Theme's Functions
	Copyright: 2012-2017, D5 Creation, www.d5creation.com
	Based on the Simplest D5 Framework for WordPress
	Since D5 CORPORATE 1.0
*/   

	require_once ( trailingslashit(get_template_directory()) . 'inc/customize.php' );
	
	function d5corporate_about_page() { 	
	add_theme_page( 'CORPORATE Options', 'CORPORATE Options', 'edit_theme_options', 'theme-about', 'd5corporate_theme_about' ); 
	}
	add_action('admin_menu', 'd5corporate_about_page');
	function d5corporate_theme_about() {  require_once ( trailingslashit(get_template_directory()) . 'inc/theme-about.php' ); }
	
	function d5corporate_setup() {
	add_theme_support( 'title-tag' );
	add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'script', 'style', ));
	load_theme_textdomain( 'd5-corporate-lite', get_template_directory() . '/languages' );	
	add_theme_support( 'automatic-feed-links' );
  	register_nav_menus( array( 'main-menu' => __('Main Menu', 'd5-corporate-lite'),  	'top-menu' => __('Top Menu', 'd5-corporate-lite') ) );


	global $content_width;
	if ( ! isset( $content_width ) ) $content_width = 584;
	add_editor_style();
		
// 	This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
	
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 150, 150, true ); // default Post Thumbnail dimensions (cropped)
		
// 	WordPress Custom Background Support	
	$d5corporate_custom_background = array(
	'default-color'          => '',
	'default-image'          => '',
	);
	add_theme_support( 'custom-background', $d5corporate_custom_background );
	
// 	WordPress Custom Header Support				
	$d5corporate_custom_header = array(
	'default-image'          => '', //get_template_directory_uri() . '/images/logo.png',
	'random-default'         => false,
	'width'                  => 300,
	'height'                 => 90,
	'flex-height'            => false,
	'flex-width'             => false,
	'default-text-color'     => '000000',
	'header-text'            => false,
	'uploads'                => true,
	'wp-head-callback' 		 => '',
	'admin-head-callback'    => '',
	'admin-preview-callback' => '',
	);
	add_theme_support( 'custom-header', $d5corporate_custom_header );
	
	}
	add_action( 'after_setup_theme', 'd5corporate_setup' );

// 	Functions for adding script
	function d5corporate_enqueue_scripts() { 
	wp_enqueue_style('d5corporate-style', get_stylesheet_uri(), false );
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); }
	wp_enqueue_script( 'd5corporate-menu-style', get_template_directory_uri(). '/js/menu.js',  array( 'jquery' ) );
	wp_enqueue_style('d5corporate-gfonts1', '//fonts.googleapis.com/css?family=Oswald', false );
		
	wp_enqueue_script( 'd5corporate-html5', get_template_directory_uri().'/js/html5.min.js'); 
    wp_script_add_data( 'd5corporate-html5', 'conditional', 'lt IE 9' );	
		
	if ( d5corporate_get_option('responsive', '1')) wp_enqueue_style('d5corporate-responsive', get_template_directory_uri(). '/style-responsive.css' );
	
	}
	add_action( 'wp_enqueue_scripts', 'd5corporate_enqueue_scripts' );
	
// 	Functions for adding script to Admin Area
	function d5corporate_admin_style() { wp_enqueue_style( 'd5corporate_admin_css', get_template_directory_uri() . '/inc/admin-style.css', false ); }
	add_action( 'admin_enqueue_scripts', 'd5corporate_admin_style' );

/**
 * Generate the Continue Reading link.
 */
function d5corporate_continue_reading_link() {
    return '<a href="' . esc_url( get_permalink() ) . '" class="read-more">'
        . esc_html__( 'Read the Rest...', 'd5-corporate-lite' ) .
        '</a>';
}

/**
 * Replace the default [...] with an ellipsis + Continue Reading link
 * for automatic excerpts ONLY.
 */
function d5corporate_excerpt_more( $more ) {
    return '... ' . d5corporate_continue_reading_link();
}
add_filter( 'excerpt_more', 'd5corporate_excerpt_more' );


/**
 * Append Continue Reading link to manual excerpts ONLY.
 */
function d5corporate_custom_excerpt_more( $excerpt ) {
    if ( has_excerpt() && ! is_attachment() ) {
        // Avoid double-adding if theme or plugin already appended it
        if ( strpos( $excerpt, 'read-more' ) === false ) {
            $excerpt .= ' ' . d5corporate_continue_reading_link();
        }
    }
    return $excerpt;
}
add_filter( 'get_the_excerpt', 'd5corporate_custom_excerpt_more' );


/**
 * Output content respecting WordPress feed settings.
 */
function d5corporate_content() {

    // Respect WordPress feed setting
    if ( is_feed() ) {
        if ( get_option( 'rss_use_excerpt' ) ) {
            the_excerpt();
        } else {
            the_content();
        }
        return;
    }

    // Normal theme behavior for posts/pages
    // Do NOT add "Read More" here for excerpts — only for full content
    the_content(
        '<span class="read-more">' .
        esc_html__( 'Read More...', 'd5-corporate-lite' ) .
        '</span>'
    );
}

//	D5 CORPORATE and WordPress Credit
	function d5corporate_credit() {
		echo '&nbsp;| D5 CORPORATE LITE Theme by: <a href="'.esc_url('https://d5creation.com').'" target="_blank">D5 Creation</a> | Powered by: <a href="http://wordpress.org" target="_blank">WordPress</a>';
	}


//	Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link
	function d5corporate_page_menu_args( $args ) {
	$args['show_home'] = true;
	return $args;
	}
	add_filter( 'wp_page_menu_args', 'd5corporate_page_menu_args' );


//	Registers the Widgets and Sidebars for the site
	function d5corporate_widgets_init() {

	register_sidebar( array(
		'name' =>  __('Primary Sidebar', 'd5-corporate-lite'),  
		'id' => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => "</aside>",
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );

	register_sidebar( array(
		'name' =>  __('Secondary Sidebar', 'd5-corporate-lite'),  
		'id' => 'sidebar-2',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => "</aside>",
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );

	register_sidebar( array(
		'name' =>  __( 'Footer Area One', 'd5-corporate-lite'), 
		'id' => 'sidebar-3',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => "</aside>",
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );

	register_sidebar( array(
		'name' =>  __( 'Footer Area Two', 'd5-corporate-lite'), 
		'id' => 'sidebar-4',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => "</aside>",
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );

	register_sidebar( array(
		'name' =>  __( 'Footer Area Three', 'd5-corporate-lite'), 
		'id' => 'sidebar-5',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => "</aside>",
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	
	register_sidebar( array(
		'name' =>  __( 'Footer Area Four', 'd5-corporate-lite'), 
		'id' => 'sidebar-6',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => "</aside>",
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	}
	add_action( 'widgets_init', 'd5corporate_widgets_init' );
	
	add_filter('the_title', 'd5corporate_title');
	function d5corporate_title($title) {
        if ( '' == $title ) {
            return '(Untitled)';
        } else {
            return $title;
        }
    }