Website Comments 1.05 Error - Trying to access array offset on value of type bool

6 posts by 4 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: July 13, 2021   (RSS)

By craig_bcd - June 17, 2021

Hi -

I started getting this error with website comments 1.05 just out of the clear blue sky (I am sure something happened I just don't know what) 

On the website it shows up like this:

Notice: Trying to access array offset on value of type bool in /home/customer/www/delanceyplace.com/public_html/cmsAdmin/plugins/websiteComments/websiteComments.php on line 279

In the error log it shows up like this: 

 E_NOTICE: Trying to access array offset on value of type bool
/home/customer/www/delanceyplace.com/public_html/cmsAdmin/plugins/websiteComments/websiteComments.php (line 279)
https://delanceyplace.com/view-search-results.php?2509

It looks like the error is in the plugin itself.

We are running:

  • CMS Builder v3.53 (Build 2265)
  • Website comments 1.05
  • PHP v7.4.18

Can you guys help?

Thanks!

Craig

By Steve99 - June 17, 2021

Hi Craig,

I could be wrong, but it sounds like the function "wsc_thread_isSubscribed" might be getting called on your page code before checking if a site visitor is logged in. I signed up a test account and no longer saw the error after being logged in.

Could do something like this for things that require a user to be logged in:

if (@$CURRENT_USER) { 
// do stuff like checking if subscribed to current post
}

Also, I noticed you are running cmsb 3.53 on php7.4 and I believe 7.4 compatibility was added in 3.54. I suppose it's possible that a php version change may have presented the error in handling code differently. Could try updating as well.

Hopefully this helps. Let me know how you make out.

Best,
Steve

By craig_bcd - June 17, 2021

Steve!

You are genius!  I changed the PHP version to 7.3 and the error magically disappeared!  I'll look to upgrade to 3.54.

Thanks!

Craig

By daniel - June 22, 2021

Hi Craig,

Steve was generally correct - this is an error that started showing up in PHP 7.4. Newer versions of CMSB have improved compatibility, but this doesn't necessarily extend to plugins. We will work on getting the official plugins updated, but in the meantime, here's a patch for this particular error in Website Comments 1.5:

If you locate this block of code in websiteComments.php (around line 275)

function wsc_thread_isSubscribed($tableOrTag, $recordNum) {
  global $CURRENT_USER;

  $isSubscribed = mysql_count('_wsc_subscribers', array(
    'userNum'    => $CURRENT_USER['num'],
    'tableOrTag' => $tableOrTag,
    'recordNum'  => $recordNum,
  ));

  return (bool) $isSubscribed;
}

And replace it with this:

function wsc_thread_isSubscribed($tableOrTag, $recordNum) {
  global $CURRENT_USER;

  if (!empty( $CURRENT_USER )) {
    $isSubscribed = mysql_count('_wsc_subscribers', array(
      'userNum'    => $CURRENT_USER['num'],
      'tableOrTag' => $tableOrTag,
      'recordNum'  => $recordNum,
    ));
  }
  
  return (bool) $isSubscribed;
}

That should allow you to run the plugin in PHP 7.4.

Let me know if you have any other issues!
Thanks,

Daniel
Technical Lead
interactivetools.com

By daniel - July 13, 2021

Hi degreesnorth,

This particular issue should be resolved in newer versions of CMSB. You can find the details of the latest release here: https://www.interactivetools.com/forum/forum-posts.php?CMSB-v3.54-Released---October-29-2020-82341

If you're unable to upgrade currently, you can also fix this error with a simple patch. In /cmsb/lib/menus/header_functions.php, replace this line (line 167):

  elseif (@$menu['visibility'] == 'requireAdmin' && $CURRENT_USER['isAdmin'])                           { $userHasMenuAccess = true; } // allow access to admin for admin menus

With this:

  elseif (@$menu['visibility'] == 'requireAdmin' && !empty($CURRENT_USER['isAdmin']))                   { $userHasMenuAccess = true; } // allow access to admin for admin menus

Note that there may be other PHP 7.4 compatibility issues in CMSB 3.50, so I would still recommend upgrading if possible.

Let me know if you have any other questions!

Thanks,

Daniel
Technical Lead
interactivetools.com