sergant210/AdminTools

PHP Warnings when using PHP8

garryn opened this issue · 1 comments

Hi, I'm posting this as I found an issue with AdminTools and PHP8 in MODX Cloud ... the following warnings can fill up the MODX error log pretty quick as they fire on every frontend web page load:

[2021-12-09 12:05:04] (ERROR @ /www/core/cache/includes/elements/modplugin/31.include.cache.php : 55) PHP warning: Attempt to read property "blocked" on null

I was able to fix the issue by changing lines 55/56 in the plugin to:

$profile = isset($modx->user) ? $modx->user->getOne('Profile') : null;
if ($modx->user && (!$modx->user->active || ($profile !== null && $profile->blocked)) && $modx->user->isAuthenticated($modx->context->get('key'))) {      

Basically, grabbing the user profile first and then checking that first before trying to access the blocked property.

And apologies as I think this PR covers it (different approach, but same result) :): #28