<?php
/**
 * Add theme page
 */
function gutenify_exosphere_menu() {
	add_theme_page( esc_html__( 'Gutenify Exosphere', 'gutenify-exosphere' ), esc_html__( 'Gutenify Theme', 'gutenify-exosphere' ), 'edit_theme_options', 'gutenify-exosphere-info', 'gutenify_exosphere_theme_page_display' );
}
add_action( 'admin_menu', 'gutenify_exosphere_menu' );

/**
 * Display About page
 */
function gutenify_exosphere_theme_page_display() {
	$theme = wp_get_theme();

	// if ( is_child_theme() ) {
	// 	$theme = wp_get_theme()->parent();
	// }

	include_once 'templates/theme-info.php';
}

function gutenify_exosphere_admin_plugin_notice() {
	$theme = wp_get_theme();
	$hide_notice_bar = get_user_meta( get_current_user_id(), 'gutenify_exosphere_hide_theme_info_noticebar', true );
	if ( '1' !== $hide_notice_bar ) {
		wp_enqueue_style( 'gutenify-exosphere-admin-style' );
		wp_enqueue_script( 'gutenify-exosphere-admin' );
		include 'templates/admin-plugin-notice.php';
	}
}
add_action( 'admin_notices', 'gutenify_exosphere_admin_plugin_notice' );


function gutenify_exosphere_hide_theme_info_noticebar() {
	check_ajax_referer( 'gutenify_exosphere-nonce', 'gutenify_exosphere-nonce-name' );
	if ( ! current_user_can( 'edit_theme_options' ) ) {
		wp_die( -1 );
	}

	update_user_meta( get_current_user_id(), 'gutenify_exosphere_hide_theme_info_noticebar', 1 );

	wp_die( 1 );
}
add_action( 'wp_ajax_gutenify_exosphere_hide_theme_info_noticebar', 'gutenify_exosphere_hide_theme_info_noticebar' );
