SMF 2.1: 'Include' hooks not removed by 'remove_integration_function'

Started by GL700Wing, June 08, 2025, 10:13:15 PM

Previous topic - Next topic

GL700Wing

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.
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Advertisement: