For moderators: My post not the same and not answered by PHP __PHP_Incomplete_Class Object with my $_SESSION data, really! Because sessions is my finale attempt to solve the problem, before I used singleton class, wp_get_user etc. Please, don't close my question, it has more nuances!
A plugin is being developed for a Wordpress site. Also on the site added authorization by oAuth through Google and Facebook (using the plugin miniOrange). I specify this point, because it may be significant.
So, a user with a certain Visitor role authorizes on the site via Google, and this is intercepted by the hook:
add_action('init', 'custom_login_handler', 20);
function custom_login_handler()
{
if (is_user_logged_in() && current_user_can('pickinteri_Visitor')) {
$user = wp_get_current_user();
$tmp_session = $_SESSION;
Auth::visitorAuthSet($user->ID);
$_SESSION['current_visitor'] = Pcab_Visitor::get_visitor();
$_SESSION['current_visitor']->ID = $user->ID;
$_SESSION['current_visitor']->first_name = isset($tmp_session['first_name'])?$tmp_session['first_name']:'';
$_SESSION['current_visitor']->last_name = isset($tmp_session['last_name'])?$tmp_session['last_name']:'';
$_SESSION['current_visitor']->full_name = isset($tmp_session['user_full_name'])?$tmp_session['user_full_name']:'';
$_SESSION['current_visitor']->display_name = isset($tmp_session['display_name'])?$tmp_session['display_name']:'';
$_SESSION['current_visitor']->email = isset($tmp_session['user_email'])?$tmp_session['user_email']:'';
$_SESSION['current_visitor']->avatar_url = isset($tmp_session['user_picture'])?$tmp_session['user_picture']:'';
$_SESSION['current_visitor']->social_user_id = isset($tmp_session['social_user_id'])?$tmp_session['social_user_id']:'';
$_SESSION['current_visitor']->social_app = isset($tmp_session['social_app_name'])?$tmp_session['social_app_name']:'';
if ($_SESSION['current_visitor']->display_name == '') {
$_SESSION['current_visitor']->display_name = $user->display_name;
}
}
}
Remark FYI - Pcab_Visitor::get_visitor() is a singleton pattern class, so it doesn't have any $var = new Pcab_Visitor().
and then from another hook
add_action('admin_init', 'redirect_dashboard');
function redirect_dashboard() {
if (is_user_logged_in() && current_user_can('pickinteri_Visitor')) {
wp_redirect(Auth::visitorCabinetURL());
exit;
}
if (is_user_logged_in() && current_user_can('subscriber')) {
wp_redirect(home_url());
exit;
}
}
is redirected to the page https://domain.space/visitor-cabinet/
This page has its own menu (as well as with the cabinets of other roles, but there users are completely independent of the authorization system Wordpress - that's why I emphasized it at first), and, for example, I call the page of the same cabinet - but not by redirect, but by clicking in the menu https://domain.space/visitor-cabinet/?mode=settings.
That was a description of the process, and now the actual problem with the $current_visitor variable located in the visitor-cabinet.php script (which generates the specified pages).
In the first case it reports about itself (var_dump() output):
php_class: TCAby\PickinteriCabinet\Admin\Pcab_Visitor, php_object: TCAby\PickinteriCabinet\Admin\Pcab_Visitor::__set_state(array(
'properties' =>
array (
'ID' => 12,
'first_name' => 'Don',
'last_name' => 'Smith',
'full_name' => 'Don Smith',
'display_name' => 'Don Smith',
'email' => '[email protected]',
'avatar_url' => 'https://lh3.googleusercontent.com/a/ACg8ocJs_EdNxyyNf-lqA1WqY8xR-q-9ZX4jOdrd2NDY3Fz9Pp7p=s96-c',
'social_user_id' => '1144905419045954546685675134657',
'social_app' => 'google',
),
))
and the second time (the page with the get-parameter) is:
php_class: __PHP_Incomplete_Class, php_object: __PHP_Incomplete_Class::__set_state(array(
'__PHP_Incomplete_Class_Name' => 'TCAby\\PickinteriCabinet\\Admin\\Pcab_Visitor',
'properties' =>
array (
'ID' => 12,
'first_name' => 'Don',
'last_name' => 'Smith',
'full_name' => 'Don Smith',
'display_name' => 'Don Smith',
'email' => '[email protected]',
'avatar_url' => 'https://lh3.googleusercontent.com/a/ACg8ocJs_EdNxyyNf-lqA1WqY8xR-q-9ZX4jOdrd2NDY3Fz9Pp7p=s96-c',
'social_user_id' => '1144905419045954546685675134657',
'social_app' => 'google',
)
Basically, I think, there is a problem not just with this variable, its behavior is just a visible part of the iceberg - because very strange behavior after page refresh (see below)
=== Before this solution (pass class through session variable) I tried to make it just a global variable in the very first initiating file - the variable was lost, it became isset() = false.
Even before that I tried to operate with standard Wordpress mechanism - like is_user_logged_in, wp_get_user_detail etc. - similarly, when going to the second page (with the parameter) everything was lost, the user was unlogged and other mysticism.