Plugin Directory

Changeset 3347790


Ignore:
Timestamp:
08/21/2025 12:17:22 AM (7 months ago)
Author:
loghin
Message:

Small compatibility patch

Location:
dynamic-front-end-heartbeat-control
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • dynamic-front-end-heartbeat-control/tags/1.2.99/defibrillator/unclogger.php

    r3320647 r3347790  
    33
    44defined('ABSPATH') or die();
     5
    56require_once plugin_dir_path(__FILE__) . 'unclogger-db.php';
    67require_once plugin_dir_path(__FILE__) . 'db-health.php';
    78
    8 class DfehcUnclogger {
    9 
     9class DfehcUnclogger
     10{
    1011    protected $db;
    1112    protected $config;
    1213
    1314    protected $default_settings = [
    14         'auto_cleanup' => false,
     15        'auto_cleanup'        => false,
    1516        'post_revision_limit' => 20,
    1617    ];
    1718
    18     public function __construct() {
    19         if (defined('WP_CLI') && WP_CLI && file_exists(self::get_plugin_path() . 'defibrillator/cli-helper.php')) {
    20             require_once(self::get_plugin_path() . 'defibrillator/cli-helper.php');
     19    public function __construct()
     20    {
     21        if (defined('WP_CLI') && WP_CLI) {
     22            $base = rtrim(self::get_plugin_path(), '/\\');
     23            $cli  = $base . '/cli-helper.php';
     24
     25            if (!is_file($cli)) {
     26                $cli = $base . '/defibrillator/cli-helper.php';
     27            }
     28
     29            if (is_file($cli)) {
     30                require_once $cli;
     31            }
    2132        }
    2233
     
    2536        $this->set_default_settings();
    2637
    27         load_plugin_textdomain('dynamic-front-end-heartbeat-control', false, dirname(plugin_basename(__FILE__)) . '/languages');
     38        load_plugin_textdomain(
     39            'dynamic-front-end-heartbeat-control',
     40            false,
     41            dirname(plugin_basename(__FILE__)) . '/languages'
     42        );
    2843
    2944        add_action('rest_api_init', [$this, 'register_rest_routes']);
    3045    }
    3146
    32     public static function get_plugin_path() {
     47    public static function get_plugin_path()
     48    {
    3349        return plugin_dir_path(__FILE__);
    3450    }
    3551
    36     public function set_default_settings() {
     52    public function set_default_settings()
     53    {
    3754        if (!get_option('dfehc_unclogger_settings')) {
    3855            update_option('dfehc_unclogger_settings', $this->default_settings, true);
    3956        }
    4057    }
    41 
    4258    public function get_settings() {
    4359        return get_option('dfehc_unclogger_settings', $this->default_settings);
  • dynamic-front-end-heartbeat-control/tags/1.2.99/engine/server-load.php

    r3320647 r3347790  
    235235add_action('wp_ajax_nopriv_get_server_load', 'dfehc_get_server_load_ajax_handler');
    236236
    237 function dfehc_get_server_load_persistent(): float
    238 {
     237function dfehc_get_server_load_persistent(): float {
    239238    static $cached = null;
    240239    if ($cached !== null) {
    241240        return $cached;
    242241    }
     242
    243243    ['client' => $client, 'type' => $type] = _dfehc_get_cache_client();
    244244    $val = false;
     245
    245246    if ($client) {
    246247        try {
    247248            $val = $client->get(DFEHC_SERVER_LOAD_CACHE_KEY);
    248249        } catch (Throwable $e) {
    249             trigger_error('DFEHC cache read error: ' . $e->getMessage(), E_USER_WARNING);
    250         }
    251     }
     250            if (defined('WP_DEBUG') && WP_DEBUG) {
     251                trigger_error('DFEHC cache read error: ' . $e->getMessage(), E_USER_WARNING);
     252            }
     253        }
     254    }
     255
    252256    if ($val !== false) {
    253257        return $cached = (float) $val;
    254258    }
     259
    255260    $fresh = dfehc_get_server_load();
    256261    dfehc_cache_server_load($fresh);
     
    258263}
    259264
    260 function dfehc_register_minute_schedule(array $schedules): array
    261 {
     265add_filter('cron_schedules', static function (array $schedules): array {
    262266    if (!isset($schedules['dfehc_minute'])) {
    263267        $schedules['dfehc_minute'] = [
     
    267271    }
    268272    return $schedules;
    269 }
    270 add_filter('cron_schedules', 'dfehc_register_minute_schedule');
    271 
    272 if (apply_filters('dfehc_enable_load_logging', true)) {
     273}, 5);
     274
     275$__dfehc_schedule = static function (): void {
     276    if (!apply_filters('dfehc_enable_load_logging', true)) {
     277        return;
     278    }
    273279    if (!wp_next_scheduled('dfehc_log_server_load_hook')) {
    274         $start = time() - (time() % 60) + 60;
    275         wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook');
    276     }
    277 }
     280        try {
     281            $start = time() - (time() % 60) + 60;
     282            wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook');
     283        } catch (Throwable $e) {
     284            if (defined('WP_DEBUG') && WP_DEBUG) {
     285                trigger_error('DFEHC scheduling error: ' . $e->getMessage(), E_USER_WARNING);
     286            }
     287        }
     288    }
     289};
     290
     291register_activation_hook(__FILE__, $__dfehc_schedule);
     292
     293add_action('init', static function () use ($__dfehc_schedule): void {
     294    $__dfehc_schedule();
     295    if (wp_next_scheduled('dfehc_log_server_load_hook')) {
     296        remove_action('init', __FUNCTION__, 1);
     297    }
     298}, 1);
  • dynamic-front-end-heartbeat-control/trunk/defibrillator/unclogger.php

    r3310561 r3347790  
    33
    44defined('ABSPATH') or die();
     5
    56require_once plugin_dir_path(__FILE__) . 'unclogger-db.php';
    67require_once plugin_dir_path(__FILE__) . 'db-health.php';
    78
    8 class DfehcUnclogger {
    9 
     9class DfehcUnclogger
     10{
    1011    protected $db;
    1112    protected $config;
    1213
    1314    protected $default_settings = [
    14         'auto_cleanup' => false,
     15        'auto_cleanup'        => false,
    1516        'post_revision_limit' => 20,
    1617    ];
    1718
    18     public function __construct() {
    19         if (defined('WP_CLI') && WP_CLI && file_exists(self::get_plugin_path() . 'defibrillator/cli-helper.php')) {
    20             require_once(self::get_plugin_path() . 'defibrillator/cli-helper.php');
     19    public function __construct()
     20    {
     21        if (defined('WP_CLI') && WP_CLI) {
     22            $base = rtrim(self::get_plugin_path(), '/\\');
     23            $cli  = $base . '/cli-helper.php';
     24
     25            if (!is_file($cli)) {
     26                $cli = $base . '/defibrillator/cli-helper.php';
     27            }
     28
     29            if (is_file($cli)) {
     30                require_once $cli;
     31            }
    2132        }
    2233
     
    2536        $this->set_default_settings();
    2637
    27         load_plugin_textdomain('dynamic-front-end-heartbeat-control', false, dirname(plugin_basename(__FILE__)) . '/languages');
     38        load_plugin_textdomain(
     39            'dynamic-front-end-heartbeat-control',
     40            false,
     41            dirname(plugin_basename(__FILE__)) . '/languages'
     42        );
    2843
    2944        add_action('rest_api_init', [$this, 'register_rest_routes']);
    3045    }
    3146
    32     public static function get_plugin_path() {
     47    public static function get_plugin_path()
     48    {
    3349        return plugin_dir_path(__FILE__);
    3450    }
    3551
    36     public function set_default_settings() {
     52    public function set_default_settings()
     53    {
    3754        if (!get_option('dfehc_unclogger_settings')) {
    3855            update_option('dfehc_unclogger_settings', $this->default_settings, true);
    3956        }
    4057    }
    41 
    4258    public function get_settings() {
    4359        return get_option('dfehc_unclogger_settings', $this->default_settings);
  • dynamic-front-end-heartbeat-control/trunk/engine/server-load.php

    r3320647 r3347790  
    235235add_action('wp_ajax_nopriv_get_server_load', 'dfehc_get_server_load_ajax_handler');
    236236
    237 function dfehc_get_server_load_persistent(): float
    238 {
     237function dfehc_get_server_load_persistent(): float {
    239238    static $cached = null;
    240239    if ($cached !== null) {
    241240        return $cached;
    242241    }
     242
    243243    ['client' => $client, 'type' => $type] = _dfehc_get_cache_client();
    244244    $val = false;
     245
    245246    if ($client) {
    246247        try {
    247248            $val = $client->get(DFEHC_SERVER_LOAD_CACHE_KEY);
    248249        } catch (Throwable $e) {
    249             trigger_error('DFEHC cache read error: ' . $e->getMessage(), E_USER_WARNING);
    250         }
    251     }
     250            if (defined('WP_DEBUG') && WP_DEBUG) {
     251                trigger_error('DFEHC cache read error: ' . $e->getMessage(), E_USER_WARNING);
     252            }
     253        }
     254    }
     255
    252256    if ($val !== false) {
    253257        return $cached = (float) $val;
    254258    }
     259
    255260    $fresh = dfehc_get_server_load();
    256261    dfehc_cache_server_load($fresh);
     
    258263}
    259264
    260 function dfehc_register_minute_schedule(array $schedules): array
    261 {
     265add_filter('cron_schedules', static function (array $schedules): array {
    262266    if (!isset($schedules['dfehc_minute'])) {
    263267        $schedules['dfehc_minute'] = [
     
    267271    }
    268272    return $schedules;
    269 }
    270 add_filter('cron_schedules', 'dfehc_register_minute_schedule');
    271 
    272 if (apply_filters('dfehc_enable_load_logging', true)) {
     273}, 5);
     274
     275$__dfehc_schedule = static function (): void {
     276    if (!apply_filters('dfehc_enable_load_logging', true)) {
     277        return;
     278    }
    273279    if (!wp_next_scheduled('dfehc_log_server_load_hook')) {
    274         $start = time() - (time() % 60) + 60;
    275         wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook');
    276     }
    277 }
     280        try {
     281            $start = time() - (time() % 60) + 60;
     282            wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook');
     283        } catch (Throwable $e) {
     284            if (defined('WP_DEBUG') && WP_DEBUG) {
     285                trigger_error('DFEHC scheduling error: ' . $e->getMessage(), E_USER_WARNING);
     286            }
     287        }
     288    }
     289};
     290
     291register_activation_hook(__FILE__, $__dfehc_schedule);
     292
     293add_action('init', static function () use ($__dfehc_schedule): void {
     294    $__dfehc_schedule();
     295    if (wp_next_scheduled('dfehc_log_server_load_hook')) {
     296        remove_action('init', __FUNCTION__, 1);
     297    }
     298}, 1);
Note: See TracChangeset for help on using the changeset viewer.