<?php
namespace ONLINE_ADAv4;
if ( !defined( 'ABSPATH' ) ) exit;

/**
 * Displays the plugin activation notice
 */
function activation_notice() {
	// Plugin activation notice, links to create a new scan and guidelines page.
	$show_activation = get_option( 'ada-plugin-show-activation-message' );
	if ( !empty($show_activation) ) {
		$screen = get_current_screen();
		if ( in_array( $screen->id, array( "ada_plugin_scan_page_wcag-guidelines", "wcag_scan", "edit-wcag_scan" ) ) ) {
			// When visiting the accessibility page, we can skip this notice.
			update_option( 'ada-plugin-show-activation-message', 0, 'yes' );
		}else{
			// On all other screens:
			// Show a notice that links to the accessibility screen. Add a dismiss box to close the notice.
			?>
			<div class="notice notice-info is-dismissable ada-plugin-notice ada-plugin-notice-plugin-activation">
				<p><strong>Accessibility Suite:</strong> Thank you for installing our WordPress plugin! You can get started immediately by <a href="<?php echo esc_attr(admin_url('post-new.php?post_type=wcag_scan')); ?>">starting a new audit</a> or take a look at the <a href="<?php echo esc_attr(admin_url('edit.php?post_type=wcag_scan&page=wcag-guidelines')); ?>">WCAG Level A & AA Guidelines for WordPress</a>.</p>

				<button type="button" class="notice-dismiss" data-action="ada_plugin_dismiss_notice" data-notice="<?php echo esc_attr(wp_create_nonce('plugin-activation')); ?>">
					<span class="screen-reader-text">Dismiss this message.</span>
				</button>
			</div>
			<?php
		}
	}
}
add_action( 'admin_notices', __NAMESPACE__ . '\\activation_notice' );

/**
 * Dismiss the notice via ajax
 */
function dismiss_notice() {
	$notice_nonce = isset($_REQUEST['notice']) ? stripslashes($_REQUEST['notice']) : false;
	if ( !$notice_nonce ) return;

	// Closing the "Plugin Activated" notice
	if ( wp_verify_nonce( $notice_nonce, 'plugin-activation' ) ) {
		update_option( 'ada-plugin-show-activation-message', 0, 'yes' );
		echo 1;
		exit;
	}
}
add_action( 'wp_ajax__oadaas__dismiss_notice', __NAMESPACE__ . '\\dismiss_notice' );
