<?php
namespace NeoMotionBeta\NeoGlobal; if (!defined("ABSPATH")) { die("neoWP direct access not allowed"); }






function install_plugin_zip($zip_url) {
    
    require_once(ABSPATH . "wp-admin/includes/file.php");
    require_once(ABSPATH . "wp-admin/includes/plugin.php");
    require_once(ABSPATH . "wp-admin/includes/class-wp-upgrader.php");
    require_once(ABSPATH . "wp-admin/includes/class-plugin-upgrader.php");
    eval('if (!function_exists("show_message")) { function show_message($message) { echo "<div>" . $message . "</div>"; } }');
    $upgrader = new \Plugin_Upgrader();
    $install_result = $upgrader->install($zip_url, ["overwrite_package" => true]);
    if (is_wp_error($install_result)) { \NeoMotionBeta\NeoGlobal\throw_global_exception("Plugin installation failed: " . $install_result->get_error_message()); }
    if ($install_result === null || $install_result === false) { \NeoMotionBeta\NeoGlobal\throw_global_exception("Plugin installation failed (unknown error)"); }
}


function register_install_neo_media_pro_rest_endpoint() {
    
    \NeoMotionBeta\NeoGlobal\register_rest_endpoint("/wp-json/neo/install-neo-media-pro-neo-motion-beta", "POST", fn () => \NeoMotionBeta\NeoGlobal\current_user_can__neo_pro_installer(), function ($get_param) {
        [$license_key, $interface_ok] = \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoFreemius\interface_freemius_license_secret_key_20260211')();
        if ($license_key === null) { return new \WP_Error("no_license_key", "No license key set.", ["status" => 400]); }
        $zip_url = \NeoMotionBeta\NeoGlobal\get_plugin_download_zip_file_url_without_version("neo-media", "pro") . "?license-key=" . urlencode($license_key);
        install_plugin_zip($zip_url);
        $result = activate_plugin(\NeoMotionBeta\NeoGlobal\get_plugin_entry_path_relative("neo-media"));
        if (is_wp_error($result)) { \NeoMotionBeta\NeoGlobal\throw_global_exception("Plugin activation failed: " . $result->get_error_message()); }
        exit;
    });
}
