<?php
/**
 * Add theme page
 */
function gutenify_store_base_menu() {
	add_theme_page( esc_html__( 'Gutenify Store Base', 'gutenify-store-base' ), esc_html__( 'Gutenify Theme', 'gutenify-store-base' ), 'edit_theme_options', 'gutenify-store-base-info', 'gutenify_store_base_theme_page_display' );
}
add_action( 'admin_menu', 'gutenify_store_base_menu' );

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

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

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

function gutenify_store_base_admin_plugin_notice() {
	$theme = wp_get_theme();

	// Enqueued unconditionally (not gated behind the notice's own dismiss
	// state) because admin.js also handles dismissal of the separate TGM
	// "recommended plugin" notice, which can appear on any admin page
	// independently of whether this notice has been dismissed.
	wp_enqueue_style( 'gutenify-store-base-admin-style' );
	wp_enqueue_script( 'gutenify-store-base-admin' );

	$hide_notice_bar = get_user_meta( get_current_user_id(), 'gutenify_store_base_hide_theme_info_noticebar', true );
	if ( '1' !== $hide_notice_bar ) {
		include 'templates/admin-plugin-notice.php';
	}
}
add_action( 'admin_notices', 'gutenify_store_base_admin_plugin_notice' );


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

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

	wp_die( 1 );
}
add_action( 'wp_ajax_gutenify_store_base_hide_theme_info_noticebar', 'gutenify_store_base_hide_theme_info_noticebar' );
