From 2fe5db4a7380b474e60102808b8f6571bd87028e Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Wed, 10 Sep 2025 16:53:46 +0200 Subject: [PATCH] use wp_doing_cron() instead of constant checking (#44) The function is available since WP 4.8 and defaults to the same logic but applies an additional filter internally. --- inc/class-statifyblacklist-admin.php | 4 ++-- inc/class-statifyblacklist.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/class-statifyblacklist-admin.php b/inc/class-statifyblacklist-admin.php index f257413..f8e320f 100644 --- a/inc/class-statifyblacklist-admin.php +++ b/inc/class-statifyblacklist-admin.php @@ -126,11 +126,11 @@ public static function plugin_actions_links( array $links, string $file ): array */ public static function cleanup_database(): void { // Check user permissions. - if ( ! current_user_can( 'manage_options' ) && ! ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { + if ( ! current_user_can( 'manage_options' ) && ! wp_doing_cron() ) { die( esc_html__( 'Are you sure you want to do this?', 'statify-blacklist' ) ); } - if ( defined( 'DOING_CRON' ) && DOING_CRON ) { + if ( wp_doing_cron() ) { $clean_ref = ( 1 === self::$options['referer']['cron'] ); $clean_trg = ( 1 === self::$options['target']['cron'] ); } else { diff --git a/inc/class-statifyblacklist.php b/inc/class-statifyblacklist.php index f310892..9b13d5d 100644 --- a/inc/class-statifyblacklist.php +++ b/inc/class-statifyblacklist.php @@ -109,7 +109,7 @@ public static function init(): void { } // CronJob to clean up database. - if ( defined( 'DOING_CRON' ) && DOING_CRON && + if ( wp_doing_cron() && ( 1 === self::$options['referer']['cron'] || 1 === self::$options['target']['cron'] ) ) { add_action( 'statify_cleanup', array( 'StatifyBlacklist_Admin', 'cleanup_database' ) ); }