WordPress bug?

How to fix PHP notices for undefined user properties in ChronoForms.

Overview

The issue occurs when a non-logged-in user accesses a CFv6 form, causing PHP notices about undefined object properties.
Apply a patch to the CF plugin that prevents the code from trying to access user data properties when no user is logged in.

Cr Crams 13 Feb, 2019
Found this bug with CFv6 and WP 5
Not sure if it's actually a bug or a misconfiguration by yours truly but this is the deal, when the user is not logged in, the form will throw several php Notices like this:

Notice: Undefined property: stdClass::$ID in /home/user/public_html/wp-content/plugins/chronoforms6/cegcore2/libs/wordpress/app.php on line 131

Commenting the block of vars assigned to the array seems to solve the problem:
 if(empty($WP_User->data->roles) OR empty($G_User['groups']) OR (array_values($WP_User->data->roles) !== $G_User['groups']) OR empty($G_User['inheritance'])){
$user_session = array();
/* $user_session['id'] = $WP_User->data->ID;
$user_session['name'] = $WP_User->data->user_nicename;
$user_session['username'] = $WP_User->data->user_login;
$user_session['email'] = $WP_User->data->user_email;
$user_session['last_login'] = $WP_User->lastvisitDate;
$user_session['logged_in'] = (int)(bool)$WP_User->data->ID;
$user_session['guest'] = (int)!(bool)$WP_User->data->ID;
*/
$user_session['groups'] = empty($WP_User->roles) ? array('public') : array_values($WP_User->roles);
$user_session['inheritance'] = array();
...
Max_admin Max_admin 19 Feb, 2019
Answer
1 Likes
Hi Crams,

Thank you, that was a bug!

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.