<?php
 namespace LingoWP\Backend; final class AddonInstaller { public function install(string $zipBytes, string $product): array { if (! function_exists('unzip_file')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } if (! function_exists('activate_plugin')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $tmpFile = wp_tempnam("lingowp-{$product}.zip"); if ($tmpFile === '' || file_put_contents($tmpFile, $zipBytes) === false) { return ['ok' => false, 'error' => 'ERR_ADDON_INSTALL_FAILED']; } try { $unzipped = unzip_file($tmpFile, WP_PLUGIN_DIR); if (is_wp_error($unzipped)) { return ['ok' => false, 'error' => 'ERR_ADDON_INSTALL_FAILED']; } $pluginFile = "lingowp-{$product}/lingowp-{$product}.php"; if (! file_exists(WP_PLUGIN_DIR . '/' . $pluginFile)) { return ['ok' => false, 'error' => 'ERR_ADDON_INSTALL_FAILED']; } $activated = activate_plugin($pluginFile); if (is_wp_error($activated)) { return ['ok' => false, 'error' => 'ERR_ADDON_ACTIVATE_FAILED']; } return ['ok' => true, 'error' => '']; } finally { @unlink($tmpFile); } } } 