Simple Machines Community Forum

SMF Development => Bug Reports => Topic started by: GL700Wing on June 08, 2025, 10:13:15 PM

Title: SMF 2.1: 'Include' hooks not removed by 'remove_integration_function'
Post by: GL700Wing on June 08, 2025, 10:13:15 PM
While I was working on a new mod yesterday (and reviewing a previous mod I'd written) I discovered that when uninstalling a mod that also uninstalls hooks using the 'hook' element in the package-info.xml file the 'include' hooks (ie, integrate_admin_include, integrate_pre_include and integrate_theme_include) are not removed by the function 'remove_integration_function' in ./Sources/Subs.php and as result the 'integrate_*_include' settings in the database retain references to non-existent files when the mods are uninstalled.

The problem is that the function 'remove_integration_function' expects that if the $file variable is defined the '$function' will have a non-blank value even though an 'include' hook can be installed via the package-info.xml file without the 'function' attribute being defined (this attribute is not applicable to an 'include' hook).

Suggested fix as follows:
Find:
// Any files  to load?
if (!empty($file) && is_string($file))
$function = $file . '|' . $function;

// Get the correct string.
$integration_call = $function;
$enabled_call = rtrim($function, '!');
$disabled_call = $enabled_call . '!';

Replace with:
// Any files with functions to load?
if (!empty($file) && is_string($file) && $function)
$function = $file . '|' . $function;

// Get the correct string.
$enabled_call = rtrim($function ? $function : $file, '!');
$disabled_call = $enabled_call . '!';


Note: The variable $integration_call can be removed because it is not referenced elsewhere in the 'remove_integration_function' function.