Custom Header Plugin Error php8.4.24

Error in the Custom Header Plugin plugin, with OJS version 3.5.0-5, PHP 8.4.24.
log:
Plugin APP\plugins\generic\customHeader\CustomHeaderPlugin failed to handle the hook TemplateManager::display\nTypeError: PKP\template\PKPTemplateManager::addHeader(): Argument #2 ($header) must be of type string, null given, called in /plugins/generic/customHeader/CustomHeaderPlugin.php on line 129 and defined in /lib/pkp/classes/template/PKPTemplateManager.php:627

Hi @williamm,

What version of the plugin are you using?

-Roger
PKP Team

Hi @rcgillis,

I’m using version 1.0.5.1, the latest one I found.

The error stopped with the following change in the plugins/generic/customHeader/CustomHeaderPlugin.php file.

I changed the displayTemplateHook() method
from:

public function displayTemplateHook(string $hookName, array $params)

{
if (!$this->injected) {
$this->injected = true;
$templateMgr =& $params[0];
$request = Application::get()->getRequest();
$context = $request->getContext();
$templateMgr->addHeader(
‘custom’,
$this->getSetting($context ? $context->getId() : PKPApplication::SITE_CONTEXT_ID, ‘content’)
);
$templateMgr->addHeader(
‘custombackend’,
$this->getSetting(
$context ? $context->getId() : PKPApplication::SITE_CONTEXT_ID,
‘backendContent’
),
[‘contexts’ => [‘backend’]]
);
}
return false;
}

to:

public function displayTemplateHook(string $hookName, array $params)
{
if (!$this->injected) {
$this->injected = true;
$templateMgr =& $params[0];
$request = Application::get()->getRequest();
$context = $request->getContext();
$contextId = $context ? $context->getId() : PKPApplication::SITE_CONTEXT_ID;

$templateMgr->addHeader(
‘custom’,
$this->getSetting($contextId, ‘content’) ?? ‘’
);

$templateMgr->addHeader(
‘custombackend’,
$this->getSetting($contextId, ‘backendContent’) ?? ‘’,
[‘contexts’ => [‘backend’]]
);
}

return false;

}

Hi @williamm,

See: PHP NOTICE: CustomHeaderPlugin failed to handle the hook TemplateManager in OJS 3.5.0-3

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,
That was it. Solved.
Thanks.