Skip to content

Commit 14cb746

Browse files
authored
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
1 parent 9d9fcb7 commit 14cb746

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

Diff for: antispam_bee.php

+8-21
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,13 @@ public static function init() {
151151

152152
self::_init_internal_vars();
153153

154-
if ( self::_current_page( 'dashboard' ) || self::_current_page( 'plugins' ) || self::_current_page( 'options' ) || self::_current_page( 'edit-comments' ) || self::_current_page( 'admin-post' ) ) {
155-
self::load_plugin_lang();
156-
self::add_reasons_to_defaults();
157-
}
154+
add_action(
155+
'init',
156+
array(
157+
__CLASS__,
158+
'add_reasons_to_defaults',
159+
)
160+
);
158161

159162
if ( defined( 'DOING_CRON' ) ) {
160163
add_action(
@@ -478,7 +481,7 @@ private static function _init_internal_vars() {
478481
*
479482
* @since 2.11.2
480483
*/
481-
private static function add_reasons_to_defaults() {
484+
public static function add_reasons_to_defaults() {
482485
self::$defaults['reasons'] = array(
483486
'css' => esc_attr__( 'Honeypot', 'antispam-bee' ),
484487
'time' => esc_attr__( 'Comment time', 'antispam-bee' ),
@@ -565,19 +568,6 @@ private static function _current_page( $page ) {
565568
}
566569

567570

568-
/**
569-
* Integration of the localization file
570-
*
571-
* @since 0.1
572-
* @since 2.4
573-
*/
574-
public static function load_plugin_lang() {
575-
load_plugin_textdomain(
576-
'antispam-bee'
577-
);
578-
}
579-
580-
581571
/**
582572
* Add the link to the settings
583573
*
@@ -2553,9 +2543,6 @@ public static function send_mail_notification( $id ) {
25532543
return $id;
25542544
}
25552545

2556-
self::load_plugin_lang();
2557-
self::add_reasons_to_defaults();
2558-
25592546
$subject = sprintf(
25602547
'[%s] %s',
25612548
stripslashes_deep(

Diff for: readme.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Contributors: pluginkollektiv, websupporter, schlessera, zodiac1978, swissspidy, krafit, kau-boy, florianbrinkmann, pfefferle
33
* Tags: anti-spam, antispam, block spam, comment, comments, comment spam, pingback, spam, spam filter, trackback, GDPR
44
* Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=TD4AMD2D8EMZW
5-
* Requires at least: 4.5
5+
* Requires at least: 4.6
66
* Tested up to: 6.5
77
* Requires PHP: 5.2
88
* Stable tag: 2.11.6
@@ -65,7 +65,7 @@ Antispam Bee works best with default WordPress comments. It does not help to pro
6565
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.
6666

6767
### Does Antispam Bee work with AJAX comment plugins or similar theme features?
68-
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).
68+
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).
6969

7070
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).
7171

0 commit comments

Comments
 (0)