<?php
// is site in development or production?
function ow_development() {
	
	if ( ow_global_var( 'in_production' ) == 0 ) {
		
		return 'development';
	}
}



// FILTER TEMPLATE NAME
function var_template_include( $t ) {
	
    $GLOBALS['current_theme_template'] = basename( $t );
    return $t;
}
add_filter( 'template_include', 'var_template_include', 1000 );



// GET TEMPLATE NAME
function get_current_template() {
	
	return $GLOBALS['current_theme_template'];
}



// IRIS BUILD ALERTS
$alert_array = array();

function developer_console_message( $msg, $lvl ) {
	
	global $alert_array;
	
	$alert_array[$msg] = $lvl;
}


// updated 1.3.3
function check_plugins_loaded() {
	
	if ( ! function_exists( 'yoast_breadcrumb' ) ) {
		
		developer_console_message( 'YOAST SEO plugin is not activated/installed', 'alert' );
	}
	if ( ! function_exists( 'the_field') ) {
		
		developer_console_message( 'Advanced Custom Fields plugin is not activated/installed', 'alert' );
	}
	if ( ! class_exists( 'LiteSpeed_Cache' ) ) {
		
		developer_console_message( 'LiteSpeed Cache plugin is not activated/installed', 'alert' );
	}
}
add_action( 'after_body', 'check_plugins_loaded' );



function check_global_var() {
	
	global $ow_global_variables;
	
	foreach ( $ow_global_variables as $key => $var ) {
		
		if ( $var === '' ) {
			
			developer_console_message( $key . ' is not defined', 'warning' );
		}
	}
}
add_action( 'after_body', 'check_global_var' );



function developer_console_alert_bar() {
	
	global $alert_array;
	
	if ( current_user_can('administrator') ) {
		
		$string = '';
		$string .= '<div id="iris-alert-bar"><ul>';
		$string .= '<li><img width="221px" height="60px" src="' . plugins_url( 'img/iris-webportal-logo-white.svg', dirname( __FILE__ ) ) . '" alt="Powered by '.PRODUCT_NAME.'" id="powered-by-openwebsite-admin"/> <span>Developer Console</span></li><li>&nbsp;</li>';
		
		if ( ow_development() ) {
			
			$string .= '<li class="info">In DEVELOPMENT mode</li>';
		} else {
			
			$string .= '<li class="alert">In PRODUCTION mode</li>';
		}
		$string .= '<li class="package">Website Package: ' . ow_global_var( 'website_package' ) . '</li>';
		
		if ( has_newsletter() ) {
			
			$string .= '<li class="package">Has Newsletter</li>';
		} else {
			
			$string .= '<li class="warning">Doesn\'t have Newsletter</li>';
		}
		$string .= '<li>Template file: ' . get_current_template() . '</li>';
		$string .= '<li>Post ID: ' . get_queried_object_id() . '</li>';
		$string .= '<li>Post Title: ' . get_the_title() . '</li>';

		if ( CLIENT_USERNAME == NULL ) {
			
			$string .= '<li class="alert">CLIENT USERNAME is not defined</li>';
		}
		foreach ( $alert_array as $alert => $lvl ) {
			
			$string .= '<li class="' . $lvl . '">' . $alert . '</li>';
		}
		$string .= '</ul>';
		$string .= file_get_contents( plugins_url( 'tags-list.php', __FILE__ ) );
		$string .= '</div>';

		echo $string;		
	}
}
add_action( 'wp_footer', 'developer_console_alert_bar', 120 );



function add_iris_plugin_css() {
	
	if ( current_user_can( 'administrator' ) ) {
		
		wp_register_style( 'iris-styles', plugins_url( 'css/style.css', dirname( __FILE__ ) ), array(), null, 'all' );
		wp_enqueue_style( 'iris-styles' );
	}
}
add_action( 'wp_enqueue_scripts', 'add_iris_plugin_css' );