<?php

// Load stylesheets

function load_stylesheets() /*load stylesheet, main and style.css*/
{
	wp_register_style('main', get_template_directory_uri() . '/css/main.css', array(), rand(111,9999), 'all');
	wp_enqueue_style('main');

	wp_register_style('mainswiper', get_template_directory_uri() . '/css/swiper-bundle.min.css', array(), rand(111,9999), 'all');
	wp_enqueue_style('mainswiper');

	wp_register_style('style', get_template_directory_uri() . '/style.css', array(), rand(111,9999), 'all');
	wp_enqueue_style('style');
	
}
add_action('wp_enqueue_scripts', 'load_stylesheets');

// Load javascript

function loadjs()  /*load custom JS*/
{
	wp_register_script('customjs', get_template_directory_uri() . '/js/scripts.js', '', 1, true);
	wp_enqueue_script('customjs');
	
	wp_register_script('customjsswiper', get_template_directory_uri() . '/js/swiper-bundle.min.js', '', true);
	wp_enqueue_script('customjsswiper');
	
}
add_action('wp_enqueue_scripts', 'loadjs');



////////// Theme Options ////////// 


add_theme_support('menus'); /* load menu WP function*/
add_theme_support('post-thumbnails'); /* load thumbnails WP function*/
add_theme_support('widgets');

// Register menu locations

register_nav_menus( 
	array(
		'header-menu' => __('Header Menu', 'theme'),
		'mobile-menu' => __('Mobile Menu', 'theme'),
		'footer-menu' => __('Footer Menu', 'theme'),
		'lang-menu' => __('Language Menu', 'theme'),
	)
);

// Image dimensions

add_image_size('smallest', 300, 300, true); /*add image sizes*/
add_image_size('largest', 800, 800, true); /*add image sizes*/

// Register sidebars

function my_sidebars(){
	register_sidebar(
		array(
			'name' => 'Page Sidebar', 
			'id' => 'page-sidebar',
			'before_title' => '<h4 class="widget-title">',
			'after_title' => '</h4>'
		)
	);
	
	register_sidebar(
		array(
			'name' => 'Blog Sidebar', 
			'id' => 'blog-sidebar',
			'before_title' => '<h4 class="widget-title">',
			'after_title' => '</h4>'
		)
	);
}
add_action('widgets_init', 'my_sidebars');

// Register Usluge Slider

function uslider(){

	$args = array(
		
		'labels' => array(
			'name' => 'Usluge Slider',
		),
		'public' => true,
		'has_archive' => false,
		'publicly_queryable'  => false,
		'menu_icon' => 'dashicons-slides',
		'supports' => array('title'),
		'rewrite' => array('slug' => 'uslider'),
	);

	register_post_type('uslider', $args);


}
add_action('init', 'uslider');


// disable toolbar for all except admins

add_action('after_setup_theme', 'remove_admin_bar');
 
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
  show_admin_bar(false);
}
}

// add user tole to body class

function get_user_role() {
    global $current_user;
    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);
    return $user_role;
}

/* bypass wordpress are you sure you want to logout screen when logging out of an already logged out account. */ 
function smart_logout() { 
	if (!is_user_logged_in()) { 
		$smart_redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '/'; 
		wp_safe_redirect( $smart_redirect_to ); 
		exit(); 
	} else { 
		check_admin_referer('log-out'); 
		wp_logout(); 
		$smart_redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '/'; 
		wp_safe_redirect( $smart_redirect_to ); 
		exit(); 
	} 
} 
add_action ( 'login_form_logout' , 'smart_logout' );

// excerpt length

function wpdocs_custom_excerpt_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );

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


function currentYear(){
	return date('Y');
}

