<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/*
 * Theme actions
 */
add_action( 'after_setup_theme',			'custom_theme_setup' );
add_action( 'widgets_init',					'custom_theme_widgets_init' );
add_action( 'wp_enqueue_scripts',			'custom_theme_scripts',	10 );
// add custom post types and custom taxonomies
add_action( 'init', 						'custom_post_types', 0 );
add_filter( 'get_search_form', 				'custom_search_form_modify' );
// rename posts and pages
//add_filter( 'post_type_labels_page', 		'custom_rename_pages' );
//add_action( 'admin_menu', 					'custom_rename_post_label' );
//add_action( 'init', 						'custom_rename_post_object' );
// show page menu with home link
add_filter( 'wp_page_menu_args',        	'page_menu_args' );
//add_action( 'init',							'wp_custom_var_search', 5);

/*
 * Javascript addons
 */
add_action( 'wp_head', 						'custom_theme_javascript_detection', 0 );
add_action( 'wp_head', 						'custom_add_ajax_library' );
//add_filter( 'script_loader_tag', 			'add_async_attribute', 10, 2);

/*
 * Hide for non admins
 */
add_action( 'pre_user_query',				'isa_pre_user_query');
add_filter( 'editable_roles', 				'exclude_role' );
add_filter( 'parse_query', 					'custom_exclude_pages_from_admin' );
// Remove the Edit link from the admin bar
//add_action( 'wp_before_admin_bar_render', 	'custom_remove_admin_bar_edit_link' );

/*
 * Admin actions 
 */
// hardcode admin pagination for all
//add_action( 'admin_head', 					'admin_pagination'); 

// image actions
add_filter( 'wp_get_attachment_image_attributes', 'custom_post_thumbnail_sizes_attr', 10, 3 );

/**
 * 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.
 */
if (!function_exists('custom_theme_setup')){
	function custom_theme_setup() {
		global $main_menu_register;
		/*
		 * Load Localisation files.
		 *
		 * Note: the first-loaded translation file overrides any following ones if the same translation is present.
		 */

		// Loads wp-content/languages/themes/theme-name-it_IT.mo.
		load_theme_textdomain( '', trailingslashit( WP_LANG_DIR ) . 'themes/' );

		// Loads wp-content/themes/child-theme-name/languages/it_IT.mo.
		load_theme_textdomain( '', get_stylesheet_directory() . '/languages' );

		// Loads wp-content/themes/theme-name/languages/it_IT.mo.
		load_theme_textdomain( '', get_template_directory() . '/languages' );
			
		
		/*	Theme Navigation
		================================================ */	
		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( $main_menu_register );
		
		if(function_exists('add_theme_support')){
			/*
			 * Switch default core markup for search form, comment form, comments, galleries, captions and widgets
			 * to output valid HTML5.
			 */
			add_theme_support( 'html5', array(
				'search-form',
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
				'widgets',				
			) );
			
			/*
			 * 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' );
		
			// Declare support for selective refreshing of widgets.
			add_theme_support( 'customize-selective-refresh-widgets' );
			
			// Post Format support. You can also use the legacy "gallery" or "asides" (note the plural) categories.
			//add_theme_support('post-formats', array('image'));
		           
			/*
			 * 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');

			// This theme uses a custom background
			//add_theme_support( 'custom-background' );			
			
			// Add support for custom logo			
			$defaults = array(
				'height'      => 87,
				'width'       => 185,
			);
			add_theme_support( 'custom-logo', $defaults );						
		}
		
		// add excerpts to post_type 'page'			
		if(function_exists('add_post_type_support')){
			//add_post_type_support( 'page', 'excerpt' );
		}

		// add custom image sizes
		if ( function_exists( 'add_image_size' )) {
			/**
			 * tuki izberemo velikosti vseh slik ki jih potem uporabljamo na strani
			 *
			 * add_image_size( $name, $width, $height, $crop );
			 *
			 * crop: array( 
			 * - x_crop_position accepts ‘left’ ‘center’, or ‘right’.
			 * - y_crop_position accepts ‘top’, ‘center’, or ‘bottom’
			 * );
			 * Images will be cropped to the specified dimensions within the defined crop area.
			 *
			 * TIP: If you try using multiple crops with the same dimensions you’re going to run into an issue.
			 * The filenames for the new thumbnails use the dimensions to differentiate themselves from other sizes 
			 * of the same image. But they don’t use the crop type. So if you try to add a thumbnail size with a crop 
			 * of 200×200 with, say, a hard crop and another thumbnail size with an array crop of bottom right also 
			 * at 200×200, you’re only going to end up with one–whichever is last in the list. That’s because the 
			 * filename for both will become something like this: /files/2015/01/photo-200x200.jpg
			 * As you can see, there’s nothing in the filename that specifies which crop mode. When you embed the 
			 * thumbnail through the Media Library it will insert a bit of code that does specify the crop mode, but 
			 * that information is basically courtesy information and doesn’t control which actual file is displayed 
			 * on the page.
			 *
			 **/
			add_image_size('fp-blog', 300, 300, true);
			add_image_size('logos', 270, 200, true);
			add_image_size('big-blog', 540, 376, true);
			//add_image_size('services', 600, 600, true);
		}
		
		// Set the default content width.
		$GLOBALS['content_width'] = 525;
	
		/*
		 * This theme styles the visual editor to resemble the theme style,
		 * specifically font, colors, and column width.
		 */
		add_editor_style( array( 'assets/css/editor-style.css' ) );		
		
		if(is_admin()){
			global $ime_opcij, $theme_includes;
		
			if($ime_opcij != ""){
				$file = dirname( __FILE__ ) . '/theme-options/'.$ime_opcij.'.php';
				// Load up our theme options page and related code.
				if(file_exists($file))
					require_once( $file );
			}

			if($theme_includes != ""||is_array($theme_includes)&&!empty($theme_includes))
			{
				if(is_array($theme_includes)){
					foreach($theme_includes as $theme_include){
						$file = dirname( __FILE__ ) . '/theme-includes/'.$theme_include.'.php';
						if(file_exists($file))
							require_once( $file );
					}
				}
				else {
					$file = dirname( __FILE__ ) . '/theme-includes/'.$theme_includes.'.php';
					if(file_exists($file))
						require_once( $file );
				}
			}
		}
	}
}

