<?php
function find_wordpress_root($start_path) {
    while (!file_exists($start_path . '/wp-load.php')) {
        $start_path = dirname($start_path);
        if ($start_path === '/') {
            return false;
        }
    }
    return $start_path;
}
$wordpress_root = find_wordpress_root(__DIR__);
require_once $wordpress_root. '/wp-load.php';
global $wpdb;
$currentConfig=$wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "hd_webapp_generator where id=".$_REQUEST["app_wp_id"]);
$getUpdate=$wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'hd_webapp_generator where id > '.$_REQUEST["app_wp_id"]." and has_force_update=1 and app_package_name='".$currentConfig->app_package_name."' and status=1 order by id DESC" );
if(!empty($getUpdate) && count($getUpdate)>0) {
    $getUpdate=$getUpdate[0];
    if (file_exists(plugin_dir_path(__FILE__) . "apps/" . $getUpdate->file_name)) {
        $response = ["is_success" => 1, "url" => plugins_url("apps/" . $getUpdate->file_name, __FILE__)];
        echo json_encode($response);
    }else{
        $response = ["is_success" => false, "url" => null];
        echo json_encode($response);
    }
}else{
    $response = ["is_success" => false, "url" => null];
    echo json_encode($response);
}
?>