<?php
/*
 * Developed By Devozon
 *
 * Check Out at https://devozon.com/
 * Email: support@devozon.com
 * Message: https://www.facebook.com/devozon
 *
 * Please feel free to contact me at any time if you need a custom script or any development work.
 *
 * Devozon Team:
 * Coded by Sanad Nabil
 * Theme by Ahmed Reda
 * Tested By Smith Carter
 *
 * Devozon All rights reserved
 * Copyright (c) 2023-2024.
 * Last Update 15 \ 9 \ 2024
 */

if (!defined('ABSPATH')) {
    exit;
}

function FENSE_BPVT_plugin_version_check()
{

    $zminutes_to_add = 15;

    $ztime = new DateTime();
    $ztime_now = $ztime->format('YmdHi');

    $ztime->add(new DateInterval('PT' . $zminutes_to_add . 'M'));
    $ztime_plus15 = $ztime->format('YmdHi');

    $zdbdata = get_option('FENSE_BPVT_DEVOZON_tg_wp_version');
    $zdbtime = get_option('FENSE_BPVT_DEVOZON_tg_wp_version_time');

    if (empty($zdbdata) || $zdbtime < $ztime_now) {
        $zapidata = wp_remote_retrieve_body(wp_remote_get(esc_url(FENSE_BPVT_MAIN_LINK) . 'wordpress_version'));
        $zdbdata = json_decode($zapidata);

        if ($zdbdata->status == 'success') {
            update_option('FENSE_BPVT_DEVOZON_tg_wp_version', $zapidata);
            update_option('FENSE_BPVT_DEVOZON_tg_wp_version_time', $ztime_plus15);
        }

    } else {
        $zdbdata = json_decode($zdbdata);
    }

    if ($zdbdata->latest != FENSE_BPVT_VERSION) {
        $currentScreen = get_current_screen();

        if ($currentScreen->parent_base) {
            echo '<div class="notice notice-warning is-dismissible">
                <p>' . esc_html__('Hello, there is a new version of Fense extension.', 'fense-block-vpn-proxy') . '
                </p>
              </div>';
        }
    }

}

add_action('admin_notices', 'FENSE_BPVT_plugin_version_check');