/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
if (!function_exists('custom_theme_widgets_init')){
	function custom_theme_widgets_init() {		
	
		register_sidebar( array(
			'name' => __( 'Language switcher', "weexplain"),
			'id' => 'lang-widget-area',
			'description' => __( 'Switch between languages', "weexplain" ),
			'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Header search', "weexplain"),
			'id' => 'search-widget-area',
			'description' => __( 'Search bar inside header', "weexplain" ),
			'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Timer', "weexplain"),
			'id' => 'timer-widget-area',
			'description' => __( 'Countdown timer', "weexplain" ),
			'before_widget' => '<div class="timer-widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Front page video', "weexplain"),
			'id' => 'frontpage-video-widget-area',
			'description' => __( 'Front page video url', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h1 class="widget-title">',
			'after_title' => '</h1>',			
		) );
		
		register_sidebar( array(
			'name' => __( 'Front page', "weexplain"),
			'id' => 'frontpage-widget-area',
			'description' => __( 'Front page appearance', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h2 class="widget-title">',
			'after_title' => '</h2>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Sidebar', "weexplain"),
			'id' => 'sidebar-widget-area',
			'description' => __( 'Sidebar', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Video sidebar', "weexplain"),
			'id' => 'sidebar-video-widget-area',
			'description' => __( 'Sidebar for videos', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Newsletter', "weexplain"),
			'id' => 'newsletter-widget-area',
			'description' => __( 'Subscribe to our newsletter', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Social icons', "weexplain"),
			'id' => 'social-widget-area',
			'description' => __( 'Social icons', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Quick contact form', "weexplain"),
			'id' => 'quick-widget-area',
			'description' => __( 'Quick contact form in footer', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Footer kontakt', "weexplain"),
			'id' => 'footer-kontakt-widget-area',
			'description' => __( 'Contact information in footer', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );
		
		register_sidebar( array(
			'name' => __( 'Copyright informacije', "weexplain"),
			'id' => 'copy-widget-area',
			'description' => __( 'Copyright informacije', "weexplain" ),
			'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div>',
			'before_title' => '<h3 class="widget-title">',
			'after_title' => '</h3>',
		) );	
		
		register_sidebar( array(
			'name' => __( 'Kontakt', "weexplain"),
			'id' => 'contact-widget-area',
			'description' => __( 'Contact information on contact page', "weexplain" ),
			'before_widget' => '<div class="widget-container-wrap"><div id="%1$s" class="widget-container %2$s">',
			'after_widget' => '</div></div>',
			'before_title' => '<h2 class="widget-title">',
			'after_title' => '</h2>',
		) );
	
	}
}

/**
 * Register custom post types
 */
function custom_post_types() {	
	// dodatni meni za testimonialse	
  	$labels = array(
    	'name'               => _x( 'Testimonials', 'Ime v množini', "weexplain" ),
		'singular_name'      => _x( 'Testimonials', 'Ime v ednini', "weexplain" ),
		'add_new'            => _x( 'Add new', "weexplain"),
		'add_new_item'       => __( 'Add new testimonial', "weexplain" ),
		'edit_item'          => __( 'Edit testimonial', "weexplain" ),
		'new_item'           => __( 'New testimonial', "weexplain" ),
		'all_items'          => __( 'All testimonials', "weexplain" ),
		'view_item'          => __( 'View testimonial', "weexplain" ),
		'search_items'       => __( 'Search in testimonials', "weexplain" ),
		'not_found'          => __( 'Testimonials not found', "weexplain" ),
		'not_found_in_trash' => __( 'Testimonials not found in Bin', "weexplain" ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Testimonials'
	);
  	$args = array(
		'labels'        => $labels,
		'label'         => __( 'Testimonials', "weexplain" ),
		'description'   => 'Testimonials of clients who have worked with us',
		'public'        => false,
		'menu_position' => 6,
		'supports'      => array( 'title', 'editor', 'thumbnail' ),
		'has_archive'   => false,
		'show_ui'		=> true,
		'show_in_menu'	=> true,
		'menu_icon'   	=> 'dashicons-format-quote',
  	);
  	register_post_type( 'testimonials', $args ); 
	
	// dodatni meni za videe	
  	$labels = array(
    	'name'               => _x( 'Videos', 'Ime v množini', "weexplain" ),
		'singular_name'      => _x( 'Video', 'Ime v ednini', "weexplain" ),
		'add_new'            => _x( 'Add new', "weexplain"),
		'add_new_item'       => __( 'Add new video', "weexplain" ),
		'edit_item'          => __( 'Edit video', "weexplain" ),
		'new_item'           => __( 'New video', "weexplain" ),
		'all_items'          => __( 'All videos', "weexplain" ),
		'view_item'          => __( 'View video', "weexplain" ),
		'search_items'       => __( 'Search videos', "weexplain" ),
		'not_found'          => __( 'Videos not found', "weexplain" ),
		'not_found_in_trash' => __( 'Videos not found in Bin', "weexplain" ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Videos'
	);
  	$args = array(
		'labels'        => $labels,
		'label'         => __( 'Videos', "weexplain" ),
		'description'   => 'Our latest work',
		'public'        => true,
		'menu_position' => 7,
		'supports'      => array( 'title', 'editor', 'thumbnail', 'page-attributes' ),
		'has_archive'   => false,
		'show_ui'		=> true,
		'show_in_menu'	=> true,
		'menu_icon'   	=> 'dashicons-format-video',
		'show_in_nav_menus' => true,
  	);
  	register_post_type( 'videos', $args ); 
	
	// Add new taxonomy, make it hierarchical (like categories)
	$labels = array(
		'name'              => _x( 'Categories', 'taxonomy general name', "weexplain" ),
		'singular_name'     => _x( 'Category', 'taxonomy singular name', "weexplain" ),
		'search_items'      => __( 'Search categories', "weexplain" ),
		'all_items'         => __( 'All categories', "weexplain" ),
		'parent_item'       => __( 'Category parent', "weexplain" ),
		'parent_item_colon' => __( 'Category parent:', "weexplain" ),
		'edit_item'         => __( 'Edit category', "weexplain" ),
		'update_item'       => __( 'Update category', "weexplain" ),
		'add_new_item'      => __( 'Add new category', "weexplain" ),
		'new_item_name'     => __( 'New category', "weexplain" ),
		'menu_name'         => __( 'Categories', "weexplain" ),
	);
	$args = array(
		'hierarchical'      => true,
		//'labels'            => $labels,
		'label'				=> 'Categories',
		'show_ui'           => true,
		'show_admin_column' => true,
		'query_var'         => true,
		'rewrite'           => array( 'slug' => 'videos_category', 'hierarchical' => true ),
	);
	register_taxonomy( 'videos_category', array( 'videos' ), $args );
	
	$args = array(
		'hierarchical'      => true,
		//'labels'            => $labels,
		'label'				=> 'Applications',
		'show_ui'           => true,
		'show_admin_column' => true,
		'query_var'         => true,
		'rewrite'           => array( 'slug' => 'videos_applications', 'hierarchical' => true ),
	);
	register_taxonomy( 'videos_applications', array( 'videos' ), $args );
	
	// dodatni meni za logote	
  	$labels = array(
    	'name'               => _x( 'Logos', 'Ime v množini', "weexplain" ),
		'singular_name'      => _x( 'Logo', 'Ime v ednini', "weexplain" ),
		'add_new'            => _x( 'Add new', "weexplain"),
		'add_new_item'       => __( 'Add new logo', "weexplain" ),
		'edit_item'          => __( 'Edit logo', "weexplain" ),
		'new_item'           => __( 'New logo', "weexplain" ),
		'all_items'          => __( 'All logos', "weexplain" ),
		'view_item'          => __( 'View logo', "weexplain" ),
		'search_items'       => __( 'Search logos', "weexplain" ),
		'not_found'          => __( 'Logos not found', "weexplain" ),
		'not_found_in_trash' => __( 'Logos not found in Bin', "weexplain" ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Logos'
	);
  	$args = array(
		'labels'        => $labels,
		'label'         => __( 'Logos', "weexplain" ),
		'description'   => 'Clients we worked with',
		'public'        => false,
		'menu_position' => 7,
		'supports'      => array( 'title', 'editor', 'thumbnail' ),
		'has_archive'   => false,
		'show_ui'		=> true,
		'show_in_menu'	=> true,
		'menu_icon'   	=> 'dashicons-visibility',
  	);
  	register_post_type( 'logos', $args ); 
	
	// dodatni meni za faq	
  	$labels = array(
    	'name'               => _x( 'Frequently asked questions', 'Ime v množini', "weexplain" ),
		'singular_name'      => _x( 'Question', 'Ime v ednini', "weexplain" ),
		'add_new'            => _x( 'Add new', "weexplain"),
		'add_new_item'       => __( 'Add new question', "weexplain" ),
		'edit_item'          => __( 'Edit question', "weexplain" ),
		'new_item'           => __( 'New question', "weexplain" ),
		'all_items'          => __( 'All questions', "weexplain" ),
		'view_item'          => __( 'View question', "weexplain" ),
		'search_items'       => __( 'Search questions', "weexplain" ),
		'not_found'          => __( 'Questions not found', "weexplain" ),
		'not_found_in_trash' => __( 'Questions not found in Bin', "weexplain" ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'FAQ'
	);
  	$args = array(
		'labels'        => $labels,
		'label'         => __( 'FAQ', "weexplain" ),
		'description'   => 'Frequently asked questions',
		'public'        => false,
		'menu_position' => 8,
		'supports'      => array( 'title', 'editor', ),
		'has_archive'   => false,
		'show_ui'		=> true,
		'show_in_menu'	=> true,
		'menu_icon'   	=> 'dashicons-editor-help',
  	);
  	register_post_type( 'faq', $args ); 
	
	// dodatni meni za 6 simple steps	
  	$labels = array(
    	'name'               => _x( 'Steps', 'Ime v množini', "weexplain" ),
		'singular_name'      => _x( 'Step', 'Ime v ednini', "weexplain" ),
		'add_new'            => _x( 'Add new', "weexplain"),
		'add_new_item'       => __( 'Add new step', "weexplain" ),
		'edit_item'          => __( 'Edit step', "weexplain" ),
		'new_item'           => __( 'New step', "weexplain" ),
		'all_items'          => __( 'All steps', "weexplain" ),
		'view_item'          => __( 'View step', "weexplain" ),
		'search_items'       => __( 'Search steps', "weexplain" ),
		'not_found'          => __( 'No steps', "weexplain" ),
		'not_found_in_trash' => __( 'No steps in Trash', "weexplain" ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Steps'
	);
  	$args = array(
		'labels'        => $labels,
		'label'         => __( 'Steps', "weexplain" ),
		'description'   => '6 simple steps',
		'public'        => false,
		'menu_position' => 8,
		'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
		'has_archive'   => false,
		'show_ui'		=> true,
		'show_in_menu'	=> true,
		'menu_icon'   	=> 'dashicons-chart-bar',
  	);
  	register_post_type( 'steps', $args ); 
	
	// dodatni meni za ekipo	
  	$labels = array(
    	'name'               => _x( 'Team', 'Ime v množini', "weexplain" ),
		'singular_name'      => _x( 'Member', 'Ime v ednini', "weexplain" ),
		'add_new'            => _x( 'Add new', "weexplain"),
		'add_new_item'       => __( 'Add new member', "weexplain" ),
		'edit_item'          => __( 'Edit member', "weexplain" ),
		'new_item'           => __( 'New member', "weexplain" ),
		'all_items'          => __( 'All members', "weexplain" ),
		'view_item'          => __( 'View member', "weexplain" ),
		'search_items'       => __( 'Search by members', "weexplain" ),
		'not_found'          => __( 'No members', "weexplain" ),
		'not_found_in_trash' => __( 'No member in Trash', "weexplain" ), 
		'parent_item_colon'  => '',
		'menu_name'          => 'Team'
	);
  	$args = array(
		'labels'        => $labels,
		'label'         => __( 'Team', "weexplain" ),
		'description'   => 'All members of our team',
		'public'        => false,
		'menu_position' => 8,
		'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
		'has_archive'   => false,
		'show_ui'		=> true,
		'show_in_menu'	=> true,
		'menu_icon'   	=> 'dashicons-groups',
  	);
  	register_post_type( 'team', $args ); 
}

/**
* Rename post type page to podstrani
*
* @param object $labels
* @hooked post_type_labels_post
* @return object $labels
*/
function custom_rename_pages( $labels )
{
    # Labels
    $labels->name = __('Podstrani', '');
    $labels->singular_name = __('Podstran', '');
    $labels->add_new = __('Dodaj podstran', '');
    $labels->add_new_item = __('Dodaj podstran', '');
    $labels->edit_item = __('Uredi podstran', '');
    $labels->new_item = __('Nova podstran', '');
    $labels->view_item = __('Poglej podstran', '');
    $labels->view_items = __('Poglej podstrani', '');
    $labels->search_items = __('Išči podstrani', '');
    $labels->not_found = __('Nobene podstrani ni bilo mogoče najti.', '');
    $labels->not_found_in_trash = __('Nobene podstrani ni bilo mogoče najti v Smeteh.', '');
    $labels->parent_item_colon = __('Starš podstrani', ''); // Not for "post"
    $labels->archives = __('Arhiv podstrani', '');
    $labels->attributes = __('Atributi podstrani', '');
    $labels->insert_into_item = __('Vstavi v podstran', '');
    $labels->uploaded_to_this_item = __('Naloženo v to podstran', '');
    $labels->featured_image = 'Featured Image';
    $labels->set_featured_image = 'Set featured image';
    $labels->remove_featured_image = 'Remove featured image';
    $labels->use_featured_image = 'Use as featured image';
    $labels->filter_items_list = __('Filtriraj spisek podstrani', '');
    $labels->items_list_navigation = __('Navigacija podstrani', '');
    $labels->items_list = __('Spisek podstrani', '');

    # Menu
    $labels->menu_name = __('Podstrani', '');
    $labels->all_items = __('Vse podstrani', '');
    $labels->name_admin_bar = __('Podstrani', '');

    return $labels;
}

function custom_rename_post_object() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = __('Obvestila', '');
    $labels->singular_name = __('Obvestilo', '');
    $labels->add_new = __('Dodaj novo', '');
    $labels->add_new_item = __('Dodaj novo obvestilo', '');
    $labels->edit_item = __('Uredi obvestilo', '');
    $labels->new_item = __('Obvestilo', '');
    $labels->view_item = __('Poglej obvestilo', '');
    $labels->search_items = __('Poišči obvestilo', '');
    $labels->not_found = __('Nič obvestil', '');
    $labels->not_found_in_trash = __('Nič obvestil v Smeteh', '');
    $labels->all_items = __('Vsa obvestila', '');
    $labels->menu_name = __('Obvestila', '');
    $labels->name_admin_bar = __('Obvestila', '');
}

/**
 * Register custom fonts.
 */
function custom_fonts_url() {
	$fonts_url = '';

	$font_families = array();

	$font_families[] = 'Anton:400';
	$font_families[] = 'Roboto:400,700';

	$query_args = array(
		'family' => urlencode( implode( '|', $font_families ) ),
		//'subset' => urlencode( 'latin,latin-ext' ),
		'subset' => urlencode( 'latin' ),
	);

	$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );

	return esc_url_raw( $fonts_url );
}
 
/**
* Enqueue scripts and styles.
*/
if (!function_exists('custom_theme_scripts')){ 
	function custom_theme_scripts() {
		global $ime_theme;
		
		if(!is_admin()){
			/**
			 * Styles
			 */
			// Add custom fonts, used in the main stylesheet.
			wp_enqueue_style( ''.$ime_theme.'-fonts', custom_fonts_url(), array(), null );

			// Load our main stylesheet.
			wp_enqueue_style( ''.$ime_theme.'-style', get_stylesheet_uri() );

			/**
			 * Scripts
			 */
			//wp_register_script(''.$ime_theme.'-cycle', 'https://malsup.github.io/min/jquery.cycle2.min.js', array('jquery'));
			wp_register_script(''.$ime_theme.'-cycle', get_template_directory_uri().'/assets/js/jquery.cycle2.min.js', array('jquery'));		
			wp_enqueue_script(''.$ime_theme.'-cycle');

			//wp_register_script(''.$ime_theme.'-cycle-carousel', 'https://malsup.github.io/min/jquery.cycle2.carousel.min.js', array(''.$ime_theme.'-cycle'));
			wp_register_script(''.$ime_theme.'-cycle-carousel', get_template_directory_uri().'/assets/js/jquery.cycle2.carousel.min.js', array(''.$ime_theme.'-cycle'));
			wp_enqueue_script(''.$ime_theme.'-cycle-carousel');

			wp_register_script(''.$ime_theme.'-script', get_template_directory_uri().'/assets/js/scripts.js', array('jquery'), false, true);
			wp_enqueue_script(''.$ime_theme.'-script');						
		}		
	}		
}

/**
 * Handles JavaScript detection.
 *
 * Adds a `js` class to the root `<html>` element when JavaScript is detected.
 *
 */
if (!function_exists('custom_theme_javascript_detection')){ 
	function custom_theme_javascript_detection() {
		echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
	}
}

/**
 * Adds the WordPress Ajax Library to the frontend.
 */
function custom_add_ajax_library() {
 
    $html = '<script type="text/javascript">';
    $html .= 'var ajaxurl = "' . admin_url( 'admin-ajax.php' ) . '"';
    $html .= '</script>';
 
    echo $html;
 
}

/**
 * Add a `screen-reader-text` class to the search form's submit button.
 */
function custom_search_form_modify( $html ) {
	return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html );
}

/**
 * Add custom variable for search results
 */
function wp_custom_var_search() { 
    global $wp;	
	$wp->add_query_var('spage');
}

/**
 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
 *
 * @param array $args Configuration arguments.
 * @return array
 */
function page_menu_args( $args ) {
	$args['show_home'] = true;
	return $args;
}

/**
 * Add custom image sizes attribute to enhance responsive image functionality
 * for post thumbnails.
 *
 * @since Twenty Seventeen 1.0
 *
 * @param array $attr       Attributes for the image markup.
 * @param int   $attachment Image attachment ID.
 * @param array $size       Registered image size or flat array of height and width dimensions.
 * @return array The filtered attributes for the image markup.
 */
function custom_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
	if ( is_archive() || is_search() || is_home() ) {
		$attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
	} else {
		$attr['sizes'] = '100vw';
	}

	return $attr;
}

/*
 * Customize login screen, URL and title with credentials added in functions.php
 **/
function my_login_logo() {
	global $login_logo_url, $login_logo_additional;
	if($login_logo_url != ""){ ?>
		<style type="text/css">
            .login h1 a {
                background-image: url(<?php echo $login_logo_url ?>) !important;
                width: 100% !important;
                height: 100px !important;
                background-size: contain !important;
                <?php if($login_logo_additional != "") echo $login_logo_additional; ?>
            }
        </style>
<?php }
}

function my_login_logo_url() {
    return home_url();
}

function my_login_logo_url_title() {
	global $login_title;
    return $login_title;
}

/**
 * Hide Administrator From User List
 **/
function isa_pre_user_query($user_search) {
	$user = wp_get_current_user();
	if (!current_user_can('administrator')) { // Is Not Administrator - Remove Administrator
    	global $wpdb;

	    $user_search->query_where = 
    	    str_replace('WHERE 1=1', 
        	    "WHERE 1=1 AND {$wpdb->users}.ID IN (
            	     SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta 
                	    WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
                    	AND {$wpdb->usermeta}.meta_value NOT LIKE '%administrator%')", 
	        $user_search->query_where
        );
	}
}
function exclude_role($roles) {

	//Hide Defualt Roles
	if (isset($roles['author'])) {
		unset($roles['author']);
	}
	
	if (isset($roles['editor'])) {
		unset($roles['editor']);
	}
	
	if (isset($roles['subscriber'])) {
		unset($roles['subscriber']);
	}
	
	if (isset($roles['contributor'])) {
		unset($roles['contributor']);
	}
	
	return $roles;
}

/* odstranimo vse strani, ki jih uporabniki ne rabijo urejat, zato jih ne rabijo tudi videt. Funkcija jih samo skrije */
function custom_exclude_pages_from_admin($query) {
	global $exclude_pages;
	if(empty($exclude_pages) || !is_array($exclude_pages) || !is_admin()) return $query;
	
	$pages_ids = array();  	
  	global $pagenow, $post_type;
	if(is_array($exclude_pages)){
		// dobimo idje vseh strani
		foreach($exclude_pages as $exclude_page){
			$slug = sanitize_title($exclude_page);
			$page = get_page_by_path( $slug );
			if(!is_null($page))
				$pages_ids[] = $page->ID;
		}
	}
  	if ( !current_user_can( 'administrator' ) && $pagenow == 'edit.php' && $post_type == 'page' )
    	$query->query_vars['post__not_in'] = $pages_ids;
}

// Force Page CPT to have excerpt (all users)
// -------------------------------------------------------------
if ( is_admin() ) :
  function force_excerpt_box() {

    // get all post types (excluding posts)
    $post_types = array('post');

    // get all users
    $all_users = get_users( );
    $user_list = array();

    $hide_boxes = array(
        'postcustom',
        'slugdiv',
		'tagsdiv-post_tag',
    );

    foreach($all_users as $user):
      $user_list[] = $user->id;
    endforeach;

    foreach($user_list as $user):

      foreach($post_types as $post_type):
        update_user_option($user, 'metaboxhidden_'.$post_type, $hide_boxes);
      endforeach;

    endforeach;

  }
  add_action( 'admin_menu', 'force_excerpt_box' );
endif;

// override all admin number of posts
function admin_pagination(){
        global $wp_query;
        $per_page = 30;
        $wp_query->query('showposts='. $per_page);
}

// Remove the Edit link from the admin bar
function custom_remove_admin_bar_edit_link() {
	if(!current_user_can('administrator')){
	    global $wp_admin_bar, $exclude_pages;
		$nodes = $wp_admin_bar->get_nodes();
		$href = $nodes['edit']->href;
		$question = strpos($href, "=");
		$and = strpos($href, '&');
		if($question>0&&$and>0&&is_array($exclude_pages)){
			$id = substr($href, ($question+1), ($and-($question+1))); // 1 ker je =
		
			// dobimo idje vseh strani
			foreach($exclude_pages as $exclude_page){
				$slug = sanitize_title($exclude_page);
				$page = get_page_by_path( $slug );
				if(!is_null($page))
					$pages_ids[] = $page->ID;
			}
			if(in_array($id, $pages_ids))
				$wp_admin_bar->remove_menu( 'edit' );
		}
	}
}