From 97e17c41c15401c92a019ba2a67813a5976f718d Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 5 Jul 2026 20:06:17 +0100 Subject: [PATCH] allow users to configure a closure (anonymous function) as a *_struct_hook config setting as well previously we required a named function, see #1069 --- config.inc.php | 5 +++++ model/PFAHandler.php | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config.inc.php b/config.inc.php index 8a65a476..7554803f 100644 --- a/config.inc.php +++ b/config.inc.php @@ -372,6 +372,11 @@ function maildir_name_hook($domain, $user) { return $struct; # important! } $CONF['admin_struct_hook'] = 'x_struct_admin_modify'; + + You can also use e.g. + $CONF['admin_struct_hook'] = function($struct) { // logic + return $struct; } + ); */ $CONF['admin_struct_hook'] = ''; $CONF['domain_struct_hook'] = ''; diff --git a/model/PFAHandler.php b/model/PFAHandler.php index 9129bc85..82f0e6d9 100644 --- a/model/PFAHandler.php +++ b/model/PFAHandler.php @@ -239,8 +239,9 @@ abstract class PFAHandler ); } + // default *_struct_hooks are empty strings $struct_hook = Config::read($this->db_table . '_struct_hook'); - if (!empty($struct_hook) && is_string($struct_hook) && $struct_hook != 'NO' && function_exists($struct_hook)) { + if (!empty($struct_hook) && $struct_hook != 'NO' && is_callable($struct_hook)) { $this->struct = $struct_hook($this->struct); }