From 14cb7467af2497025d65032c535adeae9b098801 Mon Sep 17 00:00:00 2001 From: Bernhard Kau Date: Fri, 1 Nov 2024 15:58:31 +0100 Subject: [PATCH] Remove `add_reasons_to_defaults()` from general initialization (#627) * Remove `add_reasons_to_defaults()` from general initialization The `add_reasons_to_defaults()` adds the translatable strings to the `$default`. Those `reasons` are only needed inside the `send_mail_notification()` method, which also calls the `add_reasons_to_defaults()` function. Therefore, the function call can be removed from the general `init()` function. * Remove `load_plugin_lang()` function and utilize `_load_textdomain_just_in_time()` This function is calling the `load_plugin_textdomain()`, which eventually become deprecated soon. Since this plugin is also using the "Text Domain" plugin header, it is not necessary to call this function at all. By removing this function, the `_load_textdomain_just_in_time()` function will be used, when the first string needs to be translated. * Add an action to load the reasons on `init` * Raise "Requires at least" version to 4.6 Since we don't explicitly load the translation files anymore this will make sure that the necessary function is there. * Fix PHPCS issues --- antispam_bee.php | 29 ++++++++--------------------- readme.txt | 4 ++-- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/antispam_bee.php b/antispam_bee.php index 86ab8926..acadcaa9 100755 --- a/antispam_bee.php +++ b/antispam_bee.php @@ -151,10 +151,13 @@ public static function init() { self::_init_internal_vars(); - if ( self::_current_page( 'dashboard' ) || self::_current_page( 'plugins' ) || self::_current_page( 'options' ) || self::_current_page( 'edit-comments' ) || self::_current_page( 'admin-post' ) ) { - self::load_plugin_lang(); - self::add_reasons_to_defaults(); - } + add_action( + 'init', + array( + __CLASS__, + 'add_reasons_to_defaults', + ) + ); if ( defined( 'DOING_CRON' ) ) { add_action( @@ -478,7 +481,7 @@ private static function _init_internal_vars() { * * @since 2.11.2 */ - private static function add_reasons_to_defaults() { + public static function add_reasons_to_defaults() { self::$defaults['reasons'] = array( 'css' => esc_attr__( 'Honeypot', 'antispam-bee' ), 'time' => esc_attr__( 'Comment time', 'antispam-bee' ), @@ -565,19 +568,6 @@ private static function _current_page( $page ) { } - /** - * Integration of the localization file - * - * @since 0.1 - * @since 2.4 - */ - public static function load_plugin_lang() { - load_plugin_textdomain( - 'antispam-bee' - ); - } - - /** * Add the link to the settings * @@ -2553,9 +2543,6 @@ public static function send_mail_notification( $id ) { return $id; } - self::load_plugin_lang(); - self::add_reasons_to_defaults(); - $subject = sprintf( '[%s] %s', stripslashes_deep( diff --git a/readme.txt b/readme.txt index 0b3c38d4..630a1e74 100755 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ * Contributors: pluginkollektiv, websupporter, schlessera, zodiac1978, swissspidy, krafit, kau-boy, florianbrinkmann, pfefferle * Tags: anti-spam, antispam, block spam, comment, comments, comment spam, pingback, spam, spam filter, trackback, GDPR * Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=TD4AMD2D8EMZW -* Requires at least: 4.5 +* Requires at least: 4.6 * Tested up to: 6.5 * Requires PHP: 5.2 * Stable tag: 2.11.6 @@ -65,7 +65,7 @@ Antispam Bee works best with default WordPress comments. It does not help to pro Antispam Bee works best with default WordPress comments. It is not compatible with Jetpack, wpDiscuz or Disqus Comments as those plugins load a new comment form within an iframe. Thus Antispam Bee can not access the comment form directly. ### Does Antispam Bee work with AJAX comment plugins or similar theme features? -Whether Antispam Bee works with a comment form submitted via AJAX depends on how the AJAX request is made. If the request goes to the file that usually also receives the comments, Antispam Bee could work with it out of the box (the [WP Ajaxify Comments](https://wordpress.org/plugins/wp-ajaxify-comments/) plugin does this, for example). +Whether Antispam Bee works with a comment form submitted via AJAX depends on how the AJAX request is made. If the request goes to the file that usually also receives the comments, Antispam Bee could work with it out of the box (the [WP Ajaxify Comments](https://wordpress.org/plugins/wp-ajaxify-comments/) plugin does this, for example). If the comments are sent to the `admin-ajax.php`, the `antispam_bee_disallow_ajax_calls` filter must be used to run ASB for requests to that file as well. If the script does not send all form data to the file, but only some selected ones, further customization is probably necessary, as [exemplified in this post by Torsten Landsiedel](https://torstenlandsiedel.de/2020/10/04/ajaxifizierte-kommentare-und-antispam-bee/) (in German).