fix: wire is_hard_drop_enabled + drop_score_threshold settings into Classifier filter chain
Settings::register_classifier_filters() registers priority-5 callbacks on cf7stg_classifier_thresholds and cf7stg_hard_drop_rules so the UI options actually influence Classifier behaviour. Called from Plugin::boot(). User filters at priority 10 override these defaults as expected. Adds 4 tests covering the wired behaviour and override priority. Also adds dry_run_drop? to MessageFormatter::build() @param docblock. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,8 @@ final class MessageFormatter
|
||||
* reason:string,
|
||||
* ip:string,
|
||||
* user_agent:string,
|
||||
* is_retro:bool
|
||||
* is_retro:bool,
|
||||
* dry_run_drop?:bool
|
||||
* } $ctx
|
||||
*
|
||||
* @return array{text:string,reply_markup:array|null}
|
||||
|
||||
@@ -43,6 +43,9 @@ final class Plugin
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
// Inject silent-drop options into Classifier filter chain
|
||||
Settings::register_classifier_filters();
|
||||
|
||||
// Register runtime hooks
|
||||
Dispatcher::register_hooks();
|
||||
(new CF7Source())->register();
|
||||
|
||||
@@ -171,4 +171,27 @@ final class Settings
|
||||
'reset_at' => $today,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register default callbacks that inject silent-drop options into the
|
||||
* Classifier's filter chain. Runs at plugin boot. User filters at the
|
||||
* default priority (10) override these (priority 5).
|
||||
*/
|
||||
public static function register_classifier_filters(): void
|
||||
{
|
||||
add_filter('cf7stg_classifier_thresholds', static function ($thresholds) {
|
||||
if (is_array($thresholds)) {
|
||||
$thresholds['drop'] = self::get_drop_score_threshold();
|
||||
}
|
||||
return $thresholds;
|
||||
}, 5);
|
||||
|
||||
add_filter('cf7stg_hard_drop_rules', static function ($rules) {
|
||||
if (is_array($rules) && !self::is_hard_drop_enabled()) {
|
||||
$rules['short_latin_name'] = false;
|
||||
$rules['placeholder_fields'] = false;
|
||||
}
|
||||
return $rules;
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user