Plugin Directory

Changeset 3425814


Ignore:
Timestamp:
12/23/2025 06:14:50 AM (3 months ago)
Author:
codename065
Message:

3.3.39 - 2025.12.23

  • Fixed a fatal error with Session class during early WordPress initialization
  • Added fallbacks for WordPress functions not available during plugin loading
  • Improved compatibility with various server configurations
Location:
download-manager/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • download-manager/trunk/download-manager.php

    r3425719 r3425814  
    66Author: W3 Eden, Inc.
    77Author URI: https://www.wpdownloadmanager.com/
    8 Version: 3.3.38
     8Version: 3.3.39
    99Text Domain: download-manager
    1010Domain Path: /languages
     
    4141global $WPDM;
    4242
    43 define('WPDM_VERSION','3.3.37');
     43define('WPDM_VERSION','3.3.39');
    4444
    4545define('WPDM_TEXT_DOMAIN','download-manager');
  • download-manager/trunk/readme.txt

    r3425719 r3425814  
    66Tested up to: 6.9
    77License: GPLv3
    8 Stable tag: 3.3.38
     8Stable tag: 3.3.39
    99
    1010
     
    204204== Changelog ==
    205205
     206= 3.3.39 - 2025.12.23 =
     207* Fixed a fatal error with Session class during early WordPress initialization
     208* Added fallbacks for WordPress functions not available during plugin loading
     209* Improved compatibility with various server configurations
     210
    206211= 3.3.38 - 2025.12.23 =
    207212* Added Color Scheme option (System/Light/Dark) in UI settings
  • download-manager/trunk/src/__/Session.php

    r3425719 r3425814  
    2525        self::$initialized = true;
    2626
    27         self::$store = get_option('__wpdm_tmp_storage', 'db');
     27        // get_option should be available, but fallback to 'db' if not
     28        self::$store = \function_exists('get_option') ? \get_option('__wpdm_tmp_storage', 'db') : 'db';
    2829        self::initDeviceID();
    2930
    3031        if (self::$store === 'file') {
    3132            self::loadFileSession();
    32             register_shutdown_function([__CLASS__, 'saveSession']);
     33            \register_shutdown_function([__CLASS__, 'saveSession']);
    3334        }
    3435    }
     
    5758
    5859        // Generate new ID (random is more reliable than IP+UA)
    59         $deviceID = wp_generate_password(32, false);
     60        // Use wp_generate_password if available, otherwise fallback to PHP random
     61        if (\function_exists('wp_generate_password')) {
     62            $deviceID = \wp_generate_password(32, false);
     63        } else {
     64            // Fallback for early initialization before WordPress is fully loaded
     65            $deviceID = \bin2hex(\random_bytes(16));
     66        }
    6067        self::$deviceID = $deviceID;
    6168        self::setDeviceCookie($deviceID);
     
    6976    private static function setDeviceCookie($deviceID)
    7077    {
    71         if (defined('WPDM_ACCEPT_COOKIE') && WPDM_ACCEPT_COOKIE === false) return;
    72         if (!apply_filters('wpdm_user_accept_cookies', true)) return;
    73 
    74         $domain = wp_parse_url(home_url(), PHP_URL_HOST);
    75         @setcookie('__wpdm_client', $deviceID, 0, "/", $domain, is_ssl(), true);
     78        if (\defined('WPDM_ACCEPT_COOKIE') && WPDM_ACCEPT_COOKIE === false) return;
     79
     80        // Check if apply_filters is available (WordPress fully loaded)
     81        if (\function_exists('apply_filters') && !\apply_filters('wpdm_user_accept_cookies', true)) return;
     82
     83        // Get domain - with fallback for early initialization
     84        if (\function_exists('home_url')) {
     85            $domain = \wp_parse_url(\home_url(), PHP_URL_HOST);
     86        } else {
     87            // Fallback: parse from server variables
     88            $domain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
     89            $domain = \preg_replace('/:\d+$/', '', $domain); // Remove port if present
     90        }
     91
     92        $secure = \function_exists('is_ssl') ? \is_ssl() : (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
     93        @\setcookie('__wpdm_client', $deviceID, 0, "/", $domain, $secure, true);
    7694        $_COOKIE['__wpdm_client'] = $deviceID;
    7795    }
     
    106124        if (!self::$initialized) self::init();
    107125
    108         $expireTime = time() + $expire;
     126        $expireTime = \time() + $expire;
    109127
    110128        // Always cache in memory
     
    121139            $wpdb->query($wpdb->prepare(
    122140                "REPLACE INTO {$wpdb->prefix}ahm_sessions (deviceID, name, value, expire) VALUES (%s, %s, %s, %d)",
    123                 self::$deviceID, $name, maybe_serialize($value), $expireTime
     141                self::$deviceID, $name, \maybe_serialize($value), $expireTime
    124142            ));
    125143        } else {
     
    141159        if (isset(self::$data[$name])) {
    142160            $cached = self::$data[$name];
    143             if ($cached['expire'] > time()) {
     161            if ($cached['expire'] > \time()) {
    144162                return $cached['value'];
    145163            }
     
    158176            "SELECT value FROM {$wpdb->prefix}ahm_sessions
    159177             WHERE deviceID = %s AND name = %s AND expire > %d",
    160             self::$deviceID, $name, time()
     178            self::$deviceID, $name, \time()
    161179        ));
    162180
    163181        if ($value !== null) {
    164             $unserialized = maybe_unserialize($value);
     182            $unserialized = \maybe_unserialize($value);
    165183            // Cache for subsequent calls in same request
    166             self::$data[$name] = ['value' => $unserialized, 'expire' => time() + 300];
     184            self::$data[$name] = ['value' => $unserialized, 'expire' => \time() + 300];
    167185            return $unserialized;
    168186        }
     
    203221        $wpdb->query($wpdb->prepare(
    204222            "DELETE FROM {$wpdb->prefix}ahm_sessions WHERE expire < %d AND deviceID != 'alldevice'",
    205             time()
     223            \time()
    206224        ));
    207225    }
     
    230248    {
    231249        $file = WPDM_CACHE_DIR . "/session-" . self::$deviceID . ".txt";
    232         $realpath = realpath($file);
    233         if ($realpath && file_exists($realpath) && substr_count($realpath, WPDM_CACHE_DIR)) {
    234             $data = file_get_contents($realpath);
     250        $realpath = \realpath($file);
     251        if ($realpath && \file_exists($realpath) && \substr_count($realpath, WPDM_CACHE_DIR)) {
     252            $data = \file_get_contents($realpath);
    235253            $data = Crypt::decrypt($data, true);
    236             self::$data = is_array($data) ? $data : [];
     254            self::$data = \is_array($data) ? $data : [];
    237255        }
    238256    }
     
    246264
    247265        // Filter out expired entries before saving
    248         $now = time();
    249         self::$data = array_filter(self::$data, function($v) use ($now) {
     266        $now = \time();
     267        self::$data = \array_filter(self::$data, function($v) use ($now) {
    250268            return $v['expire'] > $now;
    251269        });
     
    253271        if (empty(self::$data)) return;
    254272
    255         if (!file_exists(WPDM_CACHE_DIR)) {
    256             @mkdir(WPDM_CACHE_DIR, 0755, true);
     273        if (!\file_exists(WPDM_CACHE_DIR)) {
     274            @\mkdir(WPDM_CACHE_DIR, 0755, true);
    257275        }
    258276
    259277        $data = Crypt::encrypt(self::$data);
    260         file_put_contents(WPDM_CACHE_DIR . 'session-' . self::$deviceID . '.txt', $data);
     278        \file_put_contents(WPDM_CACHE_DIR . 'session-' . self::$deviceID . '.txt', $data);
    261279    }
    262280}
Note: See TracChangeset for help on using the changeset viewer.