<?php
/**
 * Reset Defaults
 *
 * Reset all plugin settings to default values.
 *
 * @since   6.4.1
 *
 * @package WPrequal
 */

namespace WPrequal;

if ( ! defined( 'ABSPATH' ) ) {
	wp_die( 'Access denied!!' );
}

add_action( 'admin_init', 'WPrequal\reset_defaults' );

/**
 * Reset plugin defaults
 *
 * @since 8.3.1 Add verify nonce and user is logged in.
 */

function reset_defaults() {

    if ( ! isset( $_GET['wprequal_reset_defaults'] ) ) {
        return;
    }

    $nonce = sanitize_text_field( $_GET['wprequal_reset_defaults'] );

    if ( ! wp_verify_nonce( $nonce,  'wprequal_reset_defaults' ) ) {
        wp_die( 'Invalid Action!!' );
    }

    if ( ! $_GET['wprequal_reset_defaults'] ) {
        return;
    }

    if ( ! is_admin() ) {
        return;
    }

    if ( ! is_user_logged_in() ) {
        return;
    }

    if ( ! current_user_can( WPREQUAL_CAP ) ) {
        return;
    }

    foreach ( options() as $option => $value ) {
        update_option( $option, $value );
    }

}
